Thursday, June 24, 2010

CORE JAVA

QUESTION: What is a compilation unit?

ANSWER: A compilation unit is a Java source code file.

QUESTION: What restrictions are placed on method overriding?
ANSWER:: Overridden methods must have the same name, argument list, and return type.
The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method.
QUESTION: How can a dead thread be restarted?
ANSWER: A dead thread cannot be restarted.

QUESTION: What happens if an exception is not caught?
ANSWER: An uncaught exception results in the uncaughtException() method of the thread's ThreadGroup being invoked, which eventually results in the termination of the program in which it is thrown.

QUESTION: Which arithmetic operations can result in the throwing of an ArithmeticException?
ANSWER: Integer / and % can result in the throwing of an ArithmeticException

QUESTION: Can an abstract class be final?
ANSWER: An abstract class may not be declared as final

QUESTION: What happens if a try-catch-finally statement does not have a catch clause to handle an exception that is thrown within the body of the try statement?
ANSWER: The exception propagates up to the next higher level try-catch statement (if any) or results in the program's termination

QUESTION: What is numeric promotion?
ANSWER: Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required

QUESTION: What is the difference between a public and a non-public class?
ANSWER: A public class may be accessed outside of its package. A non-public class may not be accessed outside of its package.

QUESTION: To what value is a variable of the boolean type automatically initialized?
ANSWER: The default value of the boolean type is false

QUESTION: Can try statements be nested?
ANSWER: Yes

QUESTION: What is the difference between the prefix and postfix forms of the ++ operator?
ANSWER: The prefix form performs the increment operation and returns the value of the increment operation. The postfix form returns the current value all of the expression and then performs the increment operation on that value.

QUESTION: What is the purpose of a statement block?
ANSWER: A statement block is used to organize a sequence of statements as a single statement group

QUESTION: What is a Java package and how is it used?
ANSWER: A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces.

QUESTION: What modifiers may be used with a top-level class?
ANSWER: A top-level class may be public, abstract, or final.

QUESTION: What are the Object and Class classes used for?
ANSWER: The Object class is the highest-level class in the Java class hierarchy. The Class class is used to represent the classes and interfaces that are loaded by a Java program.

QUESTION: How does a try statement determine which catch clause should be used to handle an exception?
ANSWER: When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exception is executed. The remaining catch clauses are ignored.

QUESTION: What are synchronized methods and synchronized statements?
ANSWER: Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.

QUESTION: What is the difference between an if statement and a switch statement?
ANSWER: The if statement is used to select among two alternatives. It uses a boolean expression to decide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternative should be executed.

QUESTION: What is the diffrence between inner class and nested class?
ANSWER: When a class is defined within a scope od another class, then it becomes inner class. If the access modifier of the inner class is static, then it becomes nested class.

QUESTION: Diffrence between JRE And JVM AND JDK
ANSWER: The "JDK" is the Java Development Kit. I.e., the JDK is bundle of software that you can use to develop Java based software. The "JRE" is the Java Runtime Environment. I.e., the JRE is an implementation of the Java Virtual Machine which actually executes Java programs. Typically, each JDK contains one (or more) JRE's along with the various development tools like the Java source compilers, bundling and deployment tools, debuggers, development libraries, etc.

QUESTION: Why is not recommended to have instance variables in Interface
ANSWER: By Default, All data members and methods in an Interface are public. Having public variables in a class that will be implementing it will be violation of the Encapsulation principal.

QUESTION: Can there be an abstract class with no abstract methods in it?
ANSWER: Yes