Today's Jobs :


CORE JAVA FREQUENTLY ASKED QUESTIONS AND ANSWERS-11


CORE JAVA FREQUENTLY ASKED QUESTIONS AND ANSWERS-11


Question: Is a class a subclass of itself?  
Answer:   A class is a subclass of itself. 

Question: What is the difference between a while statement and a do statement?  
Answer:   A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once. 

Question: What modifiers can be used with a local inner class?  
Answer:   A local inner class may be final or abstract. 

Question: What is the purpose of the File class?  
Answer:   The File class is used to create objects that provide access to the files and directories of a local file system. 

Question: Can an exception be rethrown?  
Answer:   Yes, an exception can be rethrown. 

Question: When does the compiler supply a default constructor for a class?  
Answer:   The compiler supplies a default constructor for a class if no other constructors are provided. 

Question: If a method is declared as protected, where may the method be accessed?  
Answer:   A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared. 

Question: Which non-Unicode letter characters may be used as the first character of an identifier?  
Answer:   The non-Unicode letter characters $ and _ may appear as the first character of an identifier 

Question: What restrictions are placed on method overloading?  
Answer:   Two methods may not have the same name and argument list but different return types. 

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: What is the return type of a program's main() method?  
Answer:   A program's main() method has a void return type. 

Question: What class of exceptions are generated by the Java run-time system?  
Answer:   The Java runtime system generates RuntimeException and Error exceptions. 

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: What is the difference between a field variable and a local variable?  
Answer:   A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method. 

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: What is the relationship between a method's throws clause and the exceptions that can be thrown during the method's execution?  
Answer:   A method's throws clause must declare any checked exceptions that are not caught within the body of the method. 

Question: Why are the methods of the Math class static?  
Answer:   So they can be invoked as if they are a mathematical code library. 

Question: What are the legal operands of the instanceof operator?  
Answer:   The left operand is an object reference or null value and the right operand is a class, interface, or array type. 

Question: What an I/O filter?  
Answer:   An I/O 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: If an object is garbage collected, can it become reachable again?  
Answer:   Once an object is garbage collected, it ceases to exist. It can no longer become reachable again. 

Question: What are E and PI?  
Answer:   E is the base of the natural logarithm and PI is mathematical value pi. 

Question: Are true and false keywords?  
Answer:   The values true and false are not keywords. 

Question: What is the difference between the File and RandomAccessFile classes?  
Answer:   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: What happens when you add a double value to a String?  
Answer:   The result is a String object. 

Question: What is your platform's default character encoding?  
Answer:   If you are running Java on English Windows platforms, it is probably Cp1252. If you are running Java on English Solaris platforms, it is most likely 8859_1. 

Question: Which package is always imported by default?  
Answer:   The java.lang package is always imported by default. 

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.