[1785] in java-interest

home help back first fref pref prev next nref lref last post

Re: main() routine

daemon@ATHENA.MIT.EDU (Arthur van Hoff)
Sat Sep 16 23:44:01 1995

Date: Sat, 16 Sep 1995 11:47:43 -0800 (PDT)
From: Arthur van Hoff <Arthur.Vanhoff@Eng.Sun.COM>
Reply-To: Arthur van Hoff <Arthur.Vanhoff@Eng.Sun.COM>
To: Michael I Angerman <michael@santafe.edu>
Cc: java-interest@java.Eng.Sun.COM



Hi Michael,

> 	But the question still remains, where is main() called from. 

Main is called when you invoke a class directly. For example:

	java ArcTest

The java interpreter loads the ArcTest class and looks for a methods
called main with the following signature:

	public static void main(String argv[]) {
	    ...
	}

If it finds one it calls it and passes it an array of command line 
arguments. That is how you write the SayHello application for
example:

        class SayHello {
	    public static void main(String argv[]) {
	        System.out.println("Hello " + argv[0]);
	    }
        }

To invoke this you call:

	java SayHello Michael

Have fun,

	Arthur van Hoff
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post