Example;-WAP to print a message “Welcome to Java World”.
public static void main (String args)
System.out.println ("Welcome to Java World");
Welcome to Java World
Explanation of above program
public static void main(String args)
All Java applications begin execution from main ( ) function. (This is just like C/C++.)
- The public keyword is an access specifier, which allows the programmer to control the visibility of class members. When a class member is preceded by public, then that member may be accessed by code outside the class in which it is declared.
- The keyword static allows main ( ) to be called without having to instantiate a particular instance of the class.
- The keyword void simply tells the compiler that main ( ) does not return a value.
- As stated, main ( ) is the method called when a Java application begins. Keep in mind that Java
is case-sensitive. Thus, Main is different from main.
- String args[ ] declares a parameter named args, which is an array of instances of the class String. (Arrays are collections of similar objects.) Objects of type String store character strings. In this case, args receives any command-line arguments present when the program is executed.
System.out.println (“This is a simple Java program.”);
This line outputs the string “This is a simple Java program.” followed by a new line on the screen.
Output is actually accomplished by the built-in println( ) method. In this case, println( ) displays the
string which is passed to it.