Вы находитесь на странице: 1из 9

Menu Bar Program

Calculator Program
Form Program
Applet Program
Interface Program
Inner Class Program

Difference between Swing and AWT?

What is the difference between text field and text area?

TextField TextArea
TextField is an AWT component TextArea is an AWT component
that allows entering a single line of that allows entering multiple lines of
text in a GUI application text in a GUI application.
It doesn’t have a scrollbar. It does have a scrollbar.

What is the method used to retrieve the text of a Label?


String getLabel() is the method used to retrieve the text of a Label.

What is the method used to place some text in the text field?
void setText(String str) is the method used to place some text in the text
field
.
Explain Component and Container.
The component is an abstract class that encapsulates all of the
attributes of a visual component. Except for menus, all user interface
elements that are displayed on the screen and that interact with the user
are subclasses of Component. It defines over a hundred public methods
that are responsible for managing events, such as mouse and keyboard
input, positioning and sizing the window, and repainting.

The Container is a component in AWT that can contain another


components like buttons, text-fields, labels etc. The classes that extends
Container class are known as container such as Frame, Dialog and Panel.
A container is responsible for laying out (that is, positioning)
any components that it contains.

Explain swing is build on AWT?


Swing eliminates a number of the limitations inherent in the AWT and
Swing does not replace it.
Instead, Swing is built on the foundation of the AWT. Swing also uses the
same event handling mechanism as the AWT. Therefore, a basic
understanding of the AWT and of event handling is required to use Swing.
How do you add/remove component in AWT?
Using add() and remove() method, we can add/remove component in AWT.
Following forms is used to add/remove component in AWT.
Component add(Component compRef)
void remove(Component compRef)

Difference between Panel and Frame?

List out methods defined inside KeyListener interface with their method
signature?
Methods defined inside Key Listener interface with their method signature
are
keyPressed( ): Methods are invoked when a key is pressed
keyReleased( ): Methods are invoked when a key is released, respectively.
keyTyped( ): Method is invoked when a character has been entered.

What are the two types of Applet?


There are two types of applet -

● Applets based on the AWT(Abstract Window Toolkit) package by extending its


Applet class.
● Applets based on the Swing package by extending its JApplet class.

Define event source and event listener?


Event sources are components, subclasses of java.awt.Component,
capable to generate events. This happens when the internal state of the object
changes in some way. The event source can be a button, TextField or a
Frame etc. Each type of event has its own registration method.
General form:
public void addTypeListener (TypeListener el )
For example, the method that registers a keyboard event listener is called
addKeyListener( ).

A listener is an object that is notified when an event occurs. The events


generated by the GUI components are handled by a special group of
interfaces known as "listeners".
For example, ActionListener handles the events of Button, TextField, List
and Menus. Listeners are from java.awt.event package.

Define the layout manager?


LayoutManager is an interface that is implemented by all the classes of
layout managers. The LayoutManagers are used to arrange components in
a particular manner.
The setLayout( ) method has the following general form:
void setLayout(LayoutManager layoutObj)

Write two feature of swing?


Swing Components Are Lightweight
Swing Supports a Pluggable Look and Feel

Differentiate between button and toggle button?

What is AWT classes?


It is one of Java’s largest packages contained in the java.awt package. It
contains numerous classes and methods that allow you to create windows
and simple controls. It is used built GUI or window-based application in
java. The java.awt package provides classes for AWT such as TextField,
Label, TextArea, RadioButton, CheckBox, Choice, List etc.

What is hiding and showing a frame in AWT?

Write steps to compile and run applet program?


c:\>javac fileName.java
c:\>appletviewer fileName.java
What is an Applet skeleton?
What is Applet?
Applet are small applications that are accessed on an Internet server,
transported over the Internet, automatically installed, and run as part of a
web document. After an applet arrives on the client, it has limited access to
resources so that it can produce a graphical user interface and
run various computations without introducing the risk of viruses or
breaching data integrity.

What is Adapter classes and Inner classes?


Adapter class is a special feature provided in java that can simplify the
creation of event handlers in certain situations. An adapter class provides
an empty implementation of all methods in an event listener interface. It is
useful when you want to receive and process only some of the events that
are handled by a particular event listener interface.

An inner class is a class which is defined inside another class. The inner
class can access all the members of an outer class, but vice-versa is not
true.

How to make text field non-editable in java?


We make text field non-editable in java by calling method:
void setEditable(boolean canEdit)

What is MVC?
MVC framework is software architecture used to separate the data access
layer, business logic code and the graphical user interface that has to be
defined and designed to let the user interact with the application. This
application has three parts,
MODEL
VIEW
CONTROLLER

How to pass Parameters to Applets?

To retrieve a parameter, use the getParameter( ) method. It returns the


value of the specified parameter in the form of a String object. Thus, for
numeric and boolean values, you will need to convert their string
representations into their internal formats.

Here is an example that demonstrates passing parameters:

import java.applet.Applet;
import java.awt.Graphics;
/*
<applet code="UseParam.class" width="300" height="300">
<param name="msg" value="Welcome to applet">
</applet>
*/
public class UseParam extends Applet {
public void paint(Graphics g) {
String str = getParameter("msg");
g.drawString(str, 50, 50);
}
}

Write two ways to run an applet?


There are two ways to run an applet
By html file.
By appletViewer tool (for testing purpose)

Java Application vs Applet

Disadvantage of 2 tier architecture?


Security
Efficency

RequestDispatcher in java?
The RequestDispatcher interface provides the facility of dispatching the request to another
resource it may be html, servlet or jsp. This interface can also be used to include the
content of another resource also. It is one of the way of servlet collaboration.

Methods of RequestDispatcher interface

1. public void forward()


2. public void include()

Example of using getRequestDispatcher method

1. RequestDispatcher rd=request.getRequestDispatcher("servlet2");
rd.forward(request, response);//method may be include or forward
ErrorPage attribute?

In JSP, the errorPage attribute of page directive is used to specify a web page which will
be displayed as an error page for the current JSP page i.e. if there is an error while
executing the current page).

● Syntax<%@ page errorPage= "path-to-another-jsp-page" %>

JSP declaration? Syntax?

● A declaration tag is a piece of Java code for declaring variables,


methods and classes. If we declare a variable or method inside
declaration tag it means that the declaration is made inside the
servlet class but outside the service method.

Syntax

<%! field or method declaration %>

Connection Pooling?

Connection pooling means that connections are reused rather than


created each time a connection is requested. To facilitate connection
reuse, a memory cache of database connections, called a connection
pool, is maintained by a connection pooling module as a layer on top
of any standard JDBC driver product.

Connection pooling is performed in the background and does not


affect how an application is coded;
Different method to execute sql statement?

1) public ResultSet executeQuery(String sql): is used to execute SELECT query.

It returns the object of ResultSet.

2) public int executeUpdate(String sql): is used to execute specified query, it

may be create, drop, insert, update, delete etc.

3) public boolean execute(String sql): is used to execute queries that may return

multiple results.

4) public int[] executeBatch(): is used to execute batch of commands.

Methods of mouse listener interface?

1. public abstract void mouseClicked(MouseEvent e);


2. public abstract void mouseEntered(MouseEvent e);
3. public abstract void mouseExited(MouseEvent e);
4. public abstract void mousePressed(MouseEvent e);
5. public abstract void mouseReleased(MouseEvent e);

Вам также может понравиться