CA331-Advanced Java Programming

kitewormsΛογισμικό & κατασκευή λογ/κού

3 Νοε 2013 (πριν από 4 χρόνια και 8 μήνες)

96 εμφανίσεις

Advanced Java Programming

2 marks questions with answers


What is Java Streaming?

Java streaming is nothing more than a flow of data. There are input streams
that direct data from the outside world from the keyboard, or a file for ins
tance, into
the computer; and output streams that direct data toward output devices such as the
computer screen or a file.


What are Byte streams?

Byte streams provide a convenient means for handling input and output of
s. Byte streams are used for example when reading or writing binary data.

3.What are Character streams?

Character streams, provide a convenient means for handling input and output
of characters. They use Unicode, and therefore, can be intern

4.List some Byte Stream supported classes.







5. List some Character Stream supported classes.







6. Write note on FileInputStream class.

The FileInputStream class creates an InputStream that you can use to read
bytes from a file. Its two most common constructors are

FileInputStream(String filepath)

FileInputStream(File fileobj)

7. Write note on FileOutputStream class.

FileOutputStream creates an OutputStream that you can use to write bytes
to a file. Its
most commonly used constructors are

FileOutputStream(String filepath)

FileOutputStream(File fileobj)

FileOutputStream(String filepath, Boolean append)

They can throw an IOException o
r a SecurityException.

8. What is the use of the class “ByteArrayInputStream”?

ByteArrayInputStream is an implementation of an input stream that uses a
byte array as the source. This class has two constructors, each of which req
uires a byte
array to provide the data source:

ByteArrayInputStream(byte array[])

ByteArrayInputStream(byte array[], int start, int numbytes)

9. Write note on the class “SequenceInputStream”.

The SequenceInputStream class allows you to concatenate multiple
InputStreams. A SequenceInputStream constructor uses either a pair of InputStreams or
an Enumeration of InputStreams as its argument:

putStream first, InputStream second)

SequenceInputStream(Enumeration streamEnum)

10. Write note on the class “PushbackReader”.

The PushbackReader class allows one or more characters to be returned to the
input stream.Th
is allows you to look ahead in the input stream. Its constructors are

PushbackReader(Reader inputstream)

PushbackReader(Reader inputstream, int bufsize)

11.What is an Event?

An event is an

object that describes a state change in a source. It can be
generated as a consequence of a person interacting with the elements in a graphical user
interface. Some of the activities that cause events to be generated are pressing a button,
entering a char
acter via the keyboard, selecting an item in a list and clicking the mouse.

12. What is an Event Listener?

A Listener is an object that is notified when an event occurs. Only the types
of events, which are registe
red with an event listener will be received by that listener.

13.When does an ActionEvent generate?

An ActionEvent is generated when a button is pressed, a list
item is double
clicked, or a menu item is selected.

u can obtain the command name for the invoking ActionEvent object by
using the getActionMethod() method.

String getActionCommand()

14.When is Component Event generated?

A ComponentEvent is generated when the size, position, or visibility of a
component is changed.

The getComponent() method of ComponentEvent returns the component that
generated the event.

15.What is an Adapter class?

An adapter class provides an empty implementation of all methods in an event
listener interface. Adapter classes are useful when you want to receive and process only
some of the events that are handled by a particular event listener interface.

16. Defin
e Multithread Programming.

A multithreaded program contains two or more parts that can run concurrently.
Each part of such program is called a thread, and each thread defines a separate path of
execution. Thus, multithreading is a specialized
form of multitasking.

17. What is Synchronization?

When two or more threads need access to a shared resource, they need some
way to ensure that the resource will be used by only one thread at a time. The process by
which this is achieved i
s called synchronization.

The general form of the synchronized statement is

synchronized (object){

// statements to be synchronized


18. In multithreading,

When does a deadlock situation occur?

Deadlock situation occurs, when two threads have a circular dependency on
a pair of synchronized objects.

19. What is the need of Thread Priorities?

Thread priorities are used by
the thread scheduler to decide when each thread be
allowed to run. Higher
priority threads get more CPU time than lower
priority threads.

To set a thread’s priority, use the setPriority() method, which is a member of

final void setPriority(int level)

20.Write note on ArrayList collection class.

The ArrayList class extends AbstractList and implements the List interface.
ArrayList supports dynamic arrays that can grow
as needed. ArrayList can dynamically
increase or decrease in size.

ArrayList has the constructors:


ArrayList(Collection c)

ArrayList(int capacity)

21.Write note on TreeSet collection class.

In TreeSet, objects are stored in sorted, ascending order. Access and retrieval
times are quite fast, which makes TreeSet an excellent choice wh
en storing large amounts
of sorted information.

The constructors are:


TreeSet(Collection c)

TreeSet(Comparator comp)

TreeSet(SortedSet ss)

2. What are Maps?

A map is an object that stores associations between keys and values or key/value
pairs. Given a key, you can find its value .Both keys and values are objects.

23.What are Comparators?

Comparator defines, in whic
h order the elements in TreeSet or TreeMap has to be
ordered. If you want to order elements a different way, then specify a Comparator object
when you construct the set or map.

24. Write note on Collection Algorithms.

The Collections fram
ework defines several algorithms that can be applied to
collections and maps. These algorithms are defined as static methods within the
collections class.

Several of the methods can throw a ClassCastException, which occurs
when a
n attempt is made to compare incompatible types, or an
UnSupportedOperationException, which occurs when an attempt is made to modify an
unmodifiable collection.

25. Write note on Collection class “Stack”.

Stack is a subclass of vecto
r that implements a standard last
in, first
stack. Stack only defines the default constructor, which creates empty stack. Stack
includes all the methods defined by Vector, and adds several of its own.

26. What is the need for creating a CustomSocket?

The real goal of using a CustomSocket with RMI is to provide some
additional functionality such as compression or security. Since the socket itself doesn’t
do much good without a stream that provides the additional functionality, you
must first
define a stream for your purposes.

27.What is Remote Method Invocation (RMI)?

Remote Method Invocation (RMI) allows a Java Object that executes on one
machine to invoke a method of a Java Object that executes on another machine. Th
is is
an important feature, because it allows you to build distributed applications.


What are stubs and skeletons in RMI?

A stub is Java Object that resides on the client machine. Its function is to present
the same interfaces as the remote server. Rem
ote method calls initiated by the
client are actually directed to the stub.

A skeleton is a Java Object that resides on the server machine. It receives request,
performs deserialization, and invokes the appropriate code on the server.

29. What do you m
eant by Activation in RMI?

Activation in RMI has the capability to remotely activate an object.

The activator will check the status of the remote object and perform what ever
initialization is necessary to get it running again.


What is object serializ

Serialization is the process of writing the state of an object to a byte stream. This is
useful when you want to save the state of your program to a persistent storage area,
such as a file. At a later time, you may restore these objects by using
the process of


Write note on the interface Serializable?

An object that implements the serializable interface can be saved and restored by the
serialization facilities. The Serializable interface defines no members. It is sim
used to indicate that a class may be serialized. If a class is serializable, all of its
subclasses are also serializable.


What is distributed garbage collection?

Freeing up the memory space in the server is called Distributed garbage collection.

e java.rimi.dgc package defines the interfaces and classes to implement the
distributed garbage collection algorithm.


Write note on Interface Definition Language?

IDL is part of a language neutral strategy provided by CORBA. Every language has a

to and from IDL. These IDL interfaces represent a method calling API that
can be used to access your object from other languages, such as c++.


What is CORBA?

The CORBA is essentially a remote method invocation facility. The ORB is

neutral, m
eaning you can create objects in any language and use the ORB
to invoke methods in those objects.


Write note on interfaces in IDL.

An IDL interface contains a set of method definitions, just like a Java interface. Like
Java interfaces, an IDL interface
may inherit from other interfaces.

Sample IDL interface is

interface MyInterface {

void myMethod (in long param1);



What is a Java Bean?

A Java Bean is a software component that has been designed to be reusable in a
variety of different environm
ents. There is no restriction on the capacity of a Bean.


List some advantages of Java Beans.

A Bean obtains all the benefits of Java’s “Write

Once, run

The configuration settings of a Bean can be saved in persistent storage and
tored at a later time.

A Bean may register to receive events from other objects and can generate
events that are sent to other objects.


What are JAR files?

A JAR file allows you to efficiently deploy a set of classes and their associated
resources. Elem
ents in a JAR file are compressed, which makes downloading a JAR
file much faster than separately downloading several uncompressed files.


Write note on manifest file in Java Beans.

Manifest file is used to indicate which of the components in a JAR file a
re Java

A manifest file may reference several . class file . If a .class file is a Java Bean,
its entry must be immediately followed by the line “Java Bean : True”.


what is Introspection?

Introspection is the process of analyzing a Bean to deter
mine its capabilities. The
java . beans . Introspector class, does all the pattern analysis to expose the properties,
methods and events that a component has.


Write the design patterns for simple properties in Bean.

A simple property has a single value.

It can be identified by the following design
patterns, where N is the name of the property and T is its type.

public T get N( );

public void set N(T arg);


What are the design patterns for Boolean properties in a Bean?

A Boolean property has a value o
f true or false. It can be identified by the following
design, patterns, where N is the name of the property ;

public boolean is N( );

public boolean get N();

public void setN(boolean


What do you meant by constrained properties in a Bean?


Bean that has a constrained property generates an event when an attempt is made to
change its value. The event is of type PropertyChangeEvent.


Define the term persistence in a Bean.

Persistence is the ability to save a Bean to nonvolatile storage and
retrieve it at a later
time. The information that is particularly important are the configuration settings.


What do you meant by Bound Properties in a Bean?

A Bean that has a bound property generates an event when the property is changed.
The event i
s of type PropertyChangeEvent and is sent to objects that previously
registered an interest in receiving such notifications.


What is Bean Customizer?

A Bean Customizer is nothing but a wizard that can be used to provide values to a
bean. A Customizer ca
n be created in the same way as any other Java program and
can then be attached to the bean with the help of BeanInfo file.


What is the use of Layout Managers in Swing?

The Layout Managers are used to place the components in a predefined manner
to each other. The layout manager puts the components in a queue and
arranges them one after the other rather then placing the components according to the
coordinates. This helps in achieving platform independence.


List some Layout Managers supported b
y Swing.

The most common Layout Managers supported by Swing are

Box Layout

Grid Layout

GridBag Layout

Border Layout


How we can include tables in Swing applications?

Swing provides a structure called the JTable which is capable of displaying the data
in a tabular format. For creating a JTable you need to create an array that contains the
column names and another array that contains the row and column contents. The
constructors to create a JTable are given below :

JTable ( )

JTable (int numRows, in
t numColumns)

JTable (Object [] [] rowData, Object [] columnNames)

JTable (TableModel dm)


Write note on Trees in Swings.

A tree is a component that presents a hierarchical view of data. A user has he ability
to expand or collapse individual subtrees
in this display. Trees are implemented in
Swing by the JTree class, which extends JComponent. Some of its constructors are :

JTree (Hastable ht)

JTree (Object obj[])

JTree (TreeNode tn)

JTree (Vector v)

51.What are Servlets?

Servlets are smal
l programs that execute on the server side of a Web connection.

Servlets dynamically extend the functionality of a Web server.

52. What are the advantages of Servelets over CGI?


Servlets are platform
independent, because they are written in


Performance is significantly better. Servlets execute within the
address space of a Web server. Creating a separate process to
handle each client request isn’t necessary.


The Java Security Manager on the server enforces a set of
restrictions to protect th
e resources on a server machine.

53. Write note on the Life Cycle of a Servlet.

Three methods are central to the life cycle of a servlet : init(), service(),

init() is invoked only when the servlet is first loaded into m

service() method is called for each HTTP request.

destroy() method is called when the servlet is uloaded from the memeory.

54. Write note on SingleThreadModel interface.

The SingleThreadModel interface is used to indi
cate that only a single thread
should execute the service () method of a servlet. It defines no constants and declares no
methods. If a servlet implements this interface, the server creates several instances of it.

55. What is Session Tracking?

HTTP is a stateless protocol, which means that each request is independent of the
previous one. However, in some applications, it is necessary to save state information, so
that information can be collected from several interactions between browser and a

Session Tracking helps to achieve this.