Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: Advance java notes with Q & A formate
Description: Java Advanced Imaging (JAI) is a Java platform extension API that provides a set of object-oriented interfaces that support a simple, high-level programming model

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


ADVANCED JAVA ANSWER KEY
OCTOBER 2015
1
...
Explain the use of adapter class with suitable example
...
An adapter class provides an empty implementation
of all methods in an event listener interface
...

You can define a new class to act as an event listener by extending one of the adapter
classes and implementing only those events in which you are interested
...
If you were interested in only mouse drag events, then you could simply extend
MouseMotionAdapter and override mouseDragged( )
...

The following example demonstrates an adapter
...
However, all other
mouse events are silently ignored
...
AdapterDemo extends
Applet
...
It also creates an instance of
MyMouseMotionAdapter
and registers that object to receive notifications of mouse motion events
...

MyMouseAdapter extends MouseAdapter and overrides the mouseClicked( ) method
...
MyMouseMotionAdapter extends MouseMotionAdapter and overrides the
mouseDragged( ) method
...

Note that both of the event listener classes save a reference to the applet
...

// Demonstrate an adapter
...
awt
...
awt
...
*;
import java
...
*;
/*


*/
public class AdapterDemo extends Applet {
public void init() {
addMouseListener(new MyMouseAdapter(this));
addMouseMotionListener(new MyMouseMotionAdapter(this));
}
}
class MyMouseAdapter extends MouseAdapter {
AdapterDemo adapterDemo;

10

public MyMouseAdapter(AdapterDemo adapterDemo) {
this
...

public void mouseClicked(MouseEvent me) {
adapterDemo
...
adapterDemo = adapterDemo;
}
// Handle mouse dragged
...
showStatus("Mouse dragged");
}
}
As you can see by looking at the program, not having to implement all of the methods
defined by the MouseMotionListener and MouseListener interfaces saves you a
considerable amount of effort and prevents your code from becoming cluttered with
empty methods
...

b
...

The Delegation Event Model
The modern approach to handling events is based on the delegation event model, which
defines standard and consistent mechanisms to generate and process events
...
In this scheme, the
listener simply waits until it receives an event
...
The advantage of this design is that the application
logic that processes events is cleanly separated from the user interface logic that
generates those events
...

In the delegation event model, listeners must register with a source in order to receive an
event notification
...
This is a more efficient way to handle events than the
design used by the old Java 1
...
Previously, an event was propagated up the
containment hierarchy until it was handled by a component
...
The delegation
event model eliminates this overhead
...

However, the delegation event model is the preferred design for the reasons just cited
...

Events
In the delegation model, an event is an object that describes a state change in a source
...
Some of the activities that cause events to be generated are

pressing a button, entering a character via the keyboard, selecting an item in a list, and
clicking the mouse
...

Events may also occur that are not directly caused by interactions with a user interface
...
You are free to
define events that are appropriate for your application
...
This occurs when the internal state of that
object changes in some way
...

Asource must register listeners in order for the listeners to receive notifications about
a specific type of event
...
Here is the
general form:
public void addTypeListener(TypeListener el)
Here, Type is the name of the event, and el is a reference to the event listener
...

The method that registers a mouse motion listener is called addMouseMotionListener( )
...
This is known as multicasting the event
...

Some sources may allow only one listener to register
...
util
...
When such
an event occurs, the registered listener is notified
...

A source must also provide a method that allows a listener to unregister an interest
in a specific type of event
...
For
example, to remove a keyboard listener, you would call removeKeyListener( )
...
For example, the Component class provides methods to add and remove keyboard
and mouse event listeners
...
It has two major
requirements
...
Second, it must implement methods to receive and process these
notifications
...
awt
...
For example, the MouseMotionListener interface defines two methods to
receive notifications when the mouse is dragged or moved
...

Many other listener interfaces are discussed later in this and other chapters
...
Write AWT based Java program that will read a string from user and display the
number of characters in the string
...
List various Event listener interfaces
...

Different event listener interfaces are :

