Core Java Tutorial 04 – Running First Java program without Eclipse IDE – HelloWorld Java Program

In this video tutorial, we will create our first Java program ( HelloWorld Java Program ) and run using javac and java commands on windows command prompt.

Also, we will understand why we set PATH Environment variable with the Java installation path upto bin directory and run a Java program without Eclipse IDE ( using Microsoft Notepad text editor)

For our readers who are unable to access the Video Tutorial!!!

`For Writing the First Java Program:

1) Write the Java Program in notepad as shown below foe eg : Hello World Program – which prints “HELLO” message as output.

public class HelloWorld {
 public static void main(String[] args) {
 System.out.println("Hello, World");

[ We will learn about class, public etc in subsequent tutorials ]

2) Save the file with the name [ Important Point to be noted-the file containing a java program has to be saved with .java file extension. ]

3) With this step program is saved in the D Drive ( storing in any of the drives according to your wish ) .

4) Now to run the Java Program Compilation needs to be done.

[ Compilation means- translation of the Java Program language to the computer language ]

5) Open command prompt window and go to d: drive ( here the drive  where you saved the program ) and type javac and press enter – this step will compile the java program and produce another file in the same directory with the same name but different file extension i.e . class.

Hence this step will produce a file with the name HelloWorld.class and with this step compiling the program process is completed.

6) For Running the Java Program- type java HelloWorld ( java and file name ) the output – HelloWold, this is my first java program is produced.

7) Now comes the Importance of setting the Path Environment Variable on our computer ( as discussed in our Tutorial 03 )

To compile the Java Program using Javac and java commands placed in the Bin Directory of Java provided by Java people for compiling and running a java program. There are two options for instructing computer to compile and run a java program using javac and java programs.

a ) Option 1– Use Commands

javac —– for compiling a Java program
java filename —- for running a Java program

b ) Option 2 – Use commands javac and java with their full path (full path means the exact path where these programs are present on your computer.)

C:\ProgramFiles\Java\jdk1.7.0._51\bin\javac filename. java -For Java Program Compilation

C:\ProgramFiles\Java\jdk1.7.0._51\bin\java filename. java -For Java Program Running

( i.e. full path of javac and java programs..

[ Java Installation directory\bin\javac or Java installation directory\bin\javac ]

As we can see that the first option is better because you do not need to write full path of javac and java programs for compiling and running a java program.So if you are going with first option: you will need to perform one time activity before compiling and running a java program and i.e setting up PATH environment variable with the Java installation path upto bin directory and, there after you go on using just javac and java without including their full location in the commands for compiling and running a java program.

Here we have successfully completed running our First Java Program.

Happy Learning!!!