GeeCON Prague 2014*
The moose likes Java in General and the fly likes why main returns nothing always in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "why main returns nothing always in java" Watch "why main returns nothing always in java" New topic
Author

why main returns nothing always in java

rajeev maurya
Greenhorn

Joined: Nov 26, 2010
Posts: 1
why main returns nothing always in java
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Compared to C?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14190
    
  20

Because that's how the people who invented Java made it...

If you need to return a return value to the operating system (so that you can use it in for example a batch file or shell script), use System.exit(n); to end your Java program (where n is the return code).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

In C and C++, the return value of the main method can be used by the calling shell (e.g. bash). In Java, you use System.exit to give this value back to the calling shell.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: why main returns nothing always in java