Key Difference – AWT vs Swing
Java is a high-level programming language developed by Sun Microsystems. Java supports Object Oriented Programming that helps to design and develop a software using objects. When Java program is compiled, it is converted into a bytecode. That bytecode is interpreted by the Java Virtual Machine (JVM) on any platform.Therefore, it is a programming language that programmers can write once and run on any platform. Java can be used to develop a variety of applications such as desktop, mobile and web applications. The language provides toolkits for creating rich Graphical User Interfaces (GUI). Two of them are AWT and Swing. This article discusses the difference between AWT and Swing. The key difference between AWT and Swing is that AWT is Java’s original platform dependent windowing, graphics, and user interface widget toolkit while Swing is a GUI widget toolkit for Java that is an extension for AWT.
What is AWT?
A Graphical User Interface is an interface for users to provide instructions for the software to perform tasks. It consists of various graphical components. Some GUI components are window, button, combo box, text area, list box, and label. Using these components, the programmer can develop an interactive user interface for the application. A GUI is based on events. Button click, closing the window, typing something in the textbox are some examples of events that can occur in a Graphical User Interface based application. Today many applications contain GUIs. Mobile applications, Air ticket reservation systems, Automated Teller Machines have rich graphical interfaces for customers to use the application easily.
AWT stands for Abstract Window Toolkit. AWT requires a native OS object to implement the functionalities. Therefore, AWT components are heavyweight and require more memory space. AWT components also take time to execute. The number of components available in AWT is minimum. It is necessary to import javax.awt package to develop an AWT based GUI applications.
Some AWT components are button, text fields, drop down boxes, scroll bars, window, frame, panel, labels. After creating the objects, they can be placed into a container. A container provides space for components to load. AWT does not support pluggable look and feel. Therefore, an AWT application developed in one operating system might not look the same in another operating system.
What is Swing?
Swing is a GUI widget toolkit for Java. It is a part of Oracle’s Java Foundation Classes (JFC). It is an Application Programming Interface to build GUI for Java applications. It is built on top of AWT API. Swing was developed to provide more flexible and sophisticated components than AWT. Swing contains basic components such as labels, text boxes, buttons. It also contains more advanced components. Some of them are trees, tables, lists, scroll panes and tabbed panes. If the programmer needs to implement a Swing application, it is necessary to import javax.swing package. The package provides classes for Java Swing API such as JButton, JRadioButton, JTextField, JCheckbox etc.
Swing components do not have a platform-specific code. Therefore, Swing is platform independent. Unlike AWT, Swing does not require native OS calls to build components. JVM is responsible for invoking the native methods. The Swing components are lightweight. The required memory space is also minimum. This is a considerable factor to run Swing based applications faster. In application development, Model, View, Controller (MVC) is a common design pattern. The model represents data. The view represents the presentation while Controller is the interface between Model and View. Swing follows this pattern. Swing supports the pluggable look and feel. Overall, it is more powerful than AWT.
What is the Similarity Between AWT and Swing?
- Both are Java-based toolkits to build Graphical User Interface.
What is the Difference Between AWT and Swing?
AWT vs Swing
|AWT is Java’s original platform dependent windowing, graphics and user interface widget toolkit preceding Swing.||Swing is a GUI widget toolkit for Java which is a part of Oracle’s Java Foundation Class (JFC).|
|AWT components are platform dependent.||Swing components are platform independent.|
|Number of Components|
|AWT contains less number of components.||Swing has a higher number of components.|
|AWT components are heavyweight.||Swing components are lightweight.|
|AWT does not follow MVC.||Swing follows MVC.|
|AWT is not fast as Swing.||Swing is faster than AWT.|
|Required Memory Space|
|AWT components require more memory space.||Swing components require less memory space.|
|AWT requires importing javax.awt package.||Swing requires importing javax.swing package.|
|Pluggable Look and Feel|
|AWT does not support pluggable look and feel.||Swing provides a pluggable look and feel.|
Summary – AWT vs Swing
This article discussed two Graphical User Interface Designing tool that is AWT and Swing. The difference between AWT and Swing is that AWT is Java’s original platform dependent windowing, graphics and user interface widget toolkit while Swing is a GUI widget toolkit for Java, which is an extension for AWT. Swing provides richer functionalities comparing to AWT. The appearance of the GUI built using Swing looks nicer than GUI with AWT. Unlike AWT, Swing supports the pluggable look and feel and increase the usability of the application.
Download the PDF Version of AWT vs Swing
You can download the PDF version of this article and use it for offline purposes as per citation note. Please download the PDF version here: Difference Between AWT and Swing
1.tutorialspoint.com. “SWING Overview.” The Point. Available here
2.“Swing (Java).” Wikipedia, Wikimedia Foundation, 24 Jan. 2018. Available here
3.“Abstract Window Toolkit.” Wikipedia, Wikimedia Foundation, 22 Jan. 2018. Available here
4.“Java Swing Tutorial – javatpoint.” Available here
5.tutorialspoint.com. “AWT Overview.” The Point. Available here
1.’AWTSwingClassHierarchy’ By Jakub Závěrka – Jakub Závěrka – own work, (Public Domain) via Commons Wikimedia