Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hello, Java! #2

Open
shyangs opened this issue Feb 16, 2017 · 0 comments
Open

Hello, Java! #2

shyangs opened this issue Feb 16, 2017 · 0 comments

Comments

@shyangs
Copy link
Owner

shyangs commented Feb 16, 2017

使用 cmd

  1. 建立一個 HelloWorld.java 純文字文件檔,假設路徑為 C:\Temp\HelloWorld.java,其內容為:
public class HelloWorld {
	public static void main(String[] args) {
		System.out.println("Hello World!");
	}
}
  1. 開啟 cmd, 切換路徑到放置 HelloWorld.java 的目錄,在此命令為 cd C:\Temp
  2. 使用 javac 命令來編譯,在此命令為 javac HelloWorld.java,在 HelloWorld.java 同資料夾裡編譯出了 HelloWorld.class ,在此路徑為 C:\Temp\HelloWorld.class
  3. 使用 java 命令來執行Class檔,在此命令為 java HelloWorld ,將看到輸出 ‵Hello World!‵
    cmd: Hello World! (Java)

使用 NetBeans

  1. NetBeans IDE >> [File] >> New Project... >> Categories: Java / Projects: Java Application >> [Next]
  2. 填寫 Project Name 和 Create Main Class >> [Finish]
  3. 開啟 {{Project Name}}.java, 撰寫程式碼。第一支程式,簡單的印出字串。在 main 函式裡,打上 System.out.println("Hello, Java!");
  4. 試著跑跑看,看結果 Run Project (F6)

NetBeans : new java application in netbeans ide

NetBeans :  my first java application

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package io.github.shyangs.helloworldprinter;

/**
 *
 * @author Java
 */
public class HelloWorldPrinter {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("Hello, Java!");
    }
    
}

使用 Eclipse

  1. NetBeans IDE >> [File] >> New >> Java Project >> 填寫 Project name >> [Finish]
  2. 在 Source Folder (src) 上點右鍵 >> New >> Class >> 填寫 Package >> 勾選 public static void main(String[] args) >> [Finish]
  3. 開啟 {{Project Name}}.java, 撰寫程式碼。第一支程式,簡單的印出字串。在 main 函式裡,打上 System.out.println("Hello, Java!");
  4. 試著跑跑看,看結果 Run Project ( Ctrl + F11)

Eclipse:  New Java Project
Eclipse: Java Project >> New Class
Eclipse:  New Java Class
Eclipse: Hello, Java!

package io.github.shyangs.helloworldprinter;

public class HelloWorldPrinter {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("Hello Java!");
	}

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant