[5291] in java-interest
Re: Is 'new' really necessary?
daemon@ATHENA.MIT.EDU (Doug Dotson)
Mon Feb 5 11:16:27 1996
Date: Mon, 5 Feb 1996 09:51:06 -0500 (EST)
From: Doug Dotson <dotson@bud.tate.com>
To: java-interest@java.sun.com
> Can someone tell me why the 'new' keyword was used in Java?
> It appears to me that its only use is as a token to
> denote that a class instanciation is coming up next.
The instanciation may not be coming up next. If I anticipate a max of 100
objects in an array, I should not have to actually instantiate 100 if I only
use 20.
> It seems redundant in that regard.
>
> Given:
> (a) Date d = new Date(CurrentTime); // Java compiler likes
Right, this creates an object handle and associates an object with it.
> (b) Date d(CurrentTime); // Java compiler doesn't like
Wrong, handles don't have constructors since they are not objects.
> (c) Date d; // Java compiler likes
Right, this creates a handle but no object yet.
> Statement (a) uses the 'new' keyword. The disadvantage
> is that it messes up C++ programmers to thinking that a dynamic
^^^^^^^^^^^^^
You better start being a JAVA programmer! JAVA is not C++ and is not even
considered to be the next generation of C++, unlike the relationship
between C and C++. It borrows the good features from C++ and leaves the
features that are dangerous or redundant.
> variable is being created (yes, Java doesn't have pointers but some
> habits are hard to break). In addition, one has to type the class
> symbol again, and the equal character.
You are creating a dynamic. This is what makes garbage collection work well
in JAVA. Since all major objects are dynamically created, the programmer does
not have to worry about freeing them. They are freed automatically when the
object handle goes out of scope. This also eliminates (reduces) memory
leaks thus making apps more robust.
> Statement (b) is far more terse and natural for C++ programmers.
Terseness is one of C++'s weak points. My impression is that JAVA is patterned
after C++ only because C++ is well accepted in the industry thus reducing
the learning curve and increasing acceptance by the community.
> Statement (c) needs to be put in contrast to the following:
> Date d = new Date();
The type is necessary because the object handle might be that of an
inhereted class.
> I hope you see my point. An instanciation is an instanciation.
> Why must I think about a "new" object?
Because an instantiation IS the creation of a new object and should be
represented as such.
It is best to let JAVA stand on it's own rather than relying on
things like "C++ does it this way..." type thoughts. If every language
looked like it's predecessor we would all still be programming in FORTRAN.
I think C++ is a good language, I have been programming in it almost since
it came out. I think JAVA is a better language in the framework for which
it is intended. I could really care less about WWW applets, I see it as
the next step in quality portable code. As long as the interpreters provide
good performance, JAVA is a reasonable choice for a wide variety of
applications.
Doug Dotson
Tate Integrated Systems, L.P.
dotson@tate.com
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com