Saturday, August 15, 2015

Hello World...!

Hi All...!




Today I'm going to show you how to write, compile & run simple Java "Hello World" program.To write this program I'm going to use Notepad to write the program and Command Prompt to compile and run the program. Let's get started...


Write The Java Hello World Program


Open your notepad and write the following piece of code make sure you are writing exacts same code. Otherwise you will get a compilation error. Don't worry about the syntax other things in this code just write-down. I will teach you about all those syntax and keywords in my next post. 





Save Java Code With .java Extension


Click on "File" then select "Save as"





Then use the class name as your file name and file type as ".java". For this code File name will be HelloWorld.java and save that file on your "Desktop"








Compile and run the program



Open your Command Prompt (Start > Type "cmd" on search box and hit enter).

Step 1

Go to the Desktop using Command Prompt type "cd desktop" and hit enter.




Step 2

Compile the "Hello World" program. Type "javac HelloWorld.java" on command prompt and hit enter.






if get the same command prompt window as above you have compile your first code successfully...!
But if you get some error codes please check the program code I have given and correct your code.   


Step 3

Let's run the program. Type "java HelloWorld" and press enter.



If you can see the "Hello World" your program is running correctly



Did you see the .class file is created when you compile the .java file....?



Before compile the file




After the compilation 






In my 1st post I have told you we use programming languages to convert human readable and writable language to computer readable and writable language. Actually that task is done by compiler. Above .java file and the .class file is a good example for this task done by the compiler.
Let's open those files and check what's in it.


Open the .java file using Notepad



You will see the code you have written.





Open the .class file using Notepad


The code you are about to see is can't be read by a human correctly 





No comments:

Post a Comment