tags:

views:

367

answers:

3

Why is it said that Swings is heavy-weight and AWT is light-weight in JAVA?

A: 

I don't totally understand the question and I'm sure this is going to result in a flamewar but perhaps it is because AWT provides a "simpler" API, though it is a bit more primitive. Swing however, is arguably a very top-heavy, or heavy weight, if you like API. It has far richer support and many more classes than AWT.

BobbyShaftoe
true as well, Swing is much more complicated because of its view/model structure.
Denis Troller
+9  A: 

AWT is said to be "Heavyweight" because basically each AWT component is a native platform component. AWT is implemented on top of the platform's native GUI toolkit. This also explains why AWT was pretty limited compared to Swing. It uses the least common denominator as far as what is implemented.

Swing, on the other hand, is implemented in Java for pretty much everything except for top level components (windows...). There can be native components and those are still termed "heavy weight".

Take a look at this page from IBM for an in-depth comparison of AWT, Swing and SWT.

EDIT: I assume that was your question, even though heavy/light seem to be reversed in your phrasing. Heavy/light weight is pretty much a standard denomination in the Java GUI toolkits so I went with my understanding. (thanks to BobbyShaftoe for pointing that out).

Denis Troller
I see, perhaps the questioner is confused as the question states that Swing is considered Heavyweight not AWT.
BobbyShaftoe
Woops true. Well he either made a mistake or was talking about something else, but since the terms "heavyweight" end "lightweight" are pretty much standard on this topic, I'd go with the mistake. If the answer is not what he was looking for, he'll let us know.
Denis Troller
Yeah, I agree. it's interesting nonetheless.
BobbyShaftoe
+1  A: 

In the Java world, AWT components are considered "heavy-weight" because they use underlying native components. When you instantiate an instance of java.awt.Button, you are actually asking the underlying OS to paint this object for you.

Swing, on the other hand, is "light-weight" because it mostly depends on the Java2D API to do all painting, which in turn delegates to the underlying OS or hardware. This also explains why Swing needs all those UI components that do the actual painting to mimic a specific look and feel (Windows, GTK, Motif, etc.).

This article explains more in detail the difference between light-weight and heavy-weight components.

Hope this helps.

Jose Chavez