answersLogoWhite

0

Why use void in main of java?

Updated: 8/11/2023
User Avatar

Wiki User

14y ago

Best Answer

No. void is not a data type.

It is mandatory for all java methods to return something and if it is not going to return anything, we have to mark the method with a "void" return type to let the JVM know that it must not expect anything from the method.

User Avatar

Wiki User

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

Wiki User

14y ago

We use void because the main method doesn't need to return a value.

This answer is:
User Avatar

User Avatar

Wiki User

6y ago

If a method has void as its return type it means it does not return anything. There is no need for a return statement, but you can use an empty return statement to return from the method.

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

It means that a method returns no value.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why use void in main of java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is psvm in java?

public static void main


Why should the java main method has the return type as void?

A void method is one that returns no value. The Java main() method is the first method to be called, therefore it doesn't need to return a value to another Java method, therefore it is declared as void. If something needs to be returned to the operating system, this is done differently, not by "returning a value" in the sense of Java.


Why using the name main for main method in java?

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)


Can return statement be in a void method in java?

the main method in java is the client code therefore doesn't return any values Unlike languages like C/C++, the user doesn't specify an error return code by returning from the main method. Instead they should use System.exit(code) to do this. If the Java main method returns, the default code of zero is returned.


Can you have two mains in java?

Yes... We can have more than one main in JAVA... Just make the only one main method as public and other as default access specifier.... public class Test { public static void main(String args[]) { } } class Test1 { public static void main(String args[]) { } } class Test2 { public static void main(String args[]) { } } Just copy the above code and try.... Have fun in learning... :-) :) :-)

Related questions

What is psvm in java?

public static void main


Why should the java main method has the return type as void?

A void method is one that returns no value. The Java main() method is the first method to be called, therefore it doesn't need to return a value to another Java method, therefore it is declared as void. If something needs to be returned to the operating system, this is done differently, not by "returning a value" in the sense of Java.


Why void is restriction in java main function?

becoz the main program doesnot return any value to the os.


Why do you write void to the first of main?

Because main is the first method being executed, the Java Virtual Machine cannot expect any return values from this method. Since void is the term used to refer to a variable that does not return any value, we use the key word void for the method signature of the main method


What is the error in exception handling in java with example?

class Demo { public static void main(String s[]) { System.out.println("hello java frm Demo"); } } class Demo1 { public static void main(String s[]) { System.out.println("hello java frm Demo1"); String z={" "}; Demo.main(); } }


Void in java?

Void is a keyword in Java. It is always used in method declarations. When used in the line that declares a method, it signifies the fact that the method will not return any value. The JVM will not expect the method to return anything. Ex: public static void main(String[] args) {}


Why void main is used except int main in java?

void to indicate the application is not returning the exit code to the outer calling process. The outer calling process is another program (not necessary written in java), the human invoke the program on OS level, a batch job/script, etc. It works just like any method in java. main() itself is a method.


Why using the name main for main method in java?

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)


Can return statement be in a void method in java?

the main method in java is the client code therefore doesn't return any values Unlike languages like C/C++, the user doesn't specify an error return code by returning from the main method. Instead they should use System.exit(code) to do this. If the Java main method returns, the default code of zero is returned.


When 'public static void main' used in java?

That is the signature for the main program. The main program is the starting point, where execution starts - from there, other programs may be invoked.


Can you have two mains in java?

Yes... We can have more than one main in JAVA... Just make the only one main method as public and other as default access specifier.... public class Test { public static void main(String args[]) { } } class Test1 { public static void main(String args[]) { } } class Test2 { public static void main(String args[]) { } } Just copy the above code and try.... Have fun in learning... :-) :) :-)


How do you create a log In page using java swing?

import javax.swing.JOptionPane; public static void main (String[]args){