[6561] in java-interest
Re: Why isn't a Java application instantiated
daemon@ATHENA.MIT.EDU (Thomas Walker)
Thu Apr 4 09:29:06 1996
Date: Thu, 4 Apr 1996 09:26:39 -0500
Reply-To: Java Interest <JAVA-INTEREST@JAVASOFT.COM>
From: Thomas Walker <walker@BLUESTONE.COM>
To: Multiple recipients of list JAVA-INTEREST
<JAVA-INTEREST@JAVASOFT.COM>
In-Reply-To: <199604031951.OAA19162@europa.coat.com>
On Wed, 3 Apr 1996, Matt Fahrner wrote:
> 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.
>
Well, I haven't read anything from Sun about why this is so, but I'll
give it a shot. If you were to access methods or variable of an instance
of object in which the main is located, what instance would be accessed?
When you start the program, you have not created (or initialized) instances
of any objects. If the constructor for this "main object class" (for
lack of a better term), required any parameters, how would this be
accomplished? Would it have to accept String arg[] as the its sole
parameter?
I also agree with your criticisms of doing this. Is this any better than
C++ in this respect? I don't see how.
> 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
> -------------------------------------------------------------------------
>
===============================================================
Thomas G. Walker Phone: (609) 727-4600
Bluestone
1000 Briggs Road Email: walker@bluestone.com
Mt. Laurel, NJ 08054 Web: http://www.bluestone.com/
===============================================================