java is an Object  Oriented Programming Language. Which is mostly used to develop Windows based Software  as well as Web Based Project. It is good to have good knowledge about a programming language and practical knowledge for developing program in that particular language. In the technical interview for the post of  Java Developer some basic questions are asked. In this post I am telling about questions at basic level. 

In the Part 1 we have seen some questions from Variable, operator interfaces and jvm etc. Now in this post  questions are related to Variable, operators, JVM and Jdk, Interface and access specifier, static keyword, inner classes, data type.


Q             When can an object reference be cast to an interface reference?  
A             An object reference can be cast to an interface reference when the object implements the referenced interface.

Q             Which class is extended by all other classes?  
A             The Object class is extended by all other classes.

Q             Can an object be garbage collected while it is still reachable?  
A             A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected.

Q             Is the ternary operator written x : y ? z or x ? y : z ?  
A             It is written x ? y : z.

Q             How is rounding performed under integer division?  
A             The fractional part of the result is truncated. This is known as rounding toward zero.

Q             What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?  
A             The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.

Q             What classes of exceptions may be caught by a catch clause?  
A             A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.

Q             If a class is declared without any access modifiers, where may the class be accessed?  
A             A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.

Q             Does a class inherit the constructors of its superclass?  
A             A class does not inherit constructors from any of its superclasses.

Q             What is the purpose of the System class?  
A             The purpose of the System class is to provide access to system resources.

Q             Name the eight primitive Java types.  
A             The eight primitive types are byte, char, short, int, long, float, double, and boolean.

Q             Which class should you use to obtain design information about an object?  
A             The Class class is used to obtain information about an object's design.

Q             Is "abc" a primitive value?  
A             The String literal "abc" is not a primitive value. It is a String object.

Q             What restrictions are placed on the values of each case of a switch statement?  
A             During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.

Q             What modifiers may be used with an interface declaration?  
A             An interface may be declared as public or abstract.

Q             Is a class a subclass of itself?  
A             A class is a subclass of itself.

Q             What is the difference between a while statement and a do statement?  
A             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.

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

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

Q             Can an exception be rethrown?  
A             Yes, an exception can be rethrown.

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

Q             If a method is declared as protected, where may the method be accessed?  
A             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.

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

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

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

Q             What class of exceptions is generated by the Java run-time system?  
A             The Java runtime system generates RuntimeException and Error exceptions.

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

Q             What is the difference between a field variable and a local variable?  
A             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.

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

Q             What is the relationship between a method's throws clause and the exceptions that can be thrown during the method's execution?  
A             A method's throws clause must declare any checked exceptions that are not caught within the body of the method.

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

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

Q             What an I/O filter?  
A             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.

Q             If an object is garbage collected, can it become reachable again?  
A             Once an object is garbage collected, it ceases to exist. It can no longer become reachable again.

Q             What are E and PI?  
A             E is the base of the natural logarithm and PI is mathematical value pi.

Q             Are true and false keywords?  
A             The values true and false are not keywords.

Q             What is the difference between the File and RandomAccessFile classes?  
A             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.

Q             What happens when you add a double value to a String?  
A             The result is a String object.

Q             What is your platform's default character encoding?  
A             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.

Q             Which package is always imported by default?  
A             The java.lang package is always imported by default.

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

Q             What’s the difference between notify() and notifyAll()?  
A             notify() is used to unblock one waiting thread; notifyAll() is used to unblock all of them. Using notify() is preferable (for efficiency) when only one blocked thread can benefit from the change (for example, when freeing a buffer back into a pool). notifyAll() is necessary (for correctness) if multiple threads should resume (for example, when releasing a "writer" lock on a file might permit all "readers" to resume).