Running a Java Program from Command Prompt


Run Command Prompt (found under All Programs/Accessories in the Start menu).  Type

C:\> cd \mywork

This makes C:\mywork the current directory.

C:\mywork> dir

This displays the directory contents.  You should see HelloWorld.java among the files.

C:\mywork> set path=%path%;C:\Program Files\Java\jdk1.8.0_05\bin

This tells the system where to find JDK programs.

C:\mywork> javac HelloWorld.java

This runs javac.exe, the compiler.  You should see nothing but the next system prompt...

C:\mywork> dir

javac has created the HelloWorld.class file.  You should see HelloWorld.java and HelloWorld.class among the files.

C:\mywork> java HelloWorld

This runs the Java interpreter.  You should see the program output:

Hello, World!