Top 15 Jface Interview Questions You Must Prepare 19.Mar.2024

Standard Widget Toolkit (SWT):

SWT is an open source widget tool kit for developing rich, efficient and portable GUI applications. It was originally developed by IBM and being maintained by Eclipse Foundation along with Eclipse IDE. It is an alternative to AWT and Swing. To display the elements, it implements the operating system GUI libraries by using Java Native Interface. The SWT applications are portable and unique for each platform.

The need of SWT is to provide a common API for accessing different operating system / platform specific widgets. The goal for designing of SWT is high performance, native OS look and feel, and platform integration. Swing on the other hand, designed to allow for a highly customizable look and feel that is common across different platforms.

JFace:

A User Interface project developed by Eclipse to handle most commonly used User Interface tasks. It is window based system independent in both implementation and API. It is designed to work with SWT. JFace is included with images, text, dialog, wizard, images, font registries and progress reporting for long running operations.

JFace has two mechanisms – namely action and viewing.

The mechanism of actions allows the commands to be defined independently by the user from the exactness of whereabouts in the User Interface.

The mechanism of viewing is based on the adapters for certain SWT widgets, which simplifies the application presentation data structured with lists, tables or trees.

Eclipse runtime kernel is connected with few classes that have JFace. It can be a common practice to extract JFace and SWT to be used for stand-alone java applications which is not based on the Eclipse runtime.

Using JFace Text framework, sophisticated editors such as XML editors and text editors can be developed. Any application needs editors to author the designated code. For example XML file needs tags to be written a flat text file. A program needs editor to author the code. By using different development template these editors can be plugged in and developed

Viewers are used to display objects using different SWT widgets.

Types of viewers are as follows:

  • The ListViewer uses the SWT List widget to display the object. A simple list of elements can be created by using ListViewer.
  • The CheckboxTableViewer uses the SWT widget to display the objects of checkboxes.
  • The CheckboxTreeViewer uses the SWT table control with checkboxes on each node.
  • The CheckboxTreeViewer uses the SWT Tree control with checkboxes on each node.
  • The TableTreeViewer uses the SWT Table Tree control.
  • TableViewer, uses the SWT TableViewer control.
  • TreeViewer, uses the SWT TreeViewer control.

The JFace viewer framework is an independent module for JFace which needs some knowledge of SWT. The abstract base classes for viewers comprise the framework. The base class is the Viewer which is an extension of a structured viewer. The Viewer acts as a widget container. It is the responsibility for the content provider to respond to the various modifications to the model by informing the viewer, what to change (using add () and remove () methods).

Each viewer registers with the label provider for identifying / notifying the changes that would affect the viewers display.

ImageRegistry:

The mapping between symbolic image names and SWT image objects is maintained by the ImageRegistry class until the SWT image objects are needed. It owns all the images registered with it and automatically disposes them when the SWT Display that creates the images is disposed.

FontRegistry:

The FontRegistry maps between symbolic font names and SWT fonts. It owns all the fonts registered with it and automatically disposes them when the SWT Display that creates the fonts is disposed.

Dialog:

Dialogs are used to communicate the information from the user or to the user.

The following are the different types of messages:

  • The MessageDialog displays information to the user
  • The InputDialog accepts the input from the user in the form of text
  • The ErrorDialog displays one or more errors to the user.

Wizard:

A wizard can be used to create new java classes, projects, files and folders. Wizards provide step by step process to create these elements. A well defined wizard is targeted to simplify user tasks and increase productivity. Wizard is meant to take out the hassle of creating repetitive and tedious tasks.

Action Mechanism:

Actions are tasks for various users operations such as clicks on menus, toolbars, status lines etc. In order to support these actions the action mechanism is implemented. There are listeners and managers for each of these actions.

Viewers:

Viewers are used to display objects using different SWT widgets.

Types of viewers are as follows:

The ListViewer uses the SWT List widget to display the object. A simple list of elements can be created by using ListViewer.

The CheckboxTableViewer uses the SWT widget to display the objects of checkboxes.

The CheckboxTreeViewer uses the SWT table control with checkboxes on each node.

The CheckboxTreeViewer uses the SWT Tree control with checkboxes on each node.

The TableTreeViewer uses the SWT Table Tree control.

TableViewer, uses the SWT TableViewer control.

TreeViewer, uses the SWT TreeViewer control.

