Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


In Java why we write public static void main(String args[])
why not main()?

Answers were Sorted based on User's Feedback



In Java why we write public static void main(String args[]) why not main()?..

Answer / guest

main() will be treated as just another method.
but public static void main(String args[])
is treated as entry point of an java application

Is This Answer Correct ?    2 Yes 1 No

In Java why we write public static void main(String args[]) why not main()?..

Answer / shiva

In entire java program main() executes only once, so that
so that it is static.

Is This Answer Correct ?    1 Yes 0 No

In Java why we write public static void main(String args[]) why not main()?..

Answer / praveen

PUBLIC: in this we should access the function inside d class
or outside d class

STATIC:if any method is invoking obj is must.but using
static no obj is necessary.

VOID: void means nothig.in main method we should not declare
any value. so void is return type.

STRING[]ARGS:in java every input consider as a string

Is This Answer Correct ?    1 Yes 0 No

In Java why we write public static void main(String args[]) why not main()?..

Answer / kedar

static methods can be accessed without creating object object of class, we know that file name of java program is "classname.java", "classname" is the class which contain main function, so it is easier for compiler to locate class which contain main(), and because of static nature it can execute it.

Is This Answer Correct ?    1 Yes 0 No

In Java why we write public static void main(String args[]) why not main()?..

Answer / anil kumar.kommmisetty

In java we using a main method
i.e public static void main(String args[])
public > This is used for any where we can access.

static > This is used for constat and then first compile to
start.
void > should not return any value.

main > where to start the compile the program to tell.

String > it is a class.

args[] > this is used to tell the when ever u enter the
data that is treated as arguments to that program.

Is This Answer Correct ?    4 Yes 4 No

In Java why we write public static void main(String args[]) why not main()?..

Answer / guest

there is only 1 main class

Is This Answer Correct ?    0 Yes 0 No

In Java why we write public static void main(String args[]) why not main()?..

Answer / gowrishankar

The Main method is the method in which execution to any java
program begins.
A main method declaration looks as follows:

public static void main(String args[]){
}


The method is public because it be accessible to the JVM to
begin execution of the program.

It is Static because it be available for execution without
an object instance. you may know that you need an object
instance to invoke any method. So you cannot begin execution
of a class without its object if the main method was not
static.

It returns only a void because, once the main method
execution is over, the program terminates. So there can be
no data that can be returned by the Main method

The last parameter is String args[]. This is used to signify
that the user may opt to enter parameters to the java
program at command line. We can use both String[] args or
String args[]. The Java compiler would accept both forms.

Command line argument
Any number of arguments can be passed to the java program
through command line. While running the program any things
written after the name of the class are the command line
arguments. Arguments are delimited by the space.
This sample code prints all the command line arguments to
the console.
public class CmdLn{

public static void main(String[] args) {
System.out.println("d");
for (int i = 0; i < args.length; i++)
System.out.println(args[i]);
}

}


Java CmdLn arg1 arg2 arg3 arg4
Output:
arg1
arg2
arg3
arg4



so,if we simply give the main() function program wont work
without the access specifier.

Is This Answer Correct ?    1 Yes 1 No

In Java why we write public static void main(String args[]) why not main()?..

Answer / rahul

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 the class.
This is necessary since main( ) is called by the Java
interpreter before any objects are made.

The keyword void simply tells the compiler that main( )
does not return a value. As you will see, methods may also
return values.
about strings[] It takes no of arguements & stored in an
array ,input is of integer type it is taken as string. so
main takes arguments of type string.

Is This Answer Correct ?    0 Yes 0 No

In Java why we write public static void main(String args[]) why not main()?..

Answer / xyz

Public -> Because we want to access the main from the out side of the class generally when we run the java program at that time it call the main method.

Static ->Because it will create only one copy of main method and we can call with class name so when we run program it will
run main method using passed program name like name.main();

Is This Answer Correct ?    0 Yes 0 No

In Java why we write public static void main(String args[]) why not main()?..

Answer / amardip sabale

we write public static void main() because
public:for access of main function all over the program
static:main is also one type of method,and for calling this
method while running our program without creation of any
object
void:because it is not return anything
String args[]:because when we run our program then always
we pass at least two command line arguments(java and
program name)for collecting them we have to write it
*THANKS*

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

Write a program to find the greatest of three numbers in java?

0 Answers  


What is polymorphism and what are the types of it?

0 Answers  


What is toarray method in java?

0 Answers  


What is a substring of a string?

0 Answers  


I have a Arraylist object, it has duplecate values also. Now question is i want delete duplecate data in that objet with out using Set?

8 Answers   Aricent,


When does a class need a virtual destructor?

0 Answers   Flextronics,


What is byte code and why is it important to java’s use for internet programming?

0 Answers  


What is use of static method?

0 Answers  


Can we use different return types for methods when overridden?

0 Answers  


What is a variable and constant?

0 Answers  


What is the constructor?

0 Answers  


we r taking <load-on-startup>0</load-on-startup> <load-on-startup>1</load-on-startup> in deployment descripter for loading servlets like serv1 N serv2? so 'll it take serv1 or serv2

2 Answers   CSC,


Categories