Saturday, March 28, 2015

Simple Java Program | Java Hello World Program | How to Program | Learn to program

Here we are starting up with our first java program. The following code snippet is our first simple java program. It just prints "Hello World!".


//call this program First.java
class First
{
 public static void main(String args[])
{
  System.out.println("Hello World!");
}
} //ends here

Description of the Program:
  • The first line of the program is the comment. It just gives the important information about our program. It is not an executable(runnable) statement. There are other ways also by which we can enter comments in the program which we will discuss later.
  • The second line of the code is the starting statement. It defines a class named First(it can be any name). Class is the container in which whole program resides. The rule says the first letter of class name should be capital letter. We will dealing with more sophisticated classes later.
  • The third line is the curly bracket({). It tells the starting of the program.
  • Next line is the main method. From here the program execution starts. It has been declared public so that it is accessible from everywhere in the program. Public is an access specifier. It is declared static so that is does not need to be instantiated(need not to make object). Next is void that means this method is not returning anything. In the bracket we have declared an array named args which is made string type. It saves whatever the program doing.
  • Next line is again curly bracket which marks the beginning of main method.
  • Next line is the output statement. It has many things. System is telling  the output should be on the standard output screen. Out is for output. Println is printing , here "ln" means it will send pointer to next screen after printing the line.
  • Next is the curly brackets. If we are opening two brackets then we have to  close two brackets.

0 comments:

Post a Comment