Introduction
I know questions like telling the differences among Swing, awt, SWT and JFace or some of them are frequently asked in an interview for Java programmers. I don't use them very often and extensively, nor do I know too much about those four things, especially from the implementation perspective or the guru's best practice perspective. But I do read some materials and figure out some conceptual difference between those four things that I think would suffice answering such questions in an interview.
AWT and Swing
-AWT
AWT stands for abastract window toolkit which comes with an early release of the Java Programming Language ( about 1.1 ). AWT components are referred to as heavyweight components. It is implemented as having "peer" native code for every widget you create. Most of the significant logics (including the core event handling logic) of the toolkit are written in C/C++, for which via JNI (Java Native Interface) your GUI program may directly calls those "peer" native code. It means all of the drawings of your GUI are done directly by the graphic API of the underlying operating system. This implementation underlies several limitations:
- Not all the operating system support the same set of native widgets, so a "least common denominator" philosophy is used when shipping the AWT library, that is only a basic set of components are provided as library via which you write your GUI. So no complex components such as slider, tree and table can be found in AWT components, which you have to build yourself either through directly writing native code as AWT is implemented, or through writing Java codes which wraps AWT ( this is the way Swing is implemented).
- Because the core logic are hided from you in the native code, debugging your GUI program can be annoying.
This kind of implementation also results in your GUI implemented with AWT always having the same look and feel as the underlying OS.
-Swing
In contrast, Swing components are known as lightweight components, because Swing doesn't implement the underlying drawing and event handling logic which are delegated to the toolkit in this case AWT, on which it is built on. As mentioned above, Swing is implemented by pure Java codes. So it is conceivable that Swing has the portability that AWT doesn't have, and that Swing has almost all the nontrivial complex components. Swing can also have the same look and feel on all OS, and can also be switched to another style of look and feel at runtime regardless of the underlying OS. It is said that Swing has a better performance than AWT, however, from the implementation logic so far I've known, I can't tell why. Swing seems well known for its good design and architecture.
-Never intermix AWT and Swing
I know a lot has been said and written about this subject. The first item in the resources section is a good example of that.
SWT and JFace
-SWT
SWT, short for standard widget tookit, is originally introduced by IBM, as a substitute of AWT. SWT now is as part of the eclipse platform based on which the eclipse GUIs are implemented. SWT is very similar to AWT conceptually, however, the underlying implementation is a little different. Different from implementing all the core logic in "peer" logic in native code, SWT bears a thin JNI layer which is used for directly call the GUI API of each underlying platform. All the significant logics are written in pure Java codes in which the thin JNI layer is used. So almost all the limitations AWT has are elimintated in SWT. Other than this, better performance are gained, for which I don't know the specific reason. As of AWT, SWT has a consisten look and feel as the underlying OS.
Disadvantages of using SWT:
- Reuire a native library (This also holds true for AWT).
- Low level of abstraction (This also holds true for AWT).
-JFace
JFace is conceputally similar to Swing. The relationship between JFace and SWT is very similar to the relationship between Swing and AWT. It works above the level of raw widgets, in this case, SWT. JFace has a rich set of complex widgets.
Resources

1 comment:
Good article Kenyth..Thanks
Post a Comment