[6543] in java-interest

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

Why isn't a Java application instantiated

daemon@ATHENA.MIT.EDU (Matt Fahrner)
Wed Apr 3 17:02:50 1996

Date:         Wed, 3 Apr 1996 14:51:54 -0500
Reply-To: Java Interest <JAVA-INTEREST@JAVASOFT.COM>
From: Matt Fahrner <Matt.Fahrner@COAT.COM>
To: Multiple recipients of list JAVA-INTEREST
              <JAVA-INTEREST@JAVASOFT.COM>

Does anyone know why they chose to make the base object (this) passed to
a class running from a "main()" method, eg:

     java MyClass

unaccessable from the main in most cases. Take for instance:

     public class MyUIApp extends Frame {
        ...
        public static void main(String arg[]) {
            ...
        }
     }

because the "main()" must be static it cannot access any of the non-static
methods or variables of its parent class "Frame" of the current instance. The
only way it can do so is to create a new "Frame", usually done something like:

     public static void main(String arg[]) {
         MyUIApp window = new MyUIApp();
         ...
         window.show();
     }

and call it's methods. However the current object in this case is also a
"Frame", so why shouldn't you be able to do this?:

     public static void main(String arg[]) {
         ...
         show();
     }

is the current object a "class" object only? Why chose to make "main()"
unable to access it (unless you add static items of course)? Why are you
forced to create this additional object? Why isn't the constructor for
"MyUIApp" called before "main()", or for that matter called at all? It
seems like this "main()" thing is a kludge and because it can't access the
current object, its no better than a procedural oriented "main()". It
seems to make the point of having "main()" in an object useless. It also
breaks symmetry between objects called through main, and objects called
from an applet.

Am I missing something? Is it so main() can set something like an "IsInApplet"
variable. It would be better to have some sort of call like:

    boolean System.runninInAnApplet();

Just asking...

                                - Matt

-------------------------------------------------------------------------
Matt Fahrner                                    PO Box 309
Network Technical Director                      Schoolhouse Lane
Burlington Coat Factory Warehouse               Etna, N.H.  03750
TEL: (603) 643-2800 xt 5150                     USA
FAX: (603) 643-3945                             Matt.Fahrner@COAT.COM
-------------------------------------------------------------------------

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