The above program will give the following as output :
My First Program Running Perfectly
Note : JAVA is case Sensitive Language(means System and system both are different), so type carefully.The following explanation will help you :
Line 1 : import java.lang.*;
This line is optional . If you will not write this line in your code then the compiler will insert it automatically in your program.
“import” is a keyword(reserved words that have some meaning defined at the time of language development) used to import the classes from packages and sub packages.
“java” is a package that conatins a subpackage named “lang” and we are importing all classes inside “lang” package in our program by writing ” * ” .; is a terminator, used to terminate a statement.
Line 2 : public class FirstProgram
“public” is an access specifier ( will be explained later in detail ) used to indicate that this class can be accessed from anywhere.
“class” is a keyword which is used to define a class.
“FirstProgram” is the name of class. ( this can be any another name like “Program” but should not be a keyword)
Line 3 : {
“{” is known as opening brace and is used to create a block .This always come with a closing brace “}” (i.e for every opening brace there should be corresponding closing brace)
Line 4 : public static void main(String[] args)
This line is the point of execution.Interpreter always call this “main” method to start executing so this line is supposed to be written as it is.
“public” is an access specifier .”static” is a keyword which is used so that this “main” method can be called without making object of class “FirstProgram””void” is a return type of method “main” representing that this method is not returning anything.”main” is a method”(String[] args)” is the parameter passed to the “main” method.
Line 6 :
System.out.println(“My First Program Running Perfectly”);
This line is used to print the string inside the parenthesis on the screen(in our case it is “My First Program Running Perfectly”.”System” is a predefined class.”out” is the reference variable declared for the class “InputStream”.”println” is the method defined inside the class “InputStream”.
So this is the complete explanation of the first program in java.Contains a LOT of things to understand and learn.But believe me if you will go through these concepts then it will become very easy to learn further.
All the Best