Sunday, October 14, 2007

JAVA QUESTIONS

25)What are inner class and anonymous class?

A) Inner class : classes defined in other classes, including those defined in methods are called inner classes.
An inner class can have any accessibility including private.
Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.

26)What is a package?

A) A package is a collection of classes and interfaces that provides a high-level layer of access protection and name space management.

27) What is a reflection package?
Ans: java.lang.reflect package has the ability to analyze itself in runtime.

28) What is interface and its use?

A) Interface is similar to a class which may contain method's signature only but not bodies and it is a formal set of method and constant declarations that must be defined by the class that implements it. Interfaces are useful for:
a)Declaring methods that one or more classes are expected to implement
b)Capturing similarities between unrelated classes without forcing a class relationship.
c)Determining an object's programming interface without revealing the actual body of the class.

30) What is the difference between Integer and int?

A)
a) Integer is a class defined in the java.lang package, whereas int is a primitive data type defined in the Java language itself. Java does not automatically convert from one to the other.
b) Integer can be used as an argument for a method that requires an object, whereas int can be used for calculations.

32) What is the difference between abstract class and interface?

A)
a) All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract.
b) In abstract class, key word abstract must be used for the methods
whereas interface we need not use that keyword for the methods.
c) Abstract class must have subclasses whereas interface can't have subclasses.

33) Can you have an inner class inside a method and what variables can you access?

A) Yes, we can have an inner class inside a method and final variables can be accessed.

34) What is the difference between exception and error?

A) The exception class defines mild error conditions that your program encounters.
Ex: Arithmetic Exception, FilenotFound exception
Exceptions can occur when
-- try to open the file, which does not exist
-- the network connection is disrupted
-- operands being manipulated are out of prescribed ranges
-- the class file you are interested in loading is missing
The error class defines serious error conditions that you should not attempt to recover from. In most cases it is advisable to let the program terminate when such an error is encountered.
Ex: Running out of memory error, Stack overflow error.

35) What is the class and interface in java to create thread and which is the most advantageous method?

A) Thread class and Runnable interface can be used to create threads and using Runnable interface is the most advantageous method to create threads because we need not extend thread class here.

36) When you will synchronize a piece of your code?

A) When you expect your code will be accessed by different threads and these threads may change a particular data causing data corruption.

37) What is daemon thread and which method is used to create the daemon thread?

A) Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread.

38) Are there any global variables in Java, which can be accessed by other part of your program?

A) No, it is not the main method in which you define variables. Global variables is not possible because concept of encapsulation is eliminated here.

39)What is the difference between applications and applets?

A)
a)Application must be run on local machine whereas applet needs no explicit installation on local machine.
b)Application must be run explicitly within a java-compatible virtual machine whereas applet loads and runs itself automatically in a java-enabled browser.
d)Application starts execution with its main method whereas applet starts execution with its init method.
e)Application can run with or without graphical user interface whereas applet must run within a graphical user interface.

40)How does applet recognize the height and width?

A) Using getParameters() method.

41)When do you use codebase in applet?

A) When the applet class file is not in the same directory, codebase is used.

42)How do you set security in applets?

A) using setSecurityManager() method

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

A) 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

44)What is source and listener ?

A)
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.

45) What is adapter class?

A) 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.

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

A) 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.

47) What is the difference between choice and list?

A) 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.

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

A) 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.

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

A) Window, Frame and Dialog classes use a BorderLayout as their layout.

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

A) Panel and Applet classes use the FlowLayout as their default layout.

51) What are wrapper classes?

A) Wrapper classes are classes that allow primitive types to be accessed as objects.

52) What is the difference between set and list?

A) 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.

what is the basic difference in rmi & corba.
1. both are distributed technologies.
2. rmi is used when both client & server are in java.
3. corba is used when client & server are written in different lang.
4. IDL comes into picture. as it changes native calls to java or vice versa.


53) what does class.forName(driver) do?

A) it requests for the driver & loads the driver.
statement.execute() returns resultset.
what type of resultset is it?
---> sql result set

No comments: