Sunday, 8 June 2014

ESSENTIALS OF JAVA PROGRAMMING



ESSENTIALS
Consider a simple java program.
class hello
{
public static void main(String ar[])
{
System.out.println(“HELLO”);
}
}                  //main ends here
Let us now examine the parts of this simple program
   1.     class hello
the line class hello means that a class is defined. The defined class is the initial class (an initial class is a class that contains a main function inside it). It should be kept in mind that the class name is same as the name of the program. The extension of the java programs is given as .java.
   2.     Method main
Our class contains one method and the name of this method is main. The main method is where a program begins execution. if we have multiple classes then the execution of the program begins from the point where main method is encountered, if we do not have a main method then the program will not get executed. The main method is also termed as driver method because it drives our program.
   3.     System.out.println("Hello”)
This statement prints HELLO to our standard output device which is generally our monitor. We must notice that this statement is terminated by semicolon(;) as usual.
   4.     Comments /*……..*/ and //
We include comments in our program to enhance code readability. /*…..*/ is used to write multiline comments and // is used to write single line comments. The comments are ignored by the compiler and not executed at all even if we write a valid java statement.

No comments:

Post a Comment