Ads 468x60px

Pages

Tuesday, 26 June 2012

Java interview questions with answers


Question: What is casting?
Answer:
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.

Question: Name Container classes.
Answer:
Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane.

Question: What class allows you to read objects directly from a stream? 
Answer:
The ObjectInputStream class supports the reading of objects from input streams.

Question:  How are this() and super() used with constructors?
Answer:
this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

Question:  How is it possible for two String objects with identical values not to be equal under the == operator?
Answer:
The == operator compares two objects to determine if they are the same object in memory. It is possible for two String objects to have the same value, but located indifferent areas of memory.

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

Question: What is the ResourceBundle class?
Answer:
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.

Question: What is the difference between a Scrollbar and a ScrollPane?
Answer:
A Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPane handles its own events and performs its own scrolling.

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: Does the code in finally block get executed if there is an exception and a return statement in a catch block?
Answer:
  If an exception occurs and there is a return statement in catch block, the finally block is still executed. The finally block will not be executed when the System.exit(1) statement is executed earlier or the system shut down earlier or the memory is used up earlier before the thread goes to finally block.

Question: How you restrict a user to cut and paste from the html page?
Answer:
Using javaScript to lock keyboard keys. It is one of solutions.

1 comments:

Anonymous said...

beanbags

Hi, Great post. I really learned a lot about java and html from your article. Thanks so much.

Post a Comment