To understand how to create a program we have the following simple program.
class Hello
{
public static void main(string args[])
{
system.out.println(“hello this is my first java program”);
}
}
Description: we have declared the class with the name of ‘Hello’. As we know in java everything must be in the class. In the class we have the code to print something.
Then the brace is opened which means starting of the block at where we have to declare and write our functionality.
Then we have the ‘main’ function which contains the follows:
main function: The ‘main’ function in java is just like in the c, c++. The interpreter executes the code stating from this function.
Public: It is an access specifier just like in c++ and used to make accessible ‘main’ function for all other classes.
Static: Static declares ‘main’ function as not a member of any object and it refers to the whole class.
Void: void means the ‘main’ method does not returns any value.
Printing something: To print on the monitor we have the ‘println’ method which is the method of ‘out’ object and which is a member of ‘system’ class.
And to terminate any statement we must have to use semicolon.