Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

1.A.Explain in brif the use of JInternal frame


-> JInternal frame - A JInternal frame is visible area of container..it is placed in
Jinternal Frame a top level swing component that has a content pane.
Use of JInternalFrame You must set the size of the internal frame
You should set the location of the internal frame
Dialogs that are internal frames should be implemented using JOption or
JInternal Frame.. To create a simple dialog,you can use JOptionPane
method.
Internal frame fire internal frame events,not windows event.
B.write a short note on JOptionpane.
-> JOptionPane Contains classes used for a graphical user interface (GUI)
Facilitates data entry and data output.
JOptionPane contains methods that display a dialog box.
The JOptionPane class provides static methods to display each type of dialog box.
ConstructorJOptionPane()-Creates a JOptionPane with a test message.

Method
showInputDialog

Description
prompt for input

showMessageDialog

display a message

showConfirmDialog

ask a yes/no question

JOptionPane

Allows you to create a dialog box

Display information

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

D.explain any three text component in swings.


-> 1) JTextField- text controls can display and edit only one line of text. Use them
to get a small amount of textual information from the user and take some action
after the text entry is complete.
ConstructorJTextField()-Constructs a new TextField.
MethodaddActionListener(ActionListener l)-Adds the specified action listener to receive
action events from this textfield.
2) JTextArea- JTextArea can display and edit multiple lines of text. Although a text
area can display text in any font, all of the text is in the same font.
ConstructorJTextArea()-Constructs a new TextArea.
MethodgetColumns()-Returns the number of columns in the TextArea.
3) JEditorPane- A styled text component can display and edit text using more than
one font. Some styled text components allow embedded images and even
embedded components.
ConstructorJEditorPane()-Creates a new JEditorPane.
MethodgetContentType()-Gets the type of content that this editor is currently set to deal
with.

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

E.Explain JScrollBar and identify the difference between JscrollBar and JscrollPane.
-> JScrollBar-The class JScrollBar is an implementation of scrollbar.
ConstructorJScrollBar-Creates a vertical scrollbar with the following initial values:
JScrollBar(int orientation)- Creates a scrollbar with the specified orientation and
the following initial values:
MethodcreateHorizontalScrollBar()-Returns a JScrollPane.ScrollBar by default.
createVerticalScrollBar()-Returns a JScrollPane.ScrollBar by default.

JscrollBar
Scrollbar is a component
scrollbar cannot have a scrollpane.

JscrollPane.
Scrollpane is a container
ScrollPane can have a scrollbar

f.Write a program in java that reads an integer n in text


fields.create a JButton sum. On click of the JbUTTON
1+2+3+.+n should be calculated and displayed in
another textfield.

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

2.A.Explain JFileChooser class with one method in it.


-> 1)The class JFileChooser is a component which provides a simple mechanism
for the user to choose a file.
2)You can add a file chooser directly to your application .
3)The JFileChooser class provides three methods that display file chooser dialogs:
showOpenDialog with an "Open" approve button,
showSaveDialog with a "Save" approve button, and
showDialog with a user-defined approve button.
ConstructorJFileChooser()-Constructs a JFileChooser pointing to the user's default directory.
JFileChooser(File currentDirectory)Constructs JFileChooser using the given File as
the path.
MethodJFileChooser(): Constructor that creates a new file chooser that starts at the home
directory of the user.

B.Explain any three constructors of the JTree Class.


-> A JTree is components that display information in hierarchical format.
Constructors1)JTree(Object Ob[])-Each element of the array object is childnode.
2) JTree(Treenode tn)- Treenode tn is the root of the tree.
3) JTree(Vector v)- Elements of vector v is the childnode.

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

c.Write a java print services API.


-> The Java Print Service API allows printing on all Java platforms including those
requiring a small footprint, such as a Java ME profile, but also supports
the java.awt.print.PrinterJob API. The Java Print Service API includes an
extensible print attribute set based on the standard attributes specified in the
Internet Printing Protocol (IPP) 1.1 from the IETF. With the attributes, client and
server applications can discover and select printers that have the capabilities
specified by the attributes. In addition to the included StreamPrintService, which
allows applications to transcode data to different formats, third parties can
dynamically install their own print services through the Service Provider
Interface.

API SpecificationThe Java Print Service API consists of these four packages:
javax.print:
Provides the principal classes and interfaces for the Java Print Service API.
javax.print.attribute:
Provides classes and interfaces that describe the types of Java Print Service
attributes and how they can be collected into attribute sets.
javax.print.attribute.standard:
Contains classes defining specific printing attributes.
javax.print.event:
Contains event classes and listener interfaces for monitoring print services and
the progress of a specific print job.

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

D.How to synchronize thread ? Explain with Example.


