Re: What's java equivalent of C's argv[ 0 ]?
"Eric Sosman" <Eric.Sosman@sun.com> wrote in message
news:1146060429.694072@news1nwk...
(No, the existence of multiple main() methods is not
a mere perversity. For example, consider the usual way
of writing Swing code that will run either as an applet
or as an application: There's a main() that gets used when
running as an application, but that is not used when the
code runs as an applet. If the code is running as an applet,
does it make sense to designate a method that's never even
called as "the" main() method?)
I thought the standard pattern for this sort of stuff is to have your
main method create a JWindow, add the JApplet to the JWindow, and call the
init() and start() method. So either the init() or the start() method could
be considered "the" "main" method.
I wrote an RPG engine with a level editor. The engine and the editor
shared a lot of code, so it was made one big project with two "public static
void main(String[] args)" methods. One in a class called Game, and one in a
class called Editor. Depending on which one you called, you could either
design a new game, or play the game you just designed.
At work, we're writing and Eclipse plugin to do various source-code
analysis type stuff. We've got lots of "public static void main(String[]
args)" methods so that each functionality can be tested at the command line
(or within unit tests). For example, there's an entry point where you can
pass in a input filename and an output filename, and it'll parse the input
file and dump the abstract syntax tree generated as an XML document to the
output filename. This is to test that the input files are correctly being
parsed, although that isn't the "main" goal of the plugin.
- Oliver