answersLogoWhite

0


Best Answer

If you run an java file(as an .class or .jar file) there's always 1 method being called: The main(String[] args) method.

The method is only called once.

Example of an main method:

public static void main(String args[]) throws IOException {

LoggingBootstrap.bootstrap();

gui = new GUI();

}

In this case it only bootstraps the logger and uses the constuctor method of GUI(the graphical user interface of the program)

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

An empty main method in Java really has no use. Under most conditions, this will mean that your program will run, execute no code, and then exit.

Edit:

The main method is called after the static initialisation is complete. A main class with an empty main method will still execute any code that is in it's static initialisers and will initialise any static variables declared in the class. When these variables are initialised, code in there class's constructer will also be run.

This answer is:
User Avatar

User Avatar

Learn bay

Lvl 8
1y ago

The signature of the main method is public static void main(String[] ags). public static void main(String a[]) is the main entry point signature for a typical Java program.

To learn more about data science please visit- Learnbay.co

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

1- What is the task of main method in a java program?

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

The main( ) method tells the java compiler the start point for an application. This is similar to C and C++ which also use main( ) to identify the start point.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Object is the main class in Java Program

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

public static void main(String [] args)

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why using the name main for main method in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can InetAddress be used with inet6 in java?

Yes. Using the method InetAddress.getByName( String name) for instance.


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'.


How do you invoke static methods?

if some method is static, then you can not call that method through the oobject of that class. but the name of the class. let us see a example: class Test { int a; int b; static void show() { System.out.println("we are in show"); } } class Main { public static void main(String args[]) { Test t=new Test(); t.show();\\thiss is an erroraneous code. because, the method "show()" is static. Test.show();\\this is correct } Arnas Sinha


What is static void Main?

The String array args refers to the arguments that the program may require before starting. In many cases you may want the program to take some values as input for processing. this string array is for that purpose.


How do you call a method from another class in Java?

If the method is static you can do this way: Classname.method() If the method is not static then you would have to instantiate the class that contains this method and then call it using that object. Classname obj = new Classname(); obj.method()

Related questions

What is method call in java?

Calling a method in Java is when you run code associated with a specific class, using the name of an instance object of a class, followed by the dot operator, followed by the name of the method, followed by the arguments of the method, enclosed in parentheses.


Can InetAddress be used with inet6 in java?

Yes. Using the method InetAddress.getByName( String name) for instance.


How do am pass arguments in public static void main?

By using command line arguments we can pass values to the static void main method at the time of running the Java class. For example: if Class name is A,then to run this class and accepts command line then run this by using below line java A <argument1> <argument2> ....


What is the difference between function and method?

functions have independent existence means they are defined outside of the class e.g. in c main() is a function while methods do not have independent existence they are always defined inside class e.g. main() in Java is called method. ######## I've been studying OOP lately and had this question myself, so I will share my thoughts; I was taught that "A Function should do 1(one) thing and do it well." In specific Regards to PHP; The difference between a Method and a Function is that a Method is tied to a specific class. Hope this helps. -------------------------------------------------------------------------------------------------------- function can return value where as method can't that is the main difference between function and method --------------------------------------------------------------------------------------------------- Actually you are describing the difference between a function and a procedure. Function returns a value, procedure does not unless you are using c#, then everything is a function. In c# a function, to paraphrase the first answer, does and thing and does it well. A method contains functions. The most important method is the Main method. All functionality of a program must be referenced in the Main method because when you run a program, it starts at the beginning of the Main method, and stops wehn it hits end of the Main method.


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 name of the main island in Indonesia?

JAVA


How do you execute a Java program?

You can run a Java application from the command line using "java <name of the class>"


How do you invoke static methods?

if some method is static, then you can not call that method through the oobject of that class. but the name of the class. let us see a example: class Test { int a; int b; static void show() { System.out.println("we are in show"); } } class Main { public static void main(String args[]) { Test t=new Test(); t.show();\\thiss is an erroraneous code. because, the method "show()" is static. Test.show();\\this is correct } Arnas Sinha


What is static void Main?

The String array args refers to the arguments that the program may require before starting. In many cases you may want the program to take some values as input for processing. this string array is for that purpose.


How do you call a method from another class in Java?

If the method is static you can do this way: Classname.method() If the method is not static then you would have to instantiate the class that contains this method and then call it using that object. Classname obj = new Classname(); obj.method()


What is the difference between method and function in java?

A function is a piece of code that can be reused by calling its name while a method is a function that is associated with a class. In Java, functions are usually referred to as static methods.


What is function overloading in java?

Any function or method in Java that is coded by the programmer is called a user defined method in Java. The JAVA API (Application Programming Interface) has a set of predefined classes & methods that are for our usage. Whatever methods we create apart from these are termed as user defined methods. In java we not use the term functions. We call them "Methods"