java for beginners
java
hello java
Wednesday 27 August 2014
what is public static void main(String args[]) in java
every java program start running from public static void main(String args[]) method.how ever your program is big its start from main method.
public : public is access specifier
example:
public class demo {} // A class, method, constructor, interface etc declared public can be accessed from any other class.
Therefore fields, methods, blocks declared inside a public class can be accessed from any class belonging to the Java Universe.
Therefore fields, methods, blocks declared inside a public class can be accessed from any class belonging to the Java Universe.
static : static is a keyword
in object oriented programming we have to create object of class to call particular methods. only that's why we called java is object oriented language
so if we use static keyword then java virtual machine create object automatic
it means you don't have to create object of class
that's why public static void main(String args[]) has static keyword
void:it is return type it return some value from particular method
example
1.no return type.
void run()//method have no return type so it will not return anything
{
System.out.println("hello programmers");//system.in for input on screen
//system.out for output on screen
//print for printing message to screen
//println for printing message to screen from new line
}
main: is a name of method
(String args[]).
Those are for command-line arguments in Java.
In other words, if you run
java MyProgram one two
Then args contains:
[ "one", "two" ]
public static void main(String [] args) {
String one = args[0]; //=="one"
String two = args[1]; //=="two"
}
The reason for this is to configure your application to run a particular way or provide it with some piece of information it needs.
Subscribe to:
Posts (Atom)