Gadgets

Friday, 12 September 2014

First Java Program



Java first program clear explanation:
public class FirstProgram {
    public static void main(String arg[])
    {
     System.out.println("this is the java first program");
    }
} 

Explanation:

è public class FirstProgram{
public keyword is an access modifier, it mean other class can access this class.
Class is a keyword to declare the class name.
FirstProgram is a class name of this program.
{ open brace, it mean starting of the class scope.
àpublic static void main(String arg[]){
Static is a keyword. If we declare a method as static, no need to create object for that method. Here no need to create object to invoke main method. The main method is executed by JVM.
Void is return. It does not return any value.
Main is a method name. It represents startup of the program.
(String arg[])  is main method parameter, it stores the  values as String array format  arg[] is a variable, we can given other name whatever we want(a[],b[],ect..).

Example :

String a=arg[0];
String b=arg[1];

{ open brace for main method. 

System.out.println(“this is the first java program”);
System is a class in the java.lang package.
Out is a static member of the System class
Println is a method of the java.io.PrintStream
} close main method
} close class

Execution: 

Save the above program as  : FirstProgram.java
Compile:  javac FirstProgram.java
Execution:  java FirstProgram
Output:   this is the first java program

Explanation in screen shots :
 









No comments:

Post a Comment