CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS J2EE JAVA DETAILS
Question :
Why we have used to in main method in JAVA this words
1)public
2)static
3)void
4)main
5)(String args[])


Posted by: satyanarayana on 12/11/2007

Contact satyanarayana  Contact satyanarayana
Category Java Interview Questions
Rating (3.0) By 1 users
Added on 12/11/2007
Views 1382
Rate it!
Answers:

The "public" keyword is an access specifier,which allows the programmer to control the visibility of class members.
When a class member is preceded by "public",then that member may be accessed by code outside the class in which it is declared.
In this case,main() must be declared as "public",since it must be called by code outside of its class when the program is started.
The keyword "static" allows main() to be called without having to instantiate a particular instance of class.
This is necessary since main() is called by the JVM before any object are made.The keyword "void" simply tells the that main() doesnot return a value .As we will see, methods may also return values.
"String args[]" declares a parameter named "args", which is an array of instance of the class "String".(Arrays are collections of similar objects).
Objects of type "String" store character strings. In this case, "args" receives any command -line arguments present when the program is executed.



 Posted by: Purella Satyanarayana    

Contact Purella Satyanarayana  Contact Purella Satyanarayana

public means common for all classes.
static means common for all objects.
void means it did nt return any thing.
Strung args[] is for what ever we enter through command line argument that will be collected in one arry i.e args[].



 Posted by: sunitha    

Contact sunitha  Contact sunitha

This uses public so that it is visible every where
This is static so that to call this function we don't need to create the object of that class its belong to.
It uses void to maintain a standard, because if we write int or char or anything else then it wont be proper function overloading.
We use String arg[] to get any no. of argument that we want from the user,If we give different arguments then it means that we are overloading, to avoid it we have a standard.



 Posted by: shweta    

Contact shweta  Contact shweta

In main method each word have specific meaning like we declare main method as public so that JVM will able to execute it(i.e. method will accessible outside the class in which it is declared).We declare it as static so that JVM will able to execute it without creating object of that class .we declare void to inform that main method doesn't return any value & args[] is array of type String which is called as command line argument & we can pass value at runtime to main method.



 Posted by: Rahul pande    

Contact Rahul pande  Contact Rahul pande

PUBLIC is used so that main can be accessed out of the class.

STATIC keyword is used so that main can be accessed without creating object of the class in which main is declared
VOID is used because main is also a function and function should have return type
MAIN-main is function from where our function starts and from main all other function are called
String args[]-is used for the command line argument and is part of syntax of main,also String is a class in which any type of data type can be accepted.



 Posted by: krishna    

Contact krishna  Contact krishna

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 does not return anything so the return type must be void.
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: reddy    

Contact reddy  Contact reddy

"public" means main method available any where inside or outside of the class.
"static" it means that without using an object main method will be executed.
"void" it means main method doesn't return any value.

string(args) it means it accepts data from outside into the method.It is string type arguments thier value passed to main method



 Posted by: sandeep    

Contact sandeep  Contact sandeep

public is for access modifier.
void is return type.
String args[] is String type arguments.



 Posted by: rusho    

Contact rusho  Contact rusho

static=because it can be call by without creating object of class
public=can be accessed from anywhere
void= return nothing
main= to tell that it is entry point of program.

i think now you get your answer



 Posted by: Pankaj Goswami    

Contact Pankaj Goswami  Contact Pankaj Goswami

public is a access specifier which allows the programmer to control the visibility of class members.

we use static keyword because the main function is called before initialisation any object.To do this the main function is declared as static

The main function doesnot return any value.so,it is declared as void

string args declares a parameter named args
args receives any command line arguments present in the program



 Posted by: mahi    

Contact mahi  Contact mahi


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
Addition of two numbers using Bitwise operators.
Reading An 2D array using single for loop
View Answer
What is UML patterns?give me clear explanation
View Answer
While developing one in JSP page we are sending request to Struts frame work.If we click two times submit button then First time only it should accept request and second time should reject that request in struts frame work.

How we can do that in controller itself...I am waiting for your Response...

View Answer
Can I execute or call one applet from another applet? If so then how??? Please Reply me...
Thanks
View Answer
what is method declaration,method attributes,method modifiers and parameters
View Answer
System Class is Used to Output text onto the Screen?
it True or False
View Answer
what is the first statement in construtor?
View Answer
What is the abstraction? Give example?
View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL Java Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/12582/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

1.28