Tuesday, 27 November 2018

Java - My First Java Program

class A (1)
{ (2)
   public static void main(String args[]) (3)
         {(4)
              System.out.println(“Welcome To Java”);(5)
         }(6)
}(7)
(1)
Every one java program must be within class. Class name must be started with capital letter and each one word’s first character should be capital letter. It is the convention only. 
(2)
Open brace for class
(3)
public
Modifier of the method, to access this method by by Runtime. 
static
The main method will be called by Runtime without object. It means before instantiation all objects. So the main should be a static method.
void
It is the return type. main() will not return anything to caller.
main
   Method name
String args[]
Arguments can be passed to main, when you run the program. The types of parameters should be String. The parameters will be stored in args[]. The name of variable(args) may be differed.
(4)
     Opening brace for main
(5)
System
   It is the class of java.lang package
System.out
out is the static variable of System. System.out returns java.io.PrintStream class object. So we call the println() by using PrintStream object.
println()
   It is a method of java.io.PrintStream. This method is deprecated. Deprecation means the method is not recommended but still available. It is used to print given statement in console.
(6)
Closing brace for main
(7)
Closing brace for class.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.