What is the difference between AWT and Swing in java

What is the difference between AWT and Swing in java?

This is one of the favorite java swing interview question asked for UI developer. Before looking at difference between AWT and Swing lets see what is AWT and what is Swing

AWT (Abstract Window Toolkit)

AWT is original Java GUI toolkit and simple where there are limited GUI components, layout managers, and events. Some commonly used components such as Tables, Trees, Progress Bars, and others, are not supported in AWT.


Java Swing is a very well-engineered, flexible, powerful GUI tool kit. Swing is built on parts of AWT. Java Swing uses the AWT event model and support classes, like Colors, Images, and Graphics.

Now let see difference between AWT and Swing

Difference between AWT and Swing

1. The base difference which everybody knows is Swing is Lightweight and AWT is heavy weight. But often you will be asked what is Heavyweight mean - answer is simple AWT components use the native code for getting the view component which is dependent on Operating System, that's why the look and feel changes from OS to OS.

To overcome the variation in behavior across different hosts, Swing minimized its dependence on host controls. So it is called as lightweight.
Swing uses the term heavyweight for peer-based components and lightweight for emulated components. In fact, Swing supports mixed heavy and light components in a single GUI, such as mixing AWT and Swing controls in the same JContainer.

2.AWT components are thread-safe but Swing components are not thread-safe so you need to be careful which thread is updating the GUI if you are using multithreading.

3. Another difference is in Swing there is a separation between view and controller. Swing uses UI delegate which makes it more robust.

4. In case of Swing you can have facility to create Programmable look and feel using Java Swing API.

5. Another key difference is the use of renderer and editors which makes it very useful in controlling the showing the data and editing data.
Share on Google Plus

About Pranav

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment


Post a Comment