ActionListener
AdjustmentListener
ComponentListener
ContainerListener
FocusListener
ItemListener
KeyListener
MouseListener
MouseMotionListener
MouseWheelListener
TextListener
WindowFocusListener
WindowListener
Explanation
The AdjustmentListener Interface
This interface defines the adjustmentValueChanged( ) method that is invoked when an
adjustment event occurs
...
Their general forms are shown here:
void componentResized(ComponentEvent ce)
void componentMoved(ComponentEvent ce)
void componentShown(ComponentEvent ce)
void componentHidden(ComponentEvent ce)
The ContainerListener Interface
This interface contains two methods
...
When a component is removed from a container,
componentRemoved( ) is invoked
...
When a component obtains keyboard focus,
focusGained( )
is invoked
...
Their general
forms are shown here:
void focusGained(FocusEvent fe)
void focusLost(FocusEvent fe)
The ItemListener Interface
This interface defines the itemStateChanged( ) method that is invoked when the state of
an
item changes
...
The keyPressed( ) and keyReleased( ) methods are
invoked when a key is pressed and released, respectively
...

For example, if a user presses and releases the A key, three events are generated in
sequence: key pressed, typed, and released
...

The general forms of these methods are shown here:
void keyPressed(KeyEvent ke)
void keyReleased(KeyEvent ke)
void keyTyped(KeyEvent ke)
The MouseListener Interface
This interface defines five methods
...
When the mouse enters a component, the mouseEntered( )
method is called
...
The mousePressed( ) and
mouseReleased( ) methods are invoked when the mouse is pressed and released,
respectively
...
The mouseDragged( ) method is called multiple
times as the mouse is dragged
...
Their general forms are shown here:
void mouseDragged(MouseEvent me)
void mouseMoved(MouseEvent me)
The MouseWheelListener Interface
This interface defines the mouseWheelMoved( ) method that is invoked when the mouse
wheel is moved
...
Its general form is shown here:
void textChanged(TextEvent te)
The WindowFocusListener Interface
This interface defines two methods: windowGainedFocus( ) and windowLostFocus( )
...
Their general forms are
shown here:
void windowGainedFocus(WindowEvent we)
void windowLostFocus(WindowEvent we)
The WindowListener Interface
This interface defines seven methods
...
If a
window is iconified, the windowIconified( ) method is called
...
When a window is opened or
closed, the windowOpened( ) or windowClosed( ) methods are called, respectively
...
The general forms of
these methods are

void windowActivated(WindowEvent we)
void windowClosed(WindowEvent we)
void windowClosing(WindowEvent we)
void windowDeactivated(WindowEvent we)
void windowDeiconified(WindowEvent we)
void windowIconified(WindowEvent we)
void windowOpened(WindowEvent we)
2
...
Write a Java program using swing components that displays table containg
employee information
...
What is use of JcolorChooser? Write down the constructors and methods of the
same
...

Constructors
JColorChooser()
Creates a color chooser pane with an initial color of white
...

JColorChooser(ColorSelectionModel model)
Creates a color chooser pane with the specified ColorSelectionModel
...

void setColor(Color color)
Sets the current color of the color chooser to the specified color
...

void setColor(int r, int g, int b)
Sets the current color of the color chooser to the specified RGB color
...

c
...
Every
tab displays a list of all subjects of respective year
...
Explain JTree with example
...
The user has the ability to
expand or collapse individual subtrees in this display
...
A sampling of its constructors is shown here:
JTree(Object obj[ ])
JTree(Vector v)
JTree(TreeNode tn)
In the first form, the tree is constructed from the elements in the array obj
...
In the third form, the tree whose
root node is specified by tn specifies the tree
...
swing, its support classes and interfaces are
packaged in javax
...
tree
...

JTree relies on two models: TreeModel and TreeSelectionModel
...
TreeExpansionEvent events occur when a
node is expanded or collapsed
...
ATreeModelEvent is fired when the data or structure
of the tree changes
...
The tree event classes and listener interfaces are
packaged in javax
...
event
...

To listen for this event, implement TreeSelectionListener
...
You can obtain
the path to the selected object by calling getPath( ), shown here, on the event object
...
The TreePath
class encapsulates information about a path to a particular node in a tree
...
In this book, only the toString( ) method is used
...

The TreeNode interface declares methods that obtain information about a tree node
...
The MutableTreeNode interface extends TreeNode
...

The DefaultMutableTreeNode class implements the MutableTreeNode interface
...
One of its constructors is shown here:
DefaultMutableTreeNode(Object obj)
Here, obj is the object to be enclosed in this tree node
...

