Most Asked Swing Interview Questions and Answers

Swing Interview Questions and Answers most commonly asked for Experienced PDF, Freshers candidates for Employment.

Which Swing methods are thread-safe?

The only thread-safe methods are following here :
> Repaint(),
> Revalidate(), and
> Invalidate()

Why won’t the JVM terminate when I close all the application windows?

The AWT event dispatcher thread is not a daemon thread. You must explicitly call System.exit to terminate the JVM.

What is double buffering?

Double buffering is the process of use of two buffers rather than one to temporarily hold data being moved to and from an I/O device. Double buffering increases data transfer speed because one buffer can be filled while the other is being emptied.

What is an event?

Event is basically a changing the state of an object .

What is an event handler?

An event handler is basically is a part of a computer program, Which is created mainly for the programs, Its signifies the program how to act in response to a specific event.

Which containers use a border Layout as their default layout?

Any containers are there which is use border layout as their default layout. that are following as :
> The window,
> Frame and
> Dialog classes .

What method is used to specify a container’s layout?

Many methods are used to specify a container’s layout But the main method is :
> The setLayout()

What is the difference between invokeAndWait() and invokeLater()?

Many diff are there which is defined as :
> InvokeAndWait : is synchronous. It blocks until Runnable task is complete.
> InvokeLater is asynchronous. It posts an action event to the event queue and returns immediately. It will not wait for the task to complete .

Why should any swing call back implementation execute quickly?

Any cal back implementation execute quickly should be imp because Callbacks are invoked by the event dispatch thread. Event dispatch thread blocks processing of other events as long as call back method executes.

Which method is used by the applet to recognize the height and width?

Method is there :
> getParameters().

What is source and listener?

They are defined as :
> A source : It is an object that generates an event. This occurs when the internal state of that object changes in some way.
> A listener : It is an object that is notified when an event occurs. It has two major requirements.
* It must have been registered with a source to receive notifications about specific event.
* It must implement necessary methods to receive and process these notifications.

What is controls and what are different types of controls in AWT?

Controls are basically a components, Which is allow a user to interact with your application.
AWT supports the following types of controls :
> Labels,
> Push Buttons,
> Check Boxes,
> Choice Lists,
> Lists,
> Scrollbars,
> Text Components.
These controls are subclasses of Component.

What is the difference between choice and list?

They are defined as :
> A Choice : Choice is displayed in a compact form that requires us to pull it down to see the list of available choices and only one item may be selected from a choice.
> A List : It may be displayed in such a way that several list items are visible and it supports the selection of one or more list items.

What is the difference between scrollbar and scrollpane?

Main diff are there :
> A Scrollbar is a Component, but not a Container whereas Scrollpane is a Container and handles its own events and perform its own scrolling.

What is a layout manager and what are different types of layout managers available?

A layout manager is basically an object, Its mainly used to organize components in a container.
The different layouts are available here :
> FlowLayout,
> BorderLayout,
> CardLayout,
> GridLayout ,
> GridBagLayout,
> Boxlayout and
> SpringLayout.

How are the elements of different layouts organized?

The elements of a FlowLayout are organized in a top to bottom, left to right fashion. The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container. The elements of a CardLayout are stacked, on top of the other, like a deck of cards. The elements of a GridLayout are of equal size and are laid out using the square of a grid. The elements of a GridBagLayout are organized according to a grid. However, the elements are of different size and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes. It is the most flexible layout.

What are types of applets?

There are two different types of applets. that are defined as :
> Trusted Applets and
> Untrusted applets.
> Trusted Applets : are applets with predefined security .and
> Untrusted Applets : are applets without any security.

What are the restrictions imposed by a Security Manager on Applets?

Applets cannot read or write files on the client machine that’s executing it. They cannot load libraries or access native libraries. They cannot make network connections except to the host that it came from. They cannot start any program on the client machine. They cannot read certain system properties. Windows that an applet brings up look different than windows that an application brings up.

What is the difference between the Font and FontMetrics classes?

Main diff are there :
> The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.

What is the relationship between an event-listener interface and an event-adapter class?

An Event-listener interface basically defines the methods , Which  must be implemented by an event handler for a particular kind of event. An event adapter provides a default implementation of an event-listener interface.

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.

What is the difference between the paint() and repaint() methods?

Main diff are there :
> The paint() method : Its supports painting via a Graphics object.
> The Repaint() method : It is used to cause paint() to be invoked by the AWT painting thread.

What interface is extended by AWT event listeners?

java.util.EventListener interface is extented by all AWT event listeners.

What is Canvas?

Canvas is basically a Component of the subclass which is used for drawing and painting. Canvas is a rectangular area where the application can draw or trap input events.

What is default Look-and-Feel of a Swing Component?

Java Look-and-Feel is the default Look-and-Feel of the Swing Component.


Popular posts from this blog

TOP Agile Testing Interview Questions and Answers

Latest Agile Testing Interview Questions and Answers

Most Asked ADO.NET Interview Questions and Answers