answersLogoWhite

0

Why void main is used except int main in java?

Updated: 8/18/2019
User Avatar

Wiki User

13y ago

Best Answer

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.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why void main is used except int main in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is psvm in java?

public static void 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) {}


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.


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(); } }


What is the meaning of java void keyword?

The void keyword is used to show that a method will not return a value. // no return type public void setX(int x) { this.x = x; } // returns an int public int getX() { return x; }


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){


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


Is there any change by interchanging the position of main in Public static void main in java?

No. You can write it in as many ways as you want. The words public, static and void can be interchanged during the method declaration and still the main() method will continue to work in the same way. i.e., public static void main(String[] args) is the same as static public void main(String[] args) However, if you miss either of these 3 keywords from the method signature, the compiler will still let you compile the method, but it just won't be the main method that can be used to start the program execution.