Java Swing AWT Interview Preparation Guide
Download PDF

Java Swing frequently Asked Questions in various Swing AWT job Interviews by interviewer. The set of Swing AWT interview questions here ensures that you offer a perfect answer to the interview questions posed to you. Get preparation of Swing AWT job interview

29 Swing AWT Questions and Answers:

1 :: Explain the use of JFC in Java Swing?

• JFC stands for Java Foundation Classes that consists of the collection of libraries designed to make the programmers that are creating the enterprise applications using Java Swing. Swing APIs are used to create a suite of library known as JFC. These classes also consist of AWT (Abstract Window Toolkit) that is used to access the API to increase the compatibility and enhance the support for the drag and drop capabilities that are provided by the JFC.
• The AWT that comes under JFC is a toolkit that comes with the Java Development Kit. It is made up of lightweight component.
• JFC consists of accessibility package that is used to provide assistance to the users who are having traditional interfaces. It is used for the devices like text readers and this allows the direct access to be given to the swing components. The accessibility consists of APIs that comes with swing distributions and utilities that are distributed separately.
• JFC consists of drag and drop facilities that provide graphical interfaces by which user can view the object and then it can be moved to another window or frame that is used in the desktop. The API allows the user to implement the elements that are used to transfer the information of Java applications.

2 :: Explain the difference between swing and AWT?

• AWT is a heavyweight component that is used to associate the language with the native component. Whereas, Swing is the lightweight component that doesn't associate, any language with the component that it uses.
• AWT draws the own component on the screen and it uses their own view-port that sends the output to the screen that displays the result. Whereas, Swing doesn't include any writing option to show the result on the screen so it does redirect to the components that makes it.
• AWT components are of the z-ordering and it is not possible to combine any other in the same container. Whereas, Swing doesn't include the z-ordering and it always come below the AWT.
• AWT is less consistent when used on different platforms. Whereas, Swing is more consistent across different platforms.

3 :: Explain the function of lightweight Components used in Swing?

Lightweight component allow the components to be dependent on the native group of other components. These components are simplified types that are used to display themselves on the screen and allow the result to be transparent from others. Each component in this renders itself using the graphics objects and the functions that are provided with it like: drawLine(), fillRect(). They render themselves on the heavyweight level component that they are used to be in. The libraries that are included in this involves: java.awt.Component or java.awt.Container classes. These classes are used to create lightweight components and it doesn't depend on the native group of components. It produce fast results and these components are memory-intensive that allows the user to create the look and feel of the application at run time. Swing component also allow modification to be done in the design easily.

4 :: Why is Model-View-Controller Architecture used in Swing?

Model-View-Controller Architecture is used to show the design of the components that are made up of three elements and these elements show the behavior of components as:
• Model: it consists of the state of individual component. Different models are used for different components for example scrollbar component that consists of the information used to display the current position and the values that are associated with it. Menu, can consists of a simple list containing the menu items that user can select and take actions on. This information doesn't change from component to component and it remains the same in every case. The model remains independent of the visual representation of the component.
• View: it defines the visual representation of the component. The view differs from one window to another window. The application can consist of different user interface platforms and specifications. It consists of all the components related to the visual appearance. It deals with different views of a particular component.
• Controller: provides the way to control the relationship between the model and the view and it allows the interaction to be done with the events. The events can have many forms like mouse click, having focus on some button or some kind of triggers that are on some menu, etc. This is the controller that decides the component that is to be used to react to an event.

5 :: How is multi-threading gets implemented using Swing?

Swing uses multi-threading techniques to utilize the resources that are provided by the Java classes. Swing allows the users to create independent threads that can be used to change the model states of the components. If any changes happens in the component that is reflected on the screen then just updating the model state of the class that is used from the event dispatching queue. This event dispatching queue allows the component to communicate with each other. It also handles the user interface events that are used by the components. To increase the performance it requires the modifications to be refreshed so that the updated data is always received every time the component gets repeated. Multi-threading allows the swing program to run faster. This decreases the delay time and reduces the CPU usage that is used by the programs running on a single thread environment.

6 :: Explain Swing?

Swing is a library of GUI controls. Classes in swing are not OS dependent.
They don’t create peer components, so they are light weight unlike AWT.
They don’t take the look and feel of the target platform so they have a consistent appearance

7 :: Explain AWT?

Abstract Window Toolkit provides a standard Application Programming Interface for writing Graphical User Interfaces in Java.

8 :: Explain the differences between Swing and AWT?

Swing is a library of GUI controls. Classes in swing are not OS dependent.
They don’t create peer components, so they are light weight unlike AWT.
They don’t take the look and feel of the target platform so they have a consistent appearance

9 :: What are heavyweight and lightweight components?

In Java AWT - Abstract Window Toolkit, GUI components created are OS dependent. When they are created, each component forms a peer component due to which they are called heavyweight components.

Swing components are platform independent. No peer components are formed due to which they are called lightweight components.

10 :: What are controls and what are different types of controls in AWT?

Controls are components that allow a user to interact with your application.
A component is a graphical object. A few examples of components are:

Button
Canvas
Checkbox
Choice
Container
Label
List
Scrollbar
TextComponent