Categories: Uncategorized

What is the difference between AWT and Swing in Java?

The main difference between AWT and Swing in Java is that the AWT is the original Java platform widget, graphics and user interface toolkit whereas Swing is a GUI widget toolkit for Java which is a AWT extension.

Java is a high-level, general-purpose programming language that supports object-oriented programming, multithreading, platform independence, and many other features. The programmer can write a variety of applications including desktop, web, mobile, image processing, etc. using the Java language. Provides toolkits for creating graphical user interfaces (GUIs). AWT and Swing are two of them.

Key Areas Covered

1. What is GUI?
     – Definition, Functionality
2. What is AWT
     – Definition, Functionality
3. What is swing
     – Definition, Functionality
4. What is the difference between AWT and Swing in Java?
     – Comparison of key differences

Key terms

AWT, GUI, Java, Swing

What is a GUI?

GUI stands for Graphical User Interface . It is an interface that allows users to operate an application and perform required tasks. Also, a GUI consists of several components. Window, buttons, radio buttons, checkboxes, labels, dropdown lists, text fields, combo boxes are some components of the GUI. These components can trigger events. For example, a new page opens after clicking a button, or the user can enter registration details and press the submit button. Most applications have a GUI to allow the user to communicate with the application.

What is AWT?

AWT stands for Abstract Window Toolkit . It is an API for developing GUI or Windows-based applications in Java. It requires a native OS object to implement the functionalities. Also, AWT components are heavy and require more memory space. Also, they take a while to run. Additionally, the programmer must import the javax.awt package to develop an AWT-based GUI. Buttons, scroll bars, text fields, lists, dialog boxes, and panels are some components of AWT. After objects are created, they are placed in a container. In addition, it provides the space required for components to be loaded. Typically, the AWT application on one operating system may look different on another operating system.

what is swing

Swing is a GUI widget toolkit for Java. It is built on top of the AWT API. Also, it is part of Oracle’s Java Foundation Classes (JFC). In addition, Swing provides basic components like labels, text boxes, buttons, etc., as well as advanced components like tabbed panels, tables, and trees. Therefore, Swing provides more sophisticated components than AWT. Here, the programmer must import the javax.swing package to write a Swing application. This package provides a number of classes such as JButton, JTable, JList, JTextArea and JCheckBox.

                                                Figure 1: Simple Java Swing Application

Swing is platform independent and its components are lightweight. Also, the components require minimal memory space. Therefore, Swing applications run much faster. A common design pattern in development is the Model, View, Controller (MVC) pattern. Swing follows this pattern. It helps to maintain the code easily.  

Difference Between AWT and Swing

Definition

AWT is a collection of GUI components (widgets) and other related services required for GUI programming in Java. Swing is a part of the Java Foundation Classes (JFC) that is used to build Java-based front-end graphical user interface applications. Thus, this explains the main difference between AWT and Swing in Java.

Guy

AWT components are heavy, while Swing components are light.

platform dependency

Another important difference between AWT and Swing in Java is that AWT is platform dependent while Swing is platform independent.

Monitor

Also, AWT does not support a pluggable look and feel. The swing supports a connectable look and feel. This is also an important difference between AWT and Swing in Java.

Components

Also, Swing has more advanced components than AWT.

Speed

Also, AWT execution is slower. However, Swing runs faster.

MVC

AWT does not support the MVC pattern, while Swing supports the MVC pattern. This is another difference between AWT and Swing.

memory space

Also, AWT components require more memory space while Swing components do not require much memory space.

Package

The programmer must import the javax.awt package to develop an AWT-based GUI. However, the programmer has to import the javax.swing package to write a Swing application.

conclusion

In short, AWT and Swing are two toolkits for creating rich graphical user interfaces (GUIs). The main difference between AWT and Swing in Java is that AWT is Java’s original platform-dependent UI, graphics, and toolkit, while Swing is a GUI widget toolkit for Java that is an extension to Java. from AWT.. 

Reference:

1. “AWT Overview.” Www.tutorialspoint.com, available here.
2. “Overview of SWING.” Www.tutorialspoint.com, available here.
3. “Swing (Java).” Wikipedia, Wikimedia Foundation, June 9, 2018, Available here.
4. “Abstract Window Toolkit.” Wikipedia, Wikimedia Foundation, August 26, 2018, Available here.

Courtesy image:

1.”Java Swings Wikibook, Event Handling, example screenshot 1” By Samwilson – Own work (CC BY-SA 3.0) via Commons Wikimedia

Mohammad Asif Goraya

M A Goraya has qualification of M.phil in Agricultural Sciences. He has almost 15 years of teaching Experience at college and university level. He likes to share his research based knowledge with his students and audience.

Recent Posts

Difference Between Summary and Conclusion with Proper Definition and Brief Explanation

Main Difference - Summary vs Conclusion Summary and conclusion are two terms that are often…

1 year ago

Difference between Moth and Butterfly

Difference between moth and butterfly fall into two categories: anatomical and behavioral. Most moths are…

1 year ago

Difference Between Architect and Engineer

An engineer is a person whose job is to design and build engines, machines, roads,…

3 years ago

Difference between the Internet and the World Wide Web

Internet is the term used to identify the massive interconnection of computer networks around the…

3 years ago

Difference Between CD-R and CD-RW

A CD-R is a type of disc that does not contain any data. It is blank…

3 years ago

Difference between x86 and x64

Computing technologies are constantly evolving, and if we base our predictions on Moore's Law, they…

3 years ago