Saturday, October 1, 2011

Simple Program

class Hello
{
public static void main(String arg[])
{
System.out.println("Hello, I am Human");
}
}

Brief consideration in above simple program:
class: we are declaring a new class using keyword 'class'.
Hello is the name of class. We put all the code( members of class) between opening curly braces({) and closing curly braces(}).
public- It will available the main method to the interpreter.
static- Allow to call the main() without instantiation of object.
void- no return type.
main() method is called at run time.
String ar[]: array of String type.
We pass the parameter (String ar[]). It means we are able to take input from command line as string.
It is always necessary to pass this parameter to main method either we are taking input or not in our program.

System is predefined class in java and out is object.
'System.out ' is reference of PrintStream class.
It connect the file(in above example "Hello, I am human") to the command line.
println() is method in System class which print output/string/text in command line.

Output of above program is as follow in command line:


No comments:

Post a Comment