0% found this document useful (0 votes)
71 views5 pages

2.swing Imp Questions

Here is Swing important questions

Uploaded by

joshiprakash3030
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views5 pages

2.swing Imp Questions

Here is Swing important questions

Uploaded by

joshiprakash3030
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Java Swing Interview Questions and Answers Pdf

Question: 1

What is a layout manager and what are different types


of layout managers available in Java Swing?
A layout manager is an object that is used to organize components in a container.

The different layouts available are FlowLayout, BorderLayout, CardLayout, GridLayout


and GridBagLayout.

FlowLayout: The elements of a FlowLayout are organized in a top to bottom, left to right
fashion.

BorderLayout: The elements of a BorderLayout are organized at the borders(North, South East
and West) and the center of a container.

CardLayout: The elements of a CardLayout are stacked, on top of the other, like a deck of
cards.

GridLayout: The elements of a GridLayout are of equal size and laid out using the square of a
grid.

GridBagLayout: The elements of a GridBagLayout are organized according to a grid. However,


the elements may be different sizes and may occupy more than one row or column of the grid. In
addition, the rows and columns may have different sizes.

Question: 2

What is a container in a GUI?


A container contains and arranges other components (including other container) through the use
of layout managers, which use specific layout policies to determine where components should go
as a function of the size of the container.

Question: 3

What advantage do Java’s layout managers provide


over traditional windowing systems?
Java uses layout managers to lay out components in a consistent manner across all windowing
platforms.

Since Java’s layout managers aren’t tied to absolute sizing and positioning, they are able to
accommodate platform specific differences among windowing systems.

Question: 4

Why Swing components are called lightweight


component?
AWT component are associated with native screen resource and called heavyweight component
while Swing components is uses the screen resource of an ancestor instead of having their own
and that’s why called lightweight or lighter component.

Question: 5

What are peerless components?


The peerless components are called light weight components.

Question: 6

What is the difference between the Font and


FontMetrics classes?
The FontMetrics class is used to define implementation specific properties, such as ascent and
descent of a Font object.

Question: 7

Which package has light weight component?


javax.Swing package contains light weight components.

All components in Swing, except JApplet, JDialog, JFrame and JWindow are lightweight
components.

Question: 8
Name Container classes?
Window,

Frame,

Dialog,

FileDialog,

Panel,

Applet or ScrollPane.

Question: 9

Name the containers which use Border Layouts as


their default layout?
Window, Frame and Dialog classes.

Question: 10

Which container method is used to cause a container


to be laid out and redisplayed?
validate()
Java Swing Interview Questions and Answers Pdf
Question: 1

What is Event Driven Thread (EDT) is Swing?


Event Driven Thread or EDT is a special thread in Swing and AWT. Event Driven Thread is
used to draw graphics and listen for events in Swing.

You will get a bonus point if you able to highlight that time consuming operations like
connecting to database, opening a file or connecting to network should not be done on EDT
thread because it could lead to freezing GUI because of blocking and time consuming nature of
these operations instead they should be done on separate thread and EDT can just be used o
spawn those thread on a button click or mouse click.

Question: 2

What are differences between Swing and AWT?


There is couple of differences between swing and AWT.

AWT component are considered to be heavyweight while Swing component are lightweights.

Swing has plug gable look and feel.

AWT is platform dependent same GUI will look different platform while Swing is developed in
Java and is platform dependent.

Question: 3

What is the difference between a Window and a


Frame?
The Frame extends Window to define a main application window that can have a menu bar.

Question: 4

What is the difference between the paint() and


repaint() methods?
The paint() method supports painting via a Graphics object.

The repaint() method is used to cause paint() to be invoked by the AWT painting thread.

Question: 5

How can a GUI component handle its own events?


A component can handle its own events by implementing the required event listener interface
and adding itself as its own event listener.

You might also like