Java Questions 51 - 100  «Prev Next»

Java Dynamic Cast

  1. How do you perform a dynamic cast using a Class cast type object instead of the static cast operator?

    Answer: Java 5 has a new method called Class.cast. This is the dynamic equivalent of the cast operator in Java.

  2. When would you use the ConcurrentHashMap class?

    Answer:
    The java.util.ConcurrentHashMap is a collection that works much like the other collections except it provides concurrency support.

  3. What is an "instance method"?

    Answer:
    This is the method that the object contains.

  4. Is the Inputstream a class or an interface?

    Answer:
    A class Public class DataInputStream extends FilterInputStream implements DatInput

  5. What is one of the applications of a finally block?

    Answer:
    A finally block is used to guarantee that input stream and output stream will be closed even if an error occurs.

  6. When should you use byte streams?

    Answer:
    When dealing with the most primitive input and output operations.

  7. What purpose does the keyword "transient" serve?

    Answer: The transient keyword in the Java language is used for Java Serialization. Any field marked transient will not be saved to disk. This is useful when a class contains a reference to another object that does not implement Serializable but you still would like to persist a class instance to disk.

  8. What is serialization in Java?

    Answer:
    One approach to saving a data model to disk is to write all of the object instances in the data model's object graph to disk, and then simply reload them at a later time. Deserializing an object is the process of reconstructing the object instance from the data members written to disk.

  9. What is the readResolve() method in Java?

    Answer:
    The accessibility of the readResolve method is significant. If you place a readResolve method on a non-final class you must carefully consider its accessibility.

  10. What do all array types implement?

    Answer:
    All array types implement the cloneable interface. Any array can be copied by invoking its clone() method.