Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

Hot Searches
struts-config.xml  web.xml  Java date format  read/write text file using javascript  ArrayList  Insert Data into Database Using Hibernat  create text file using java  insert data to text file using java  Visual Basic Date and Time Display the t  Create table and insert data by sql quer 

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Understanding Hello World Java Program

                         

Now you are familiar with the Java program. In the last lesson you learned how to compile and run the Java program. Before start hard programming in Java, its necessary to understand each and every part of the program. Lets understand the meaning of  public, class, main, String[] args, System.out, and so on.

 

 

 

 

 

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

Class Declaration:

Class is the building block in Java, each and every methods & variable exists within the class or object. (instance of program is called object ). The public word specifies the accessibility of the class. The visibility of the class or function can be public, private, etc. The following code declares a new class "HelloWorld" with the public accessibility:

public class HelloWorld { 

The main Method: 

The main method is the entry point in the Java program and java program can't run without main method. JVM calls the main method of the class. This method is always first thing that is executed in a java program. Here is the main method:

public static void main(String[] args) {

......
.....

}

{ and is used to start the beginning of main block and } ends the main block. Every thing in the main block is executed by the JVM.

The code:

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

prints the "Hello World" on the console. The above line calls the println method of System.out class.

The keyword static:

The keyword static indicates that the method is a class method, which can be called without the requirement to instantiate an object of the class. This is used by the Java interpreter to launch the program by invoking the main method of the class identified in the command to start the program.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

6 comments so far (
post your own) View All Comments Latest 10 Comments:

pliz help me write a jav program that prints 10 multiples of a certain number which are greater than a certain number

Posted by Thaane on Wednesday, 09.17.08 @ 23:20pm | #80145

how to draw two flowcharts. The first chart will describe how a program called Hello is programmed using C# or Java (your choice) from the very beginning when you write the program to the beautiful end when the program is stored to hard disk to folder c:\programs\hello in the executable form (named hello.exe). Describe the phases from C# -program to executable.

Posted by Eric kwasi on Thursday, 05.8.08 @ 21:28pm | #58944

Firstly, I haven't understand ur tutorial and secondly, what is it's use

Posted by Ravi on Thursday, 10.4.07 @ 23:36pm | #31413

class A{
-----
}
class B extends A{
---------
---
}
public static void main( string args[])
{
-------
}is this excuted with out creating object?

Posted by suman on Friday, 05.4.07 @ 11:48am | #15254

After succesful compilation when i give the command java HelloWorld
i got the error as
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld

what is the reason

Posted by srinadh on Sunday, 03.11.07 @ 16:47pm | #11368

sir please tell me why we use static variable.

Posted by hardesh kumar on Thursday, 02.1.07 @ 12:40pm | #5164

Join and Excel yourself with our Online instructor led training sessions
Integrated Struts 2 Hibernate and JPA Training
Java Training
Hibernate Training
JPA Training
JSF Training
Spring Framework Training
Struts 2 Training
EJB 3 Training
PHP Training
Junit Training
DbUnit Training
Ajax Training
IBM Websphere Training
Design Patterns Training
Weblogic Training
Tomcat Training
JMS Training
Jboss Training
Servlet Training
JSP Training
JavaFX Training
SQL Server Training
TPTP Training
Tell A Friend
Your Friend Name

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.