• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Returning value from standalone program  RSS feed

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I need to write a standalone java program which will return a value (0 or 1) so that I can use this value in a DOS batch file. When I tried to do this I got an error message saying that main must be declared with void.
Can anyone tell me how I can return a value from a java program?
Thanks
Suresh
 
High Plains Drifter
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use System.exit(). exit() will take an integer value that is returned to the OS upon program completion. Example:

main() is a bootstrap method, of sorts -- I'd look up a more precise meaning but Marilyn or Cindy will come along and do that anyway -- and has no "calling method" in the usual sense. Therefore the only appropriate return value must be handled through the system, and not through a direct return by the method itself.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess he didn't like your answer because he asked the same question again. I gave him the same answer so he probably won't like that either.
 
Suresh Kanagalingam
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply.
Works great.
Suresh
 
Michael Ernest
High Plains Drifter
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure one has to answer with a certain, oh I don't know..."wherewithal" for it to sink in.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!