Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

Class destructors

Thread view: 
mlw - 19 Apr 2007 23:58 GMT
Could someone explain why there is no destructor in Java classes?

There are many times you need to be called WHEN an object goes out of scope
and not when it will eventally be freed.
~kurt - 20 Apr 2007 02:28 GMT
> Could someone explain why there is no destructor in Java classes?

The explanation I remember is destructors are generally used to free
memory, and Java has garbage collection.  Doesn't make it right, but that
is the way it is.

- Kurt
mlw - 20 Apr 2007 03:15 GMT
>> Could someone explain why there is no destructor in Java classes?
>
> The explanation I remember is destructors are generally used to free
> memory, and Java has garbage collection.  Doesn't make it right, but that
> is the way it is.

That's one of the things that bothers me about Java. So many newbe CompSci
people think it is wonderful, but it has so many glaring omissions and all
too often it falls short of a real and useful programing language. Like
Windows, skill in Java comes from knowing the trivia of Java, and not from
the theory and science of your algorithms.
~kurt - 21 Apr 2007 03:08 GMT
> That's one of the things that bothers me about Java. So many newbe CompSci
> people think it is wonderful, but it has so many glaring omissions and all
> too often it falls short of a real and useful programing language. Like
> Windows, skill in Java comes from knowing the trivia of Java, and not from
> the theory and science of your algorithms.

Most of my experience is with structured programming - OOD is relatively new
to me.  I have to admit, I didn't start "getting it" until I started working
with Java.  Most of the things you "can't" do, you can't do for a reason.
While I like C for structured programming, I just never liked C++ - seems
kind of like a kludge to me.  Most of the C++ code I have been forced to work
with is just crap (fault of the programmer, not the language).  Overall, I
have to admit I enjoy programming in Java.  It seems to encourage better OOP.
You do need to have an idea as to what is going on under the hood to avoid
making bloated and inefficient code.

I've been coding up some engineering related algorithms to gain the
experience (not work related).  I guess through using it I'll see if it is
really of any real value for scientific work.  I did see a demo for a Java3D
based application similar to Google Earth (but with an astrodynamic slant).
It was very slick - excellent graphics and performance.  I've also been
messing around with Java3D myself - so far I'm impressed.

- Kurt
EricF - 21 Apr 2007 05:28 GMT
>>> Could someone explain why there is no destructor in Java classes?
>>
[quoted text clipped - 7 lines]
>Windows, skill in Java comes from knowing the trivia of Java, and not from
>the theory and science of your algorithms.

There are a large number of places running real and useful enterprise
applications that were written in Java.

Being skilled in algorithms makes you a good developer. Java does nothing to
take away from that. Being skilled in Java "trivia" - aka the language and
"libraries" - makes you a better developer, but that's true of any language.

Java has its warts. Also true of all other languages I've seen.

Eric
Silvio Bierman - 01 May 2007 13:08 GMT
>>> Could someone explain why there is no destructor in Java classes?
>>
[quoted text clipped - 7 lines]
> Windows, skill in Java comes from knowing the trivia of Java, and not from
> the theory and science of your algorithms.

Total nonsense. Destructors have nothing whatever to do with general theory
and science of algorithms.

In the C++ object model where objects (class instances) and the lexical
reference to them have a one-to-one relationship destructors make sense. The
fact that C++ does not offer GC makes them even essential. And yes, many
other usefull constructs can be expressed using destructors.

In Java (and most other contemporary programming/scripting languages) the
object instance and the syntactical construct referencing it are loosely
coupled. Objects can have zero or more references pointing to them, not
unlike C++ pointers (or C++ references, for that matter). Such an object
model does not allow the definition of a destructor like construct because
the lexical scope of an object reference and the lifetime of the actual
object instance are at best indirectly related.

If you value a theoretical approach to programming than you should be able
to distinguish abstract algorithms from language constructs that allow you
to implement them. If you find yourself unable to implement your abstract
algorithm in a language without destructors (which would not leave you many
options anyway) then you obviously are unable to make that distinction.

Silvio Bierman
~kurt - 02 May 2007 04:27 GMT
> In the C++ object model where objects (class instances) and the lexical
> reference to them have a one-to-one relationship destructors make sense. The
[quoted text clipped - 8 lines]
> the lexical scope of an object reference and the lifetime of the actual
> object instance are at best indirectly related.

Thanks for the writeup.

- Kurt
Faton Berisha - 10 May 2007 04:42 GMT
> Total nonsense. Destructors have nothing whatever to do with general theory
> and science of algorithms.

Well, for that matter, neither do constructors.

The reason for not implementing destructors in Java is,
I think, that many found it difficult to properly use them
(if not completely omit them), and this is compatible with not
implementing pointers.

Personally, the thing I miss the most from C++ is operator overloading.
(Readability is to blame here, I guess.)

Obviously, the designers had in mind things other than
developing a scientific computation or a system programming language
when designing Java.

Faton Berisha
Silvio Bierman - 10 May 2007 12:19 GMT
>> Total nonsense. Destructors have nothing whatever to do with general
>> theory and science of algorithms.
>
> Well, for that matter, neither do constructors.

Off course. Only a language as a whole represents a view on implementing
algorithms.

> The reason for not implementing destructors in Java is,
> I think, that many found it difficult to properly use them
> (if not completely omit them), and this is compatible with not
> implementing pointers.

I already stated why a destructor is in contradiction with the Java language
logic. Java object references are quite close to pointers in C(++). Only the
concept-mix of arrays and pointers that C++ inherited from C (as much as
Stroustrup said to regret that) is totally missing which means no pointer
arithmetic.

Being an old time C (and since its early conception, C++) programmer I kind
of liked pointer arithmetic and I must admit I sometimes miss it when doing
some array fiddling in Java.

> Personally, the thing I miss the most from C++ is operator overloading.
> (Readability is to blame here, I guess.)

I welcomed it when it was added to C++ and used it enthousiasticly. In
retrospect I find it is only suitable when implementing very generic classes
(like strings, collection classes etc). I always found application level
logic to be expressed best with descriptively named operations
(functions/methods).

> Obviously, the designers had in mind things other than
> developing a scientific computation or a system programming language
> when designing Java.

My guess is they started with C++ but wanted something managed (Virtual
Machine based) and simpler (quirk-free as opposed to C++ which is full of
quirks that only language theorists like to play with). They made some good
design decisions, some bad. The resultng Java environment just works,
despite some things I would like to have seen different about the language.
The cross-platformness and the enormous amount of freely availably libraries
for almost anything a developer could need in combination with an OK
language has effectively won me over.

I find it pointless to discuss isolated language details or doing
apples/oranges comparisons between programming languages. In the end the
quality and timely availability of the resulting software systems is all
that counts, whichever languages where used to implement them.

Silvio Bierman

> Faton Berisha


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.