File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes void ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "void ?" Watch "void ?" New topic
Author

void ?

Lou Maybe
Greenhorn

Joined: Nov 26, 2002
Posts: 2
I have a basic understanding of c++ and that about as far as my programming
knowledge extends. I was lead to belive void main was a bad thing yet in every sample program i've seen in java this seems standard practice, why?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9001
main() a bad thing?

You need to have a method named
public static void main( String[] args )
to start off any java application. You may not need main() in every class in your project, but you certainly need one or your app won't run.

If you only program applets or servlets you could, however, get by without a main() method.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
The main method in Java *has* to have a return value of "void" per specification.
In C/C++, it is a good practice to let main have a return value of int to specify the exit code of the program.
In Java, a program has an exit value of 0 by default - if you want to specify a different value, you need to use System.exit(exitCode).


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
jQuery in Action, 2nd edition
 
subject: void ?
 
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture