Sample of java program
Sample of java program to print " Hello Java" on screen with short
description to easy understand the java program.
Sample Program
public class Hello
{
public static void main ( String args[] )
{
System.out.println("Hello Java");
}
}
class name and file name are same.
public is a access specifier this define the scope of the method or class.
static means that method is associated with the class, not a specific instance(object)
of that class.
void specify the return type of the method.
array args[] is a String array use to get value from command line argument.
In System.out.println()
- System is a in-built class which is present in "java.lang" package.
- out is a static final field (ie, variable) in System class which is of the type
PrintStream ( a built-in class, contains methods to print the different data values ).
- println() is a method use to print any message in nee line. we also use print()
method is to print message is current line.
how to compile ?
javac programName.java;
ex:- javac Hello.java;
how to Run ?
java MainClassName;
MainClassName means class which contain main method.
ex:- java Hello
O/P :-
0 comments:
Post a Comment