Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Javacodeexamples Very simple `Hello world' java program that prints HelloWorld

Related Tutorials


 
 

Share on Google+Share on Google+

Very simple `Hello world' java program that prints HelloWorld

Advertisement
Very simple `Hello world' java program that prints HelloWorld Hello World Java Simple Java Program for beginners (The HelloWorld.java) Java is powerful programming language and it is used to develop robust applications. Writing a simple Hello

Hello World Java

Simple Java Program for beginners (The HelloWorld.java)

Java is powerful programming language and  it is used to develop robust applications. Writing a simple Hello World program is stepwise step. This short example shows how to write first java application and compile and run it. I am assuming that latest version of JDK is installed on your machine

HelloWorld.java - the source code for the "Hello, world!" program

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

How to save 
To run this program, save it in a file with the name HelloWorld.java. It must be sure that the file name must match the name of the class.

Compile the program

javac HelloWorld.java command is used to compile the source code.
When you compile the program you'll create a byte-code file named HelloWorld.class.
You can confirm this with the dir command in the DOS/Windows world.

Execute the byte code
Now you can execute the byte code in the Java interpreter with this command: 
java HelloWorld

Output of the program
When you run the program at the command line, you'll see this output 
Hello, world!

Understanding the HelloWorld.java code
Let's examine the HelloWorld.java file. Class is the basic building block of the java program, java codes are written in the java class. 

class HelloWorld{

//Java Codes

}

Java codes are saved in the same name as the class name.java, so we have saved the file with the name "HelloWorld.java".

There is one method  public static void main (String[] args)  which is necessary to for any class to be runnable. This function is the entry point of the execution. And the code System.out.println("Hello World!"); actually writes the Hello World! on the screen

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 30, 2005

Related Tutorials

Discuss: Very simple `Hello world' java program that prints HelloWorld  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:21
chuks francis
September 22, 2012
how to write simple program using java

tanx is helpful but i need more codes and tutorials
vivek
September 26, 2012
java

nothin
Swetha
December 28, 2012
Java

I want to know which software is necessary for java
LUIS
October 13, 2012
THANKS

The exanple code worked fine. First I had a problem with locating my HelloWorld.java file but then I changed it to C:\projects and then it worked ok. I had to set the environment to: Variable name = PATH Variable value = (C:\Program Files\Java\jdk1.7.0_07\bin) I hope this info is useful.
mr senvida
November 13, 2012
i'm beginer for start java

how to start java
jaqueline reyes
November 16, 2012
CS202

It's good....
arunkarthik.p
April 11, 2013
java

it,s very useful to me
arunkarthik.p
April 11, 2013
java

nice
DEEPENDRA
July 21, 2013
java program

how to learn different type big programs
DMCA.com