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 / sudheer nath

public means the main functiio can be accessible outside the class the jvm remain outside the class so we add the public visiblity mode.
static means the compiler automatically called the main ()functio without creating its instance or object.
void is the return type of the main function means main() does not return any kind of values to its caller means jvm.

Is This Answer Correct ?    0 Yes 0 No

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

Answer / abhi

it is bcoz...
since MAIN is also a method and it is not called by creating instance it is declared STATIC so that it is invoked by the JVM without creating instance.....

PUBLIC because it is called by the jvm which is not is not a part of the class directly.....

VOID because it does not return any value.....

Is This Answer Correct ?    0 Yes 0 No

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

Answer / anil chahal

We write main method as static because we call this method
from class name. We are not instancing by making its object
so if we call from class name we must have to write static .
we write void because main method is return nothing.Public
because there is always only one main class that is one file
having only one main file, because this main file may be
used anywhere means
outside this package so public keyword is must.

Is This Answer Correct ?    0 Yes 0 No

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

Answer / madhu

public static void main()

Public:-->The method is public because it be accessible to
the JVM to begin execution of the program JVM is outside of
the class.

Static:--> 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

Void:--> 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

Main:--> Main() is the entry point of the program. Rather
we can say it is the main gate to enter inside the
apartment. It should be public because the compiler need to
enter inside the method (The guest need to access the
apartment to reach the security guard).

Is This Answer Correct ?    0 Yes 0 No

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

Answer / preetham m.s.

he main method is the first method, which the Java Virtual
Machine executes. When you execute a class with the Java
interpreter, the runtime system starts by calling the
class's main() method. The main() method then calls all the
other methods required to run your application. It can be
said that the main method is the entry point in the Java
program and java program can't run without this method.

The signature of main() method looks like this:

public static void main(String args[])

The method signature for the main() method contains three
modifiers:

public indicates that the main() method can be called by
any object.
static indicates that the main() method is a class method.
void indicates that the main() method has no return value.

Is This Answer Correct ?    0 Yes 0 No

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

Answer / marrapu venkatesh.

Public: the reason for using public is to be accessed by the jvm. if u write private it should not be recognized by the jvm to execute. public methods accessed out of the class that's why we write public.
Static: the reason for static is when the program execution start main method should be invoked first. static method is called first. because we cant create object to main class to call methods. that's why we write static.
Void: In java main function does not return any value.

Is This Answer Correct ?    0 Yes 0 No

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

Answer / pandurang d billavar

for execution of class in java is done by creating a object
for methods of that class.so main method is also a class
method.so this method is called by jvm directly without
creating object for main method.it is possible only if main
is static.............so we maked main as static.

Is This Answer Correct ?    0 Yes 0 No

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

Answer / hari kiran

I think so it is done because all the java receives
everything in the form of a string.

Is This Answer Correct ?    0 Yes 0 No

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

Answer / ratna

As said by Prabhakant Prabhakar Rasal
if There are two main reasons to write string args[]
1. TO identify the program
2. To get command_line arguments

How does the string args[] helps in identifying the program ????

Is This Answer Correct ?    0 Yes 0 No

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

Answer / srinivas_cena

public- public isa access specifier,so we can use the method from out the class
static- static is a keyword which is used to calla methos with out creation of object for a class. so jvm directly runs from main() method.
void- main() method does not return any value so it has void data type.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

How does final modifier work?

1 Answers   Tech Mahindra,


What does substring mean?

0 Answers  


What is initial size of arraylist in java?

0 Answers  


Can we declare register variable as global?

0 Answers  


What is cr keyboard?

0 Answers  






why do we use interface in java?

5 Answers  


How many types of variables are there?

0 Answers  


How do I write a self declaration?

0 Answers  


Can you call a method in a method?

0 Answers  


Is there any case when finally will not be executed?

0 Answers  


What is a flag value?

0 Answers  


What is the static field modifier?

0 Answers  


Categories