//code for hello.java
class hello
{
public static void main(String args[])
{
System.out.println(”hello world”);
}
}
This is a simple hello world program. The most imp thing is that for every .java file there has to be atleast one class and the a class with the exactly same name as the .java file name. Like in this example the file name is hello.java and the name of the class is also hello ( please remember that even the case of the filename and the class name should match as java is a case sensitive language).
Next is the main function which is also imp as C/C++ but unlike C/C++ its in the main class (hello in this case).since main has to be accesed from outside when the program has to be executed so it has to be public ( which has same meaning as in C/C++ classes) and static so that its initialised only once, and void if it returns nothing.
The control flow of the program starts from the main function and goes line by line in sequence. “System.out.println” is a predefined function for console output. System.out.print is also a similar predefined function the difference is that println returns a newline at the end of the thing to be printed and print just prints the thing to be printed.
example :-
System.out.println(”1″);System.out.println(”2″);
this will print :
1
2
where as –
System.out.print(”1″);System.out.print(”2″);
will print : 1 2

