return type of main in java

The short answer is: Because that’s what the language specification says.

In today’s commonly used operating systems (Windows and Unix families), the only “return value” from a process is an exit status, which is a small number (usually 8-bit). This value can be returned from a Java program using the System.exit(int) method:

public static void exit(int status)

Terminates the currently running Java Virtual Machine. The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.

Leave a Comment