-> When we start two or more threads within a program, there may be a
situation when multiple threads try to access the same resource and finally they
can produce unforeseen result due to concurrency issues. For example, if
multiple threads try to write within a same file then they may corrupt the data
because one of the threads can override data or while one thread is opening the
same file at the same time another thread might be closing the same file.
So there is a need to synchronize the action of multiple threads and make sure
that only one thread can access the resource at a given point in time. This is
implemented using a concept called monitors. Each object in Java is associated
with a monitor, which a thread can lock or unlock. Only one thread at a time may
hold a lock on a monitor.

E.What Are the method involved in communication between threads.


-> In a multithreaded Java process , it is often needed a communication between
different threads. This inter-thread communication is performing
using wait(),notify() , and notifyAll() methods of Java.Lang.Object class .
Method-

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

wait() tells calling thread to give up monitor and go to sleep until some
other thread enters the same monitor and call notify.

notify() wakes up a thread that called wait() on same object.

notifyAll() wakes up all the thread that called wait() on same object.

3.A.write a brif account of the drivers of JDBC.


-> JDBC Driver is a software component that enables java application to interact
with the database.There are 3 types of JDBC drivers:
1) JDBC-ODBC bridge driver- The JDBC-ODBC bridge driver uses ODBC driver to
connect to the database. The JDBC-ODBC bridge driver converts JDBC method calls
into the ODBC function calls.
2) Native-API driver- The Native API driver uses the client-side libraries of the
database. The driver converts JDBC method calls into native calls of the database
API.
3) Thin driver- The thin driver converts JDBC calls directly into the vendor-specific
database protocol. It is fully written in Java language.
B.explain the importance of following methods.

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

->1) Class.forName()-The most common approach to register a driver is to use


Java'sClass.forName() method, to dynamically load the driver's class file into memory, which
automatically registers it.

DriverManager.getConnection() -After you've loaded the driver, you can establish


connection using the DriverManager.getConnection() method. For easy reference,
let me list the three overloaded DriverManager.getConnection() methods

getConnection(String url)

getConnection(String url, Properties prop)

getConnection(String url, String user, String password)

Here each form requires a database URL. A database URL is an address that
points to your database.
2)Conection.createStatement()-

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

D.Write a short note on stored procedures.


-> In a database management system, a stored procedure is a set of SQL statements with
an assigned name that's stored in the database in compiled form.
The use of stored procedures can be helpful in controlling access to data (end-users may
enter or change data but do not write procedures), preserving data integrity (information is
entered in a consistent manner), and improving productivity (statements in a stored
procedure only need to be written one time).

E.Explain any three important methods of ResultSetMetaData.


->The metadata means data about data i.e. we can get further information from the data.
methods of ResultSetMetaData1)getColumnCount()-it returns the total number of columns in the ResultSet object.
2)getColumnName(int index)- it returns the column name of the specified column index.
3)getColumnTypeName(int index)- it returns the column type name for the specified index.

4.A.write a short note on Socket Direct Protocol.


-> The Sockets Direct Protocol (SDP) provides access to high performance
network connections, such as that provided by InfiniBand. This trail shows how to
enable SDP, which Java APIs are involved, and explains how it works.
SDP support is essentially a TCP by pass technology.
When SDP is enabled and an application attempts to open a TCP connection, the
TCP mechanism is bypassed and communication goes directly to the IB network.

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

SDP support is disabled by default. The steps to enable SDP support are:

Create an SDP configuration file.

Set the system property that specifies the location of the configuration file.

B. Explain socket class in details.


-> 1) A socket is one endpoint of a two-way communication link between two programs
running on the network.
2) Sockets allow communication between two different processes on the same or different
machines
3)the Java platforms supports two types of sockets:TCP/IP and Datagram.
4)Using socket class,write a program to show how a client sends and receive data from the
server through the socket.
ConstructorSocket()-Creates an unconnected socket, with the system-default type of
SocketImpl.
Socket(InetAddress address, int port)-Creates a stream socket and connects it to
the specified port number at the specified IP address.
Method-

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

close()-Closes this socket.


connect(SocketAddress endpoint)-Connects this socket to the server.
DataGramClient
Practical code:
import java.net.*;
import java.io.*;
class DataGramClient
{
public static DatagramSocket ds;
public static byte buffer[]=new byte[1024];
public static int cp=1510,sp=1511;
public static void main(String args[])throws Exception
{
ds=new DatagramSocket(cp);
System.out.print("Client is waiting for server to send data...");
while(true)
{
DatagramPacket dp=new DatagramPacket(buffer,buffer.length);
ds.receive(dp);
String str=new String(dp.getData(),0,dp.getLength());
if(dp.getLength()==0)
break;
System.out.println(str);
}
}
}

D.Explain the following methods from URL class.