Editors: Using JFace Text framework, sophisticated editors such as XML editors and text editors can be developed. Any application needs editors to author the designated code. For example XML file needs tags to be written a flat text file. A program needs editor to author the code. By using different development template these editors can be plugged in and developed

Actions are tasks for various users operations such as clicks on menus, toolbars, status lines etc. In order to support these actions the action mechanism is implemented. There are listeners and managers for each of these actions.

The mapping between symbolic image names and SWT image objects is maintained by the ImageRegistry class until the SWT image objects are needed. It owns all the images registered with it and automatically disposes them when the SWT Display that creates the images is disposed.

Some of the operating system specific libraries are to be loaded for SWT applications before they can execute. The combination of SWT application with Java Web Start provides powerful tools to deploy the client side applications.

To test a Java Web Start application the following are the prerequisites:

  • Microsoft Windows XP or Red Hat Linux V8
  • Java 2 SDK, Standard Edition V1.4 or later
  • Apache Ant V1.5.3 or later
  • Apache Jakarta Tomcat V4.1.24 or later

The steps for deploying:

Install the application in the required directory

Signing the code and security:

SWT is tightly integrated with the operating system's native windowing environment. SWT uses a system libraries to manage the platform independent API and the supporting operating system. All the required JAR files deployed with Java Web Start must be digitally signed. Self-signed test certificate is needed to be created, as the specific application is not going to deploy for wide user base.

Creation of self-signed certificate:

Execute the command in the directory where the application is to be deployed:

keytool -genkey -keystore keystore -alias myself

A prompt message will be displayed stating to enter the password,name, locality etc. During the ANT build process, the actual signing the JAR files will be completed.

To verify that the keystore was properly created, type the following command:

keytool -list-keystore keystore

Build the file using the ANT

a). To clean the environment, type: ant clean

b). To execute the build process type: ant

Give a trial to execute the application using the command: ant run

To deploy the application to Apache Tomcat web server:

  • Place the application’s .war file into webapps directory under Tomcat.
  • Execute the script to start Apache Tomcat
  • Open the web browser and type http://localhost:8080/index.html. Now click on Launch application.
  • Click on Start in the displayed dialog box to start the application.

Dialogs are used to communicate the information from the user or to the user.

The following are the different types of messages:

  • The MessageDialog displays information to the user
  • The InputDialog accepts the input from the user in the form of text
  • The ErrorDialog displays one or more errors to the user.

The JFace text provides a framework for the creation and manipulation of text documents. IDocument is the major abstraction for the text model. The content management, position management using portion categories, document partition management, and change notification is provided by this text model.

Java Web Start (JavaWS) technology is a framework which is used to allow the user to run java platform specific application software directly from the internet. The Java Web Start applications do not run in a browser. Web start application provides a series of classes which provides various services to the applications. These classes are available in the package called javax.jnlp

Web start comes as a part of Java Runtime Environment without having separately installed. It comprises the portability of applets and maintainability of servlets and JSP technologies. Java Web Start allows the java client applications to be launched, updated, and deployed from a standard web server.

The Java Application Manager feature allows the end-users to organize the java applications and also provides different options such as specifying the use of multiple Java Runtime Environments, setting proxy servers for HTTP.

The automatic conversion of primitive int type into a wrapper class object is called autoboxing. It does not require to type cast the int value. The modification of primitive wrapper objects is done directly.

The following example illustrates autoboxing:

int number;

Integer intObject;

number = 1;

intObject = 2;

number = intObject;

intObject = number;

Advantages of SWT:

  • Provides backend by providing native look with backend widgets by supporting Swing programming model.
  • SWT could run Swing native objects which enables SWT to run on any Swing support platform.
  • SWT based application loads faster compared to Swing applications
  • The memory usage is smaller in SWT as it uses the shared libraries. The shared library loads only once for all SWT applications.
  • Provides the exact platform look and feel. Even with the skinned desktop, it looks and feel is also skinned.
  • Provides different styles for different types of menus

A wizard can be used to create new java classes, projects, files and folders. Wizards provide step by step process to create these elements. A well defined wizard is targeted to simplify user tasks and increase productivity. Wizard is meant to take out the hassle of creating repetitive and tedious tasks.

The FontRegistry maps between symbolic font names and SWT fonts. It owns all the fonts registered with it and automatically disposes them when the SWT Display that creates the fonts is disposed.