Core Java - Interview Questions and Answers VOL-II

Q.1  How can you force garbage collection?

Ans:  You can't force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.

Q.2  What is the immediate superclass of the Applet class?

Ans:  Panel

Q.3  When is the ArithmeticException throwQuestion: What is the GregorianCalendar class?

Ans:  The GregorianCalendar provides support for traditional Western calendars.

Q.4  What is the SimpleTimeZone class?

Ans:  The SimpleTimeZone class provides support for a Gregorian calendar.

Q.5  What is casting?

Ans:  There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.

Q.6  Explain the usage of the keyword transient?

Ans:  This keyword indicates that the value of this member variable does not have to be serialized with the object.

When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for

integers).

Q.7  What is the immediate superclass of the Dialog class?

Ans:  Window.

Q.8  What is clipping?

Ans:  Clipping is the process of confining paint operations to a limited area or shape.

Q.9  What is a native method?

Ans:  A native method is a method that is implemented in a language other than Java.

Q.10  Can a for statement loop indefinitely?

Ans:  Yes, a for statement can loop indefinitely. For example, consider the following: for(;;) ;

Q.11  What are order of precedence and associativity, and how are they used?

Ans:  Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left

Q.12  Is Empty .java file a valid source file?

Ans:  Yes, an empty .java file is a perfectly valid source file.

Q.13  Can a .java file contain more than one java classes?

Ans:  Yes, a .java file contain more than one java classes, provided at the most one of them is a public class.

Q.14  Is String a primitive data type in Java?

Ans:  No String is not a primitive data type in Java, even though it is one of the most extensively used object. Strings in Java are instances of String class defined in java.lang package.

Q.15  Is main a keyword in Java?

Ans:  No, main is not a keyword in Java.

Q.16  Is next a keyword in Java?

Ans:  No, next is not a keyword.

Q.17  Is delete a keyword in Java?

Ans:  No, delete is not a keyword in Java. Java does not make use of explicit destructors the way C++ does.

Q.18  Can an object's finalize() method be invoked while it is reachable?

Ans:  An object's finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object's finalize() method may be invoked by other objects.

Q.19  What is the Set interface?

Ans:  The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements.

Q20.  Name three Component subclasses that support painting.

Ans:  The Canvas, Frame, Panel, and Applet classes support painting.

Q21.  What value does readLine() return when it has reached the end of a file?

Ans:  The readLine() method returns null when it has reached the end of a file.

Q.22  Is exit a keyword in Java?

Ans:  No. To exit a program explicitly you use exit method in System object.

Q.23  What happens if you don't initialize an instance variable of any of the primitive types in Java?

Ans:  Java by default initializes it to the default value for that primitive type. Thus an int will be initialized to 0, a Boolean will be initialized to false.

Q.24  How can a subclass call a method or a constructor defined in a superclass?

Ans:  Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass's constructor.

Q.25  What is the Properties class?

Ans:  The properties class is a subclass of Hashtable that can be read from or written to a stream. It also provides the capability to specify a set of default values to be used.


Q.26  What interface must an object implement before it can be written to a stream as an object?

Ans:  An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.

Q.27  What is the ResourceBundle class?

Ans:  The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program's appearance to the particular locale in which it is being run.

Q.28  How do you know if an explicit object casting is needed?

Ans:  If you assign a superclass object to a variable of a subclass's data type, you need to do explicit casting. For example:
Object a; Customer b; b = (Customer) a;When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.

Q.29  What is a Java package and how is it used?

Ans:  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.

Q.30  How do you restrict a user to cut and paste from the html page?

Ans:  Using Servlet or client side scripts to lock keyboard keys. It is one of solutions.

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Hostgator Coupon Code