• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why main returns nothing always in java

 
rajeev maurya
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why main returns nothing always in java
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compared to C?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15219
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic