Sunday, January 22, 2012

Hello World of Java 7 on Windows 8, in "cmd" DOS Prompt

After installed of Java environment, it's time to code our first Java program - helloworld.

The first exercise of helloworld we create and compile in "cmd" (DOS Prompt) environment.

- Create a text file helloworld.java, using any editor program you like.

- Entent the code, and save it:
public class helloworld{

public static void main(String[] args){
System.out.println("Hello World!");
}

}

helloworld.java

- Start a "cmd" window in Windows 8, refer to the post "Run 'cmd' in Windows 8" if you don't know how. Change to the directory of helloworld.java.

- Type the command to compile the java program:
javac helloworld.java

- Type the command to run the compiled class:
java helloworld

- If your JDK environment is set properly, the output should be:
Hello World!

helloworld.java

*** If you cannot run javac/java due to missing in path setting, refer to the post "Set PATH for JDK 7 on Windows 8".

1 comment:

  1. it says java is not recognized as an internal or external command

    ReplyDelete