Difference between Swing and AWT in Java – AWT vs Swing

By | April 6, 2018

Swing Vs AWT

Major differences between Swing and AWT

AWT Swing
AWT stands for Abstract Window Toolkit AWT is the foundation of Swing and it implements GUI components which was built on AWT.
AWT GUI components are heavy weight. Swing components are light weight.
AWT consumes comparatively high System Resources than Swing. Swing consumes less System Resources.
AWT produces platform dependent components. i.e. the program is dependent on the current Operating System. Swing will produce platform independent components. i.e. you can use it on any Operating System that supports Java.
The list of components are comparatively smaller than Swing. Swing is an advanced version of AWT and hence the list of components are higher than AWT.
In AWT, even for enabling window closing option. We need to provide a lot of code. In Swing, a small piece of code is sufficient. e.g. Obj.setDefaultCloseOption(JFrame.EXIT-ON-CLOSE);
AWT does not follow MVC (Model View Controller) design pattern. Swing follows MVC design pattern.
It requires javax.awt package. It requires javax.swing package.


What do you mean by AWT is heavy weight and Swing is light weight?

First of all, by heavy weight, it means the code will take comparatively more time to load and it will consume more System resources. AWT is considered to be heavy weight because its components are dependent on the underlying Operating System. E.g. When you create an object of java.awt.Checkbox class, its the underlying Operating System that will generate a checkbox for you. This is also the reason, AWT programs are platform dependent.

On the other hand, most of the Swing components are implemented in Java itself. Some of the top level components like windows are dependent on Operating System. But still, the overall program is comparatively light weighted than AWT.


Is it important to learn AWT before Swing?

Swing is the advanced and optimized version of AWT and it is built on top of AWT. Still, many AWT classes are used in Swing either directly or indirectly. It is important to do basics of AWT before proceeding to Swing. Otherwise, you won’t understand the underlying facts about several control delegations while GUI in java.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.