->1)getHost- Return the host of URL.
2)getPort-return the port of URL
3)getProtocol-return the protocol of URL.
4)getFile-return the file name of URL.
5)getRef-return the reference part of url.
5.A.Explain the JDialog class With Multiple Example.
-> the main class for creating a dialog window. You can use this class to create a
custom dialog, or invoke the many class methods in JOptionPane to create a
variety of standard dialogs.

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

Every Dialog is dependent on a frame,when that frame is destroyed,so are


dependent dialogs.
When a frame is iconfield,its dependent dialogs disappear from screen .
When frame is deiconfined,its dependent dialogs returns to the screen.
he JDialog component contains a JRootPane as its only child.
The contentPane should be the parent of any children of the JDialog. As a
convenience add and its variants.
ConstructorJDialog()-Creates a modeless dialog without a title and without a
specified Frame owner.
JDialog(Dialog owner)-Creates a modeless dialog with the specified Dialog as its
owner and an empty title.
MethodcreateRootPane()-Called by the constructor methods to create the
default rootPane.
getContentPane()-Returns the contentPane object for this dialog.

Exampleimport javax.swing.*;
import java.awt.*;
class JDialogExample extends JFrame
{
JDialog d1;

public JDialogExample()
{
createAndShowGUI();
}

private void createAndShowGUI()


{
setTitle("JDialog Example");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

// Must be called before creating JDialog for


// the desired effect
JDialog.setDefaultLookAndFeelDecorated(true);

// A perfect constructor, mostly used.


// A dialog with current frame as parent
// a given title, and modal
d1=new JDialog(this,"This is title",true);

// Set size
d1.setSize(400,400);

// Set some layout


d1.setLayout(new FlowLayout());

d1.add(new JButton("Button"));
d1.add(new JLabel("Label"));
d1.add(new JTextField(20));

setSize(400,400);
setVisible(true);

// Like JFrame, JDialog isn't visible, you'll


// have to make it visible
// Remember to show JDialog after its parent is
// shown so that its parent is visible
d1.setVisible(true);
}

public static void main(String args[])


{

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

new JDialogExample();
}
}

B.Explain any Three Method of Timer Class.


-> The java.util.Timer class provides facility for threads to schedule tasks for
future execution in a background thread.

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

This class is thread-safe i.e multiple threads can share a single Timer
object without the need for external synchronization.

This class schedules tasks for one-time execution, or for repeated


execution at regular intervals.

All constructors start a timer thread.

Method1)void cancel()-This method terminates this timer, discarding any currently


scheduled tasks.
2)void schedule(TimerTask task, Date time)-This method schedules the specified
task for execution at the specified time.
3)void schedule(TimerTask task, long delay)-This method schedules the specified
task for execution after the specified delay.

C.Write a note on JDBC exception classes.


->1)java.sql.SQLException extends the java.lang.Exception class
2)java.sql.SQLException-is core JDBC exception class that provides information
about database access errors.
3)java.sql.BatchUpdateException-a batchUpdateException provides the update
counts for all commands.
4)java.sql.SQLWarning-provides information about database access warnings.
Methods-

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

1)getErrorCode( )- Gets the error number associated with the exception.


2) getNextException( )- Gets the next Exception object in the exception chain.

D.What are the step involved in creating and running RMI programs.
->

RMI

application

and Server program.

can

be

divided

A Server program

into

creates

two
some

part,Client program
remote

object,

A Clientprogram make request for remote objects on server and invoke method
on them. Stub and Skeleton are two important object used for communication
with remote object.
Steps for Creating a RMI program

Define a remote interface.

SEM 5

ADVANCE JAVA

Implementing remote interface.

create and start remote application

create and start client application

QUESTION PAPAR 2014

Steps for running a RMI programYou are running both the Server and Client programs on the same machine:
set path=C:\j2sdk1.4.0-rc\bin
Step 1: compile all the java programs
1) javac addserverintf.java
2) javac addserverimpl.java
3) javac addclient.java
4) javac addserver.java
Step 2: Generate stubs and skeleton
> rmic addserverimpl
Step 3: start the rmiregistry
> start rmiregistry [A new blank window will be generated]
Step 4: In a new window
> java addserver
Step 5: In another window
> java addclient 127.0.0.1 4 5

F.Write a short note on RMI architecture.


-> RMi is a server side technology which is used Commuinication beteween sever
& many client it consist of four layers

SEM 5

ADVANCE JAVA

QUESTION PAPAR 2014

1. Application layer which is used contains the actual object definition


2. proxy layer which contain stub class ,it is userful part of rmi stub class consist
of interfaces or abstract classes it is put on to the client machine and it
provide communication beteween server & client
3. Remote Reference Layer : gets the stream of bytes from thetransperent layer
and sends it to the proxy layer
4. Transportation layer : Responsible for handling theactual machine-tomachinecommunication.

You might also like