Monday, October 15, 2007



FREQUENTLY ASKED QUESTIONS (JAVA) IN INTERVIEWS




51)How do you set security in applets?

Ans: using setSecurityManager() method


52) What is an event and what are the models available for event handling?

Ans: An event is an event object that describes a state of change in a source. In other words, event occurs when an

action is generated, like pressing button, clicking mouse, selecting a list, etc.

There are two types of models for handling events and they are:

a) event-inheritance model and b) event-delegation model


53) What are the advantages of the model over the event-inheritance model?

Ans: The event-delegation model has two advantages over the event-inheritance model. They are:

a)It enables event handling by objects other than the ones that generate the events. This allows a clean separation between a component’s design and its use.

b)It performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to be repeatedly process unhandled events as is the case of the event-inheritance.


54)What is source and listener ?

Ans: source : A source is an object that generates an event. This occurs when the internal state of that object changes in some way.

listener : A listener is an object that is notified when an event occurs. It has two major requirements. First, it must have been registered with one or more sources to receive notifications about specific types of events. Second, it must implement methods to receive and process these notifications.


55) What is adapter class?

Ans: 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. You can define a new class to act listener by extending one of the adapter classes and implementing only those events in which you are interested.For example, the MouseMotionAdapter class has two methods, mouseDragged( )and mouseMoved(). The

signatures of these empty are exactly as defined in the MouseMotionListener interface. If you are interested in only mouse drag events, then you could simply extend MouseMotionAdapter and implement mouseDragged( ) .


56)What is meant by controls and what are different types of controls in AWT?

Ans: Controls are components that allow a user to interact with your application and the AWT supports the following types of controls:Labels, Push Buttons, Check Boxes, Choice Lists, Lists, Scrollbars, Text Components.These controls are subclasses of Component.


57) What is the difference between choice and list?

Ans: A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices and only one item may be selected from a choice.A List may be displayed in such a way that several list items are visible and it supports the selection of one or more list items.


58) What is the difference between scrollbar and scrollpane?

Ans: A Scrollbar is a Component, but not a Container whereas Scrollpane is a Conatiner and handles its own events and perform its own scrolling.


59) What is a layout manager and what are different types of layout managers available in java.awt?

Ans: A layout manager is an object that is used to organize components in a container. The different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBagLayout.


60) How are the elements of different layouts organized?

Ans: FlowLayout: The elements of a FlowLayout are organized in a top to bottom, left to right fashion. BorderLayout: The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container.

CardLayout: The elements of a CardLayout are stacked, on top of the other, like a deck of cards.GridLayout: The elements of a GridLayout are of equal size and are laid out using the square of a grid. GridBagLayout: The elements of a GridBagLayout are organized according to a grid. However, the elements are of different size and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.


61) Which containers use a Border layout as their default layout?

Ans: Window, Frame and Dialog classes use a BorderLayout as their layout.


62) Which containers use a Flow layout as their default layout?

Ans: Panel and Applet classes use the FlowLayout as their default layout.


63) What are wrapper classes?

Ans: Wrapper classes are classes that allow primitive types to be accessed as objects.


64) What are Vector, Hashtable, LinkedList and Enumeration?

Ans: Vector : The Vector class provides the capability to implement a growable array of objects.Hashtable : The Hashtable class implements a Hashtable data structure. A Hashtable indexes and stores objects in a dictionary using hash codes as the object’s keys. Hash codes are integer values that identify objects.

LinkedList: Removing or inserting elements in the middle of an array can be done using LinkedList. A

LinkedList stores each object in a separate link whereas an array stores object references in consecutive locations.

Enumeration: An object that implements the Enumeration interface generates a series of elements, one at a time. It has two methods, namely hasMoreElements( ) and nextElement( ). HasMoreElemnts( ) tests if this enumeration has more elements and nextElement method returns successive elements of the series.


65) What is the difference between set and list?

Ans: Set stores elements in an unordered way but does not contain duplicate elements, whereas list stores elements in an ordered way but may contain duplicate elements.


66) What is a stream and what are the types of Streams and classes of the Streams?

Ans: A Stream is an abstraction that either produces or consumes information. There are two types of Streams and they are:

Byte Streams: Provide a convenient means for handling input and output of bytes.Character Streams: Provide a convenient means for handling input & output of characters.Byte Streams classes: Are defined by using two abstract classes, namely InputStream and OutputStream.Character Streams classes: Are defined by using two abstract classes, namely Reader and Writer.


67) What is the difference between Reader/Writer and InputStream/Output Stream?

Ans: The Reader/Writer class is character-oriented and the InputStream/OutputStream class is byte-oriented.


68) What is an I/O filter?

Ans: An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.


69) What is serialization and deserialization?

Ans: Serialization is the process of writing the state of an object to a byte stream.Deserialization is the process of restoring these objects.


70) What is JDBC?

Ans: JDBC is a set of Java API for executing SQL statements. This API consists of a set of classes and interfaces to enable programs to write pure Java Database applications.

No comments: