473,769 Members | 3,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class destructors

mlw
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.
Apr 19 '07 #1
6 7530
mlw <ml*@nospamnowa y.zzwrote:
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
Apr 20 '07 #2
mlw
~kurt wrote:
mlw <ml*@nospamnowa y.zzwrote:
>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.

Apr 20 '07 #3
In article <du************ *************** ***@comcast.com >, mlw <ml*@nospamnowa y.zzwrote:
>~kurt wrote:
>mlw <ml*@nospamnowa y.zzwrote:
>>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

Apr 21 '07 #4

"mlw" <ml*@nospamnowa y.zzwrote in message
news:du******** *************** *******@comcast .com...
~kurt wrote:
>mlw <ml*@nospamnowa y.zzwrote:
>>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
May 1 '07 #5
Silvio Bierman wrote:
>
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
May 10 '07 #6

"Faton Berisha" <fb******@uni-pr.eduwrote in message
news:jO******** *************** *******@giganew s.com...
Silvio Bierman wrote:
>>
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


May 10 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1333
by: alexhong2001 | last post by:
When design a class, should always make it "derivable" as a base class? Is there really a situation that the designed class not "derivable"? When should make a member "protected"? Only when allowing the derived class(es) directly access it? Should destructor always be virtual? Thanks for your comments!
2
4553
by: Chunhui Han | last post by:
Hi, I was recently reading about virtual base classes in C++. The book I was reading says that it is illegal to have non-virtual destructor for the virtual base class. It seems to me that virtual destructors are essential when the class has virtual functions, since this class is supposed to be used as a base class for polymorphism. But what is the real reason for a virtual destructor in a virtual base class? Thanks,
23
5184
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
13
4563
by: jois.de.vivre | last post by:
Hi All, I'm trying to write a wrapper class for std::vector to extend some of its functionality. The problem I'm getting into is returning an iterator type from a member function. Here is the essense of what I'm trying to do: //-------code------- #include <vector>
3
2965
by: dischdennis | last post by:
Hello List, I would like to make a singleton class in python 2.4.3, I found this pattern in the web: class Singleton: __single = None def __init__( self ): if Singleton.__single: raise Singleton.__single
5
1607
by: The Cool Giraffe | last post by:
I'm designing an ABC and in connection to that i have run into some "huh!" and "oh...". Let me put it as a list. 1. Since the class will only contain bodies of the methods, only the header file is needed. There will be no definitions provided until i derive the ABC. True or false? 2. Since i'll have two different classes (both derived from the original ABC) i'll use the following syntax in my main class using the derivation.
9
2048
by: desktop | last post by:
On this page: http://www.eptacom.net/pubblicazioni/pub_eng/mdisp.html Shape specify the virtual function: virtual double Intersect( const Shape& s) = 0; then the derived class Circle also specify:
12
1627
by: Shraddha | last post by:
Can I stop people by deriving my class? I mean I don't want my class to be as a base class... Can I do that?
1
5343
by: Stodge | last post by:
Yet another SWIG question (YASQ!). I'm having a problem with using an abstract base class. When generating the Python bindings, SWIG thinks that all the concrete classes that derive from this abstract class are abstract too and won't create the correct constructor. Abstract class: class CORE_API Shape
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.