To create a hierarchy of tree nodes, the add( ) method of DefaultMutableTreeNode can be
used
...

JTree does not provide any scrolling capabilities of its own
...
This way, a large tree can be scrolled through a smaller
viewport
...
Create an instance of JTree
...
Create a JScrollPane and specify the tree as the object to be scrolled
...
Add the tree to the scroll pane
...
Add the scroll pane to the content pane
...
The
program creates a DefaultMutableTreeNode instance labeled “Options
...
Additional tree nodes are then created, and the add( ) method
is called to connect these nodes to the tree
...
The tree is then provided as the
argument to the JScrollPane constructor
...
Next, a label is created and added to the content pane
...
To receive selection events from the tree, a TreeSelectionListener
is registered for the tree
...

// Demonstrate JTree
...
awt
...
swing
...
*;
import javax
...
*;
import javax
...
tree
...
invokeAndWait(
new Runnable() {
public void run() {
makeGUI();
}
}
);
} catch (Exception exc) {
System
...
println("Can't create because of " + exc);
}
}
private void makeGUI() {
// Create top node of tree
...

DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
top
...
add(a1);
DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
a
...

DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
top
...
add(b1);
DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2");
b
...
add(b3);
// Create the tree
...


JScrollPane jsp = new JScrollPane(tree);
// Add the scroll pane to the content pane
...

jlab = new JLabel();
add(jlab, BorderLayout
...

tree
...
setText("Selection is " + tse
...
Attempt any two of the following:
a
...

When a servlet accepts a call from a client, it receives two objects
...

ServletResponse encapsulates the communication from the server to client
...

 Names of the remote host that made the request
...

Subclass os ServletRequest allow the servlet to retrieve more protocol specific data
...
HttpServletRequest
Defines an object to provide client request information to a servlet
...

A ServletRequest object provides data including parameter name and values, attributes,
and an input stream
...
lang
...
lang
...

java
...
Enumeration getAttributeNames()
Returns an Enumeration containing the names of the attributes available to this
request
...
lang
...
lang
...

java
...
Enumeration
getParameterNames()
Returns an Enumeration of String objects containing the names of the parameters
contained in this request
...
lang
...
lang
...


10

RequestDispatcher getRequestDispatcher(java
...
String path)
Returns a RequestDispatcher object that acts as a wrapper for the resource located
at the given path
...
lang
...

void removeAttribute(java
...
String name)
Removes an attribute from this request
...
lang
...
lang
...

ServletResponse interface provides methods to the Servlet for replying to the client
...

 Provides an output stream and a Writer
...

Subclasses of ServletResponse provide the Servlet with more protocol-specific
capabilities
...
HttpServletResponse
java
...
Locale getLocale()
Returns the locale assigned to the response
...

java
...
PrintWriter getWriter()
Returns a PrintWriter object that can send character text to the client
...

void setLocale(java
...
Locale loc)
Sets the locale of the response, setting the headers (including the Content-Type's
charset) as appropriate
...
Write a servlet program to display the factorial of a given number
...
What is servlet? What are different tasks carried out by servlets?
A java Servlet is a server side program that services HTTP requests and returns the result
as HTTP responses
...
Servlets are the
Web Server side counterpart to Applets
...

Applets are Java application components, which are downloaded, on demand, run in a
Java enabled client browser and thus participate in the commercial application, which
needs them
...

It is most commonly used with HTTP and the world Servlet is often used in the meaning
of HTTP Servlet
...

It solves the performance problem by executing all requests as threads in one process
It can easily share resources
It can be easily ported to other platforms that support Java, as it runs inside a JVM
...

The servlet dynamically produces a response to the request, typically an HTML web page

and sends it back to the requesting web browser
...

It is the JVM that is built to run on a specific hardware platform
...

Java servlet provide an object-oriented and extensible middle tire for web server based
applications
...

Different tasks carried out by servlet are
A servlet can process and/or store data submitted by an HTML form
A servlet can provide dynamic content
...

(A stateless protocol does not require the server to retain session information or status
about each communications partner for the duration of multiple requests
...

A servlet can handle multiple requests concurrently and these requests can be
synchronized to support systems allowing collaboration between people
...
List various classes of Servlet API
...

GenericServlet
ServletInputStream
ServletOutputStream
Cookies
HttpServlet
HttpSessionBindingEvent
Httputil

4
...
What are the disadvantages of JSP?
1
...
Java code required
3
...
Difficult looping in JSP
5
...
List various directives of JSP
...

1
...
The include directive
3
...
List and explain different types of JDBC drivers
...
JDBC-ODBC Driver
2
...
Java Network Protocol Driver
4
...
Write the purpose of the following JDBC classes

10

i
...
ResultSet
PreparedStatement

iii
...
Connection

v
...

ResultSet : is a database result set generated from currently executed SQL statement
...
The objective is to pass to the database the SQL command for
execution and to retrieve output results from the database in th eform of Resultset
...
Can be used to retrieve
information regarding the tables in th edatabase to which connection is opened
...
This object
can then be executed multiple times much more efficiently than preparing and issuing the
same statement each time it is needed
...
Attempt any two of the following:
a
...
Explain in short
...
What is Facelet? Write the features of Facelet?
Facelets is commonly used term to refer to JavaServer Faces View Defination
Framework which is page declaration language developed for use with Java server Faces
technology
...
0 allows declaration
of UI components in different presentation technologies
...

Facelet is built specifically for JavServer Faces
...

Facelets is a powerful but lightweight page declaration language that is used to build
JavaServer Faces views using HTML style templates and to build component trees
...

 Templatting and Composite Components through Faceltes
...

 Bookmarkability to generate hyperlinks based on component properties at render
time
...

 Resource registration and relocation using annotations
...

 Support for Bean Validation
...

 Support for Ajax Integration
...
Write the benefits of EJB
...
Write the code that define stateless bean which convert an amount from one
currency to other
...
Attempt any two of the following:
a
...
With suitable diagram explain the architecture of hibernate
...
What is Value stack? Explain
...

The value stack is a set of several objects which keeps the following objects in the
provided order:
Temporary Objects
There are various temporary objects which are created during execution of a page
...

The Model Object
If you are using model objects in your struts application, the current model object is
placed before the action on the value stack
The Action Object
This will be the current action object which is being executed
...
What is the purpose of Hibernate mapping file?
Write the Hibernate mapping file that maps the application to the table GuestBook
of GuestBook database
...

7
...
Write AWT based Java program that demonstrate the use of checkbox and
radiobuttons
...
Write a Java program using swing components to divide the window into two
horizontal windows
...
Textbox
is used to accept a number from user
...
What is the purpose of WEB-INF file? Explain
...
The root of this
hierarchy serves as the document root for files that are part of the application
...
This
directory contains all things related to the application that aren’t in the document root of
the application
...
No file contained in the WEB-INF directory may be served directly to a
client by the container
...
Hence, if the
Application Developer needs access, from servlet code, to application specific
configuration information that he does not wish to be exposed directly to the Web client,
he may place it under this directory
...
The contents of the WEB-INF
directory are:
• The /WEB-INF/web
...

• The /WEB-INF/classes/ directory for servlet and utility classes
...

• The /WEB-INF/lib/*
...
These files contain servlets,
beans, and other utility classes useful to the Web application
...

The Web application class loader must load classes from the WEB-INF/ classes directory
first, and then from library JARs in the WEB-INF/lib directory
...
SRV
...
5
...
Explain the Request and Response implicit objects of JSP
...
servlet
...
HttpServletRequest object
...

The request object provides methods to get HTTP header information including form
data, cookies, HTTP methods etc
...
These methods are available with HttpServletRequest object which represents
client request to webserver
...
servlet
...
HttpServletResponse object
...

The response object also defines the interfaces that deal with creating new HTTP
headers
...

methods are available with HttpServletResponse object are:
addCookie(), encodeURL(), sendRedirect(), setStatus()
...
List and explain different types of Enterprise Beans
...
Session Beans
a
...
Stateful Session Bean
c
...
Message Driven Beans
f
...

Action is heart and soul of the Struts 2 framework
...

It is associated with HTTP request from user
...
This Action class holds the code spec that helps sreve the user request
Actions are used to :
 Encapulate the actuat work to be done for a given request
...

 Assist the framework in choosing theresponse that has to be the user i
...
view
Title: Advance java notes with Q & A formate
Description: Java Advanced Imaging (JAI) is a Java platform extension API that provides a set of object-oriented interfaces that support a simple, high-level programming model