Write your first simple java program.


First of all we need is a placewhere we can write your Java code. All Java programs are written using plain text files such as a notepad.Therefore there is no need of a fancy software.Lets come to write your first program.For this you open a notepad and start writing a code.The program code looks like this:

class HelloWorld


  public static void main(String[] args)


 System.out.println("Hello World!");



For your first program we are going to understand step by step process to compile and run a program.

1.The first step is to save the file written on the notepad.



A dialog box is open as show above. Now save your file as "HelloWorld.java". Now I have created an directory in My Documents called "Java" to store the all the Java programs in one place for my convience. You are free to create a another folder on your computer as you prefered.


It is very Sincere while saving a file you must save a file as "HelloWorld.java".

class HelloWorld


The above code is an instruction to call the class "HelloWorld".

2. Then we need to open a Terminal Window as show below.



Most of the program are window application you are use a cursor to open a file but the above program are a example of console application it does not run on its own window its needs a terminal window to run a program. A terminal window is a source to run a programs that is stored on your hard drive.

Now to open a terminal window, press the "Windows key" and the letter “R” at one time.

Now a dialog box is open and type a cmd and press ok.

3. The Java Compiler



Now what is a java compiler .It is one of the console program is the Java compiler called "javac". Its function is to read the code in the HelloWorld.java file, and then translate it into a language that your computer understand. This process is known as called compiling.In Java every program you write in a notepad they have to be compiled before it can be run.

To run javac from the terminal window,First of all you need to tell your computer where The file is located on your computer.Now you give the directory just like I give here my location is "C:\Program Files\Java\jdk\1.6.0_06\bin". If you have the same directory then use it otherwise search your directory from your computer.

When you found your directory location, type the following command into the terminal window:

set path= *the directory where javac located*


set path=C:\Program Files\Java\jdk\1.6.0_06\bin

Now press Enter. The terminal window return you something in a flash, It will be the command prompt. At last the path to the compiler has now been set and ready to use.


 4. Change the Directory as you preferred


Now,you think where your HelloWorld.java file is saved in your computer. My file has been saved in a directory called "Java1" in My Documents. The location is as "C:\Documents and Settings\Chandan\My Documents\Java1".

Follow the below code to change the directory in the terminal window, type in the command:

cd *directory where HelloWorld.java file is saved*


cd C:\Documents and Settings\paul\My Documents\Java1


5. Compile Your Program


Now you are ready to compile Your program. For that, enter the command:

javac HelloWorld.java

When you hit Enter buttom, the compiler work start and look at the code contained within the HelloWorld.java file, and try to attempt to compile it if yor program does not contain any error. If it contain error, it will display a series of errors on the command prompt which help you fix the code.After fixing the error again try to compile your program in the same manner as discuss above.

Tip: After your HelloWorld program has been successfully compiled, and you will see a new file in the same directory. It will be the “HelloWorld.class”.


6. Run the Program


And at last the only thing is to remain is to run the program. In your terminal window type the command:

java HelloWorld

When you press Enter, the program will run and you will see a output as "Hello World!" written to the terminal window.

This all about your first java program keep going I will discuss the core java in a brief in my next article . Thanks for reading my article.


Like it on Facebook, Tweet it or share this article on other bookmarking websites.

Comments (0)

There are no comments posted here yet

iPhone 5 is worth for the price?

iPhone 5 is worth for the price? share your oponion  

No answer selected. Please try again.
Please select either existing option or enter your own, however not both.
Please select minimum 0 answer(s) and maximum 3 answer(s).
[{"id":"21061","title":"yes its worth","votes":"47","type":"x","order":"0","pct":43.93,"resources":[]},{"id":"21062","title":"No, not at all","votes":"33","type":"x","order":"0","pct":30.84,"resources":[]},{"id":"21063","title":"i don't know","votes":"27","type":"x","order":"0","pct":25.23,"resources":[]}] ["#ff5b00","#4ac0f2","#b80028","#eef66c","#60bb22","#b96a9a","#62c2cc"] ["rgba(255,91,0,0.7)","rgba(74,192,242,0.7)","rgba(184,0,40,0.7)","rgba(238,246,108,0.7)","rgba(96,187,34,0.7)","rgba(185,106,154,0.7)","rgba(98,194,204,0.7)"] 350
bottom 200
No married couple wants to end up getting divorced. It is not like they have planned for it. They try to put up with their partners for as long as they
Due to our modern lifestyle, we feel that digestion related disorders are a common problem. Thus, we neither give importance to them nor seek any help
The bond of marriage brings the two people together. Initially, everything may seem okay and both of them slowly start discovering each other in the journey.