Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old April 20th, 2007, 12:05 AM
mlw
Guest
 
Posts: n/a
Default Class destructors

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.
  #2  
Old April 20th, 2007, 02:35 AM
~kurt
Guest
 
Posts: n/a
Default Re: Class destructors

mlw <mlw@nospamnoway.zzwrote:
Quote:
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
  #3  
Old April 20th, 2007, 03:15 AM
mlw
Guest
 
Posts: n/a
Default Re: Class destructors

~kurt wrote:
Quote:
mlw <mlw@nospamnoway.zzwrote:
Quote:
>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.

  #4  
Old April 21st, 2007, 05:35 AM
EricF
Guest
 
Posts: n/a
Default Re: Class destructors

In article <duGdnaEi0J4EvLXbnZ2dnUVZ_q_inZ2d@comcast.com>, mlw <mlw@nospamnoway.zzwrote:
Quote:
>~kurt wrote:
>
Quote:
>mlw <mlw@nospamnoway.zzwrote:
Quote:
>>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.
>
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

  #5  
Old May 1st, 2007, 01:15 PM
Silvio Bierman
Guest
 
Posts: n/a
Default Re: Class destructors


"mlw" <mlw@nospamnoway.zzwrote in message
news:duGdnaEi0J4EvLXbnZ2dnUVZ_q_inZ2d@comcast.com. ..
Quote:
~kurt wrote:
>
Quote:
>mlw <mlw@nospamnoway.zzwrote:
Quote:
>>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.
>
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


  #6  
Old May 10th, 2007, 04:45 AM
Faton Berisha
Guest
 
Posts: n/a
Default Re: Class destructors

Silvio Bierman wrote:
Quote:
>
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
  #7  
Old May 10th, 2007, 12:25 PM
Silvio Bierman
Guest
 
Posts: n/a
Default Re: Class destructors


"Faton Berisha" <fberisha@uni-pr.eduwrote in message
news:jOudnWNAmvxCCd_bnZ2dnUVZ8qLinZ2d@giganews.com ...
Quote:
Silvio Bierman wrote:
Quote:
>>
>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.
Quote:
>
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.
Quote:
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).
Quote:
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
Quote:
>
Faton Berisha


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles