Difference Between Abstract Window Toolkit (AWT) And Swing In Java

AWT (Abstract Window Toolkit)

Abstract Window Toolkit (AWT) is a set of application program interfaces (APIs) used by Java programmers to create graphical user interface (GUI) objects such as buttons, scroll bars and windows. Java AWT components are platform-dependent i.e components are displayed according to the view of the operating system.

AWT is part of the Java Foundation Classes (JFC) from Sun Microsystems, the company that founded Java. The JFC are a comprehensive set of GUI class libraries that make it easier to develop the user interface part of an application program.

Java Abstract Window Tool Kit package is used for displaying the data within a GUI environment. Features of AWT package include:

  • A set of native user interface components
  • A robust event-handling model
  • Graphic and image tools including shape, color and front classes
  • Layout managers, for flexible window layouts that do not depend on a particular window size or screen resolution.
  • Data transfer classes for cut-and-paste through the native platform clipboard.

The Java.awt package provides clases for AWT API such as TextField, Label, TextArea, RadioButton, CheckBox, Choice, List etc.

AWT is rarely used now days because of its platform dependent and heavy-weight in nature. AWT components are considered heavy weight because they are being generated by underlying operating system (OS). For example, if you are instantiating a text box in AWT that means you are actually asking OS to create a text box for you.

What You Need To Know About AWT

  • AWT components are dependent on the nature of the platform. Its code resides in OS of the system hence makes it impossible for platform independence.
  • Programmer has to import the javax.awt package to develop an AWT-based GUI.
  • AWT components serve as a thin layer of coding that lies at the top of OS.
  • Many features/functions of AWT components have to be implemented by the coder.
  • AWT components require and occupy larger memory space.
  • AWT does not follow MVC (Model View Controller).
  • AWT components are heavyweight because every graphical unit will invoke the native methods.
  • AWT is less powerful than swing.
  • The look and feel of AWT depends upon platform.
  • AWT provides less components than swing.
  • Execution of AWT is slower.
  • AWT does not support pluggable look and feel.

Swing

Swing is a GUI widget toolkit for Java. It is part of Oracle’s Java Foundation Classes (JFC) that is used to create window-based application. Swing was developed to provide a more advanced set of GUI components than the Abstract Window Toolkit (AWT.

Swing provides a look and feel that emulates the look and feel of several platforms and also supports a pluggable look and feel that allows applications to have a look and feel unrelated to the underlying platform.

The Javax.swing package provides classes for Java swing API such as JButton, JTextField, JTextArea, JRadioButton, JCheckbox, JMenu, JColorChooser etc. In addition to these components, swing provides several advanced components such as tabbed panel, scroll panes, trees, tables and list.

In comparison to AWT components, Swing components are not implemented by platform-specific code. Instead, they are written entirely in Java and therefore they are platform-independent and lightweight.

What You Need To Know About Swing

  • Java swing components are not dependent on the nature of the platform. They are purely scripted in Java.
  • Programmer has to import javax.swing package to write a swing application.
  • Swing components are much larger and offer higher levels of functionality.
  • Swing components provide in-built functions for their performance.
  • Swing components do not occupy as much memory space as AWT components.
  • Swing is based on MVC (Model View Controller), where model represents data, view represents presentation and controller acts as an interface between model and view.
  • Swing components are lightweight because it’s the responsibility of JVM to invoke the native methods.
  • Swing is an extension to AWT and many drawbacks of AWT are removed in swing.
  • Swing is based on Model View Controller pattern; the look and feel of swing components is independent of the hardware and the operating system.
  • Swing provides more powerful components such as tables, lists, scrollpanes, colorchooser, tabbedpane etc.
  • Swing executes faster.
  • Swing supports pluggable look and feel.

Also Read: Difference Between While And Do-while Loop In Java

Difference Between AWT And Swing In Tabular Form

BASIS OF COMPARISON ABSTRACT WINDOW TOOLKIT (AWT) SWING
Description AWT components are dependent on the nature of the platform. Its code resides in OS of the system hence makes it impossible for platform independence.   Java swing components are not dependent on the nature of the platform. They are purely scripted in Java.  
Package Programmer has to import the javax.awt package to develop an AWT-based GUI.   Programmer has to import javax.swing package to write a swing application.  
Nature AWT components serve as a thin layer of coding that lies at the top of OS.   Swing components are much larger and offer higher levels of functionality.  
Features Many features/functions of AWT components have to be implemented by the coder.   Swing components provide in-built functions for their performance.  
Memory Space Requirement AWT components require and occupy larger memory space.   Swing components do not occupy as much memory space as AWT components.  
Model View Controller AWT does not follow MVC (Model View Controller).   Swing is based on MVC (Model View Controller), where model represents data, view represents presentation and controller acts as an interface between model and view.  
General Feature AWT components are heavyweight because every graphical unit will invoke the native methods.   Swing components are lightweight because it’s the responsibility of JVM to invoke the native methods.  
Functionality AWT is less powerful than swing.   Swing is an extension to AWT and many drawbacks of AWT are removed in swing.  
Look And Feel The look and feel of AWT depends upon platform.   Swing is based on Model View Controller pattern; the look and feel of swing components is independent of the hardware and the operating system.  
Number Of Components AWT provides less components than swing.   Swing provides more powerful components such as tables, lists, scrollpanes, colorchooser, tabbedpane etc.  
Execution Execution of AWT is slower.   Swing executes faster.  
Support Pluggable Look And Feel AWT does not support pluggable look and feel.   Swing supports pluggable look and feel.  

Also Read: Difference Between Throw And Throws In Java