Java Interview Questions and Answers
Question - 91 : - How is it possible for two String objects with identical values not to be equal under the == operator? How are this() and super() used with constructors?
Answer - 91 : - The == operator compares two objects to determine if they are the same objects in memory. It is possible for two String objects to have the same value, but located in different areas of memory.
Question - 92 : - What is an IO filter?
Answer - 92 : - An IO filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.
Question - 93 : - What is the Set interface?
Answer - 93 : - The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements.
Question - 94 : - How can you force garbage collection?
Answer - 94 : - You can't force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.
Question - 95 : - What is the purpose of the enableEvents() method?
Answer - 95 : - The enableEvents() method is used to enable an event for a particular object. Normally, an event is enabled when a listener is added to an object for a particular event. The enableEvents() method is used by objects that handle events by overriding their event-dispatch methods.
Question - 96 : - What is the difference between the File and RandomAccessFile classes?
Answer - 96 : - The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file.
Question - 97 : - What interface must an object implement before it can be written to a stream as an object?
Answer - 97 : - An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.
Question - 98 : - What is the ResourceBundle class?
Answer - 98 : - 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 - 99 : - How do you know if an explicit object casting is needed?
Answer - 99 : - 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.
Question - 100 : - What is a Java package and how is it used?
Answer - 100 : - 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.