This post is a step by step guide for Hello world Java program using command prompt.

Note: Below screen shots are for windows 64-bit version. Please act accordingly for 32-bit versions.

Step-1: Download Java.

Click Here to download Java 7 SDK.

You will see that there are two folder created in your C:\\Program files\Java. (In my case I already had Java 6 installed too).

Step-2: Add Java to classpath.

set path=%path%;C:\Program Files\Java\jdk1.7.0_79\bin; 1 set path = % path % ; C : \ Program Files \ Java \ jdk1 . 7.0_79 \ bin ;

Restart your computer after changing path.

Step-3: Code Java Program.

Create the folder structure <BASE_FOLDER>/<PACKAGE> where <BASE_FOLDER> can be any folder of your choice and <PACKAGE> is the package that is used in your helloworld program. For my example below I have used ‘D:\develop\tutorials\HelloWorld\src\’ as <BASE_FOLDER> and ‘\com\srinichekuri\helloworld’ as <PACKAGE>. Copy and paste below code to a note pad and save it in <BASE_FOLDER>/<PACKAGE> folder.

package com.srinichekuri.helloworld; /** * Hello World Java Program * * @author Srinivas Chekuri * */ public class HelloWorld { public static void main(String args[]){ System.out.println("Hello World - Core Java!!!"); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 package com . srinichekuri . helloworld ; /** * Hello World Java Program * * @author Srinivas Chekuri * */ public class HelloWorld { public static void main ( String args [ ] ) { System . out . println ( "Hello World - Core Java!!!" ) ; } }

Step-4: Compile File

Compile the file using ‘javac’ command.

javac com/srinichekuri/helloworld/HelloWorld.java 1 javac com / srinichekuri / helloworld / HelloWorld . java

After this you will see that a class file is created. This is the file that will be used for execution.



Step-5: Execute file

Execute file by running below program

java com.srinichekuri.helloworld.HelloWorld 1 java com . srinichekuri . helloworld . HelloWorld

Hope this is helpful!!!

Learn and share!!!