First Java Program
Here is the very basic java program :
public class Welcome
{
public static void main(String args[])
{
System.out.println("Welcome to Java!!");
}
}
Output :
Description :
public class Welcome
Here :
-public : Access specifier which indicates that this class definition can be used by other class.
That is another class can be inherited from this class and this class definition can be used by
the methods of other class.
-class : It is a keyword that is used to create a class.
In Java all the programs are done in classes. Means we have to create a class to do any
program like sum of a number etc.
-Welcome : It is the name of the class
public static void main(String args[]) : This is the main method of java. The execution of
program starts from this main method. We have already discussed it in detail.
System.out.println("Welcome to Java!!") : This function is used to display the message or
result. We have already discussed it in detail.
Important Note :
- Save notepad file as "Welcome.java". That is the class name and file name should be
the same.
We will discuss the steps to compile and run the java program in the next topic.
0 comments:
Post a Comment