Download downloading

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
ADVANCE JAVA PROGRAMMING
SNS COLLEGE OF technology
COIMBATORE – 35
DEPARTMENT OF COMPUTER SIENCE AND ENGINEERING (UG & PG)
Third Year Computer Science and Engineering, 6th Semester
2 Marks Question and Answer
Subject Code & Name:CS316 & ADVANCE JAVA PROGRAMMING
Prepared by: K.Maheswari AP/CSE, S.Sathish Kumar,AP/CSE, V.Praveena,AP/CSE
UNIT-I
1. 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 instance, into the
computer; and output streams that direct data toward output devices such as the computer
screen or a file.
2. What are Byte streams?
Byte streams provide a convenient means for handling input and output of bytes.
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 internationalized.
4.List some Byte Stream supported classes.
 BufferedInputStream
 BufferedOutputStream
 ByteArrayInputStream
 ByteArrayOutputStream
 DataInputStream
 DataOutputStream
5. List some Character Stream supported classes.
 BufferedReader
 BufferedWriter
 CharArrayReader
 CharArrayWriter
 FileReader
 FileWriter
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)
SNSCT – Department of Compute Science and Engineering
Page 1
ADVANCE JAVA PROGRAMMING
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 or 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 requires 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:
SequenceInputStream(InputStream 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.This 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 character via the keyboard, selecting an item in a list and clicking the mouse.
12. What is an Event Listener?
SNSCT – Department of Compute Science and Engineering
Page 2
ADVANCE JAVA PROGRAMMING
A Listener is an object that is notified when an event occurs. Only the types of
events, which are registered 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 doubleclicked, or a menu item is selected.
You 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. Define 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 is 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.
SNSCT – Department of Compute Science and Engineering
Page 3
ADVANCE JAVA PROGRAMMING
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 Thread.
final void setPriority(int level)
20.What is the use of Layout Managers in Swing?
The Layout Managers are used to place the components in a predefined manner relative 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.
21.List some Layout Managers supported by Swing.
The most common Layout Managers supported by Swing are




Box Layout
Grid Layout
GridBag Layout
Border Layout
22.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, int numColumns)
JTable (Object [] [] rowData, Object [] columnNames)
JTable (TableModel dm)
23.
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)
SNSCT – Department of Compute Science and Engineering
Page 4
ADVANCE JAVA PROGRAMMING
UNIT-II
1. 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()
ArrayList(Collection c)
ArrayList(int capacity)
2.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 when storing large amounts
of sorted information.
The constructors are:
TreeSet()
TreeSet(Collection c)
TreeSet(Comparator comp)
TreeSet(SortedSet ss)
3.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.
4.What are Comparators?
Comparator defines, in which 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.
5.Write note on Collection Algorithms.
The Collections framework 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
an attempt is made to compare incompatible types, or an UnSupportedOperationException,
which occurs when an attempt is made to modify an unmodifiable collection.
SNSCT – Department of Compute Science and Engineering
Page 5
ADVANCE JAVA PROGRAMMING
6.Write note on Collection class “Stack”.
Stack is a subclass of vector that implements a standard last-in, first-out 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.
7.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.
SNSCT – Department of Compute Science and Engineering
Page 6
ADVANCE JAVA PROGRAMMING
UNIT-III
1. 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. This is an
important feature, because it allows you to build distributed applications.
2. 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. Remote 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.
3.
What do you meant 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.
4. What is object serialization?
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 deserialization.
5.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 simply used to
indicate that a class may be serialized. If a class is serializable, all of its subclasses are also
serializable.
5. What is distributed garbage collection?
Freeing up the memory space in the server is called Distributed garbage collection.The
java.rimi.dgc package defines the interfaces and classes to implement the distributed
garbage collection algorithm.
6. Write note on Interface Definition Language?
IDL is part of a language neutral strategy provided by CORBA. Every language has a
mapping 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++.
7. What is CORBA?
The CORBA is essentially a remote method invocation facility. The ORB is language –
neutral, meaning you can create objects in any language and use the ORB to invoke
methods in those objects.
SNSCT – Department of Compute Science and Engineering
Page 7
ADVANCE JAVA PROGRAMMING
8. 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);
9. What are JAR files?
A JAR file allows you to efficiently deploy a set of classes and their associated resources.
Elements in a JAR file are compressed, which makes downloading a JAR file much faster
than separately downloading several uncompressed files.
UNIT-IV
1.What are Servlets?
Servlets are small programs that execute on the server side of a Web connection.
Servlets dynamically extend the functionality of a Web server.
2. What are the advantages of Servelets over CGI?
o Servlets are platform-independent, because they are written in Java.
o 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.
o
The Java Security Manager on the server enforces a set of restrictions to
protect the resources on a server machine.
3. Write note on the Life Cycle of a Servlet.
Three methods are central to the life cycle of a servlet : init(), service(), destroy().
init() is invoked only when the servlet is first loaded into memory.
service() method is called for each HTTP request.
destroy() method is called when the servlet is uloaded from the memeory.
4. Write note on SingleThreadModel interface.
The SingleThreadModel interface is used to indicate 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.
SNSCT – Department of Compute Science and Engineering
Page 8
ADVANCE JAVA PROGRAMMING
5. 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 server.Session
Tracking helps to achieve this.
SNSCT – Department of Compute Science and Engineering
Page 9
ADVANCE JAVA PROGRAMMING
UNIT-V
1. What is a Java Bean?
A Java Bean is a software component that has been designed to be reusable in a variety of
different environments. There is no restriction on the capacity of a Bean.
2. List some advantages of Java Beans.
a. A Bean obtains all the benefits of Java’s “Write – Once, run-anywhere”
paradigm.
b. The configuration settings of a Bean can be saved in persistent storage and
restored at a later time.
c. A Bean may register to receive events from other objects and can generate
events that are sent to other objects.
3. What are JAR files?
A JAR file allows you to efficiently deploy a set of classes and their associated resources.
Elements in a JAR file are compressed, which makes downloading a JAR file much faster
than separately downloading several uncompressed files.
4. Write note on manifest file in Java Beans.
Manifest file is used to indicate which of the components in a JAR file are Java Beans.
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”.
5. what is Introspection?
Introspection is the process of analyzing a Bean to determine its capabilities. The java .
beans . Introspector class, does all the pattern analysis to expose the properties, methods
and events that a component has.
6. 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);
7. What are the design patterns for Boolean properties in a Bean?
A Boolean property has a value of 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 value);
8. What do you meant by constrained properties in a Bean?
A Bean that has a constrained property generates an event when an attempt is made to
change its value. The event is of type PropertyChangeEvent.
SNSCT – Department of Compute Science and Engineering
Page 10
ADVANCE JAVA PROGRAMMING
9. 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.
10. 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 is of type PropertyChangeEvent and is sent to objects that previously registered an
interest in receiving such notifications.
11. What is Bean Customizer?
A Bean Customizer is nothing but a wizard that can be used to provide values to a bean. A
Customizer can 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.
SNSCT – Department of Compute Science and Engineering
Page 11