answersLogoWhite

0


Best Answer

Well, if an application could be run without a main method, then you would not need it. However, Java applications cannot run if they do not contain a main method.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: If application can be run without main what need of main method?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why static is used in main method?

It is declared static because the JVM would need to execute the main method and if it is not static the JVM would need an object of the class to access the method. How can the JVM get an object of a class without invoking it. since it is static, the JVM can easily access it without this need to have an object of the class.


Why main function written as public static in java?

They are public because they must be accessible to the JVM to begin execution of the program. Main is the first method that would get executed in any class.They are static because they must 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.OrMain is starting point of the program execution Main method is called by JVM there is no need for JVM tocreate an object of the class just to access Main function


What is need of static method?

If you need to access a method without creating an object of corresponding class, it need to be a static method.


Is it possible to define a java static method inside a main method?

Because, the main method is the starting point of the java program and if we need an object of that class even before the main can be invoked, it is not possible. Hence it is declared static so that the JVM Can acess the main method without having to instantiate that particular class


How to write java program without using main method?

Java program without mainWe need a main method for executing a program.But YES we can write a program without using main() method.TRICK 1 of 2 :: while writing applets in java we don't use main... we use init() method instead.TRICK 2 of 2 :: using 'static' we can write a program whic will execute successfully and output the desired message on screen. Here it is :: class Mohit{ static { System.out.println("This java program has run without the main method"); System.exit(0); } } -->save the program as Mohit.java to compile::javac Mohit.java (in command prompt) to run ::java Mohit(command prompt) output will be ::This java program has run without the main methodWhoa!!!!! we are done.;)


Why java program is not running without the IOException declaration in main method?

Most likely, one of the methods you're calling is throwing an IOException. You either need to declare it to be thrown in the main method or surround the statement with a try-catch block.


Why main method is static?

Main method in java is always static as main method id the only method from where the program execution starts,and as we all know that main method is defined inside a class so JVM needs to make a object of the class to call the method and objects are build inside the main method ,so to execute the main method it has to make objects of the class but objects are build inside main method so that's the reason that main method is static so that JVM can execute the main method without making its object as static members can be called by class anme only


Why is it the main method is a static method?

It doesn't need to be shared among several objects.


Why main is used in java?

In java need main() method. without main() in java we won't run the java programe main() signals the entry point to the program - it tells the Java Virtual Machine which is the first program that should be executed.


Can we write static public void main in java?

the method of an class that can is triggered when starting a Java application e.g. by running the command: "java MyProgram" Answer Public is an Access Specifier,static is a keyword which illustrates that method shared along all the classes.void illustrates that this method will not have any return type.main is the method which string has an argument. Public specifier makes the method visible outside the Class and because of the static nature of the method, JVM can call this main method without instantiating the class 'MyProgram'.


What is the parameter specification for the public static void main method?

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.


What is the use of main method in java?

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.