Core Java Interview Questions and Answers
<< Previous Question Next Question >>
 Question: 1621 Page Views: 

Expain each keyword of public static void main(String args[])?



Posted By: Avi Date: 9 November 2009 06:12:58 AM
 Answer:

public:
main() is the first method called by java environment when a program is executed so it has to accessible from java environment. Hence the access specifier has to be public.

static:
Java environment should be able to call this method without creating an instance of the class, so this method must be declared as static.

void:
main() method does not return anything so the return type must be void.

args[]:
The argument String indicates the argument type which is given at the command line and arg[] is an array for string given during command line.


Posted By: eTechPlanet


Date: 9 November 2009 06:12:58 AM

public static void main( String[] args ):

1. public - declares that the main method is publicly accessible to other classes.

2. static - declares that the main method can be invoked without creating an instance of the class.

3. void - declares that the main method does not return any value.

4. main - defines the name of the method.

5. String[] args - defines a parameter to the main method which will contain any command line options passed by the user when invoking the program.

These command line options will be passed to the program as an array of string objects.


Posted By: Johndecruse


Date: 17 February 2010 12:29:47 AM
Post a better Answer if you have
 
(Will show your Gravatar icon)  
  Country flag

Loading
Enter the text as shown in the image ou1dXa
Related Questions
Core Java : What is the difference between a break statement and a continue statement?

What is the difference between a break statement and a continue statement?

A break statement breakes from the loop. A continue statement is used to end the current loop iterat....
Category: Core Java Date: 11/7/2010 8:24:48 PM
Core Java : What is a native method?

What is a native method?

A native method is a method that is implemented in a language other than Java
Category: Core Java Date: 11/7/2010 8:13:52 PM
Core Java : Can the object that is garbage collected be reachable again?

Can the object that is garbage collected be reachable again?

No, it is once that an object is garbage collected.
Category: Core Java Date: 11/7/2010 6:02:49 PM
Core Java : Can an object be garbage collected while it is still reachable?

Can an object be garbage collected while it is still reachable?

A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected.
Category: Core Java Date: 11/7/2010 5:18:53 PM
Core Java : Can Thread be serialized?

Can Thread be serialized?

No
Category: Core Java Date: 11/7/2010 4:57:47 PM