Here we create a simple Java program as follow :-
class Sample{public static void main(String args[]){System.out.println("This is a simple Java program.");}} |
Save this file as Sample.java
Compile it as:- javac Sample.java
Execute it as:- java Sample
Output is:- This is a simple Java program.
Meaning of Program:-
Let's see what is the meaning of different word's used in this simple java program
1) class - class keyword is used to declare a class in java.
2) public - public keyword is an access specifier,which allows the programmer to control the visibility of class member.Here public mean we can access the code outside the class.
3) static - static is a keyword. if we declare any method as static, then there is no need to creating/using object to invoke the method.
4) void - the return type. void means there's no return type.
5) main - entry level of program.
6) String[] args - arguments to the method.
7) System.out.print - it is a print statement.
Note:- If you find error "java is not recognized as an internal or external command ,operable program or batch file" it means path for java compiler is not set. to set the path read Setting up java.
No comments:
Post a Comment