Search Interview Questions | ![]() ![]() Click here and help us by providing the answer. ![]() Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers - Order By Newest | ||||
![]() ![]() | ||||
| ||||
Ans. 1. Issue with Jar and ClassPath Conflicts 2. Killing JVM will terminate all applications | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. It stores the string as a character array with 2 bytes for each character. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. POJO is Plain Java Object that holds only Member Elements , getters are setters and minimal processing on that. The primary purpose of such object is to either transfer information or keeping state for a while. They are not intended to provide any processing or transformation. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Multi Level Inheritance is multi level hierarchy of classes. Here is the example - http://www.buggybread.com/2015/09/java-se-class-diagram-classes-that_603.html Class RoleList extends ArrayList which in turn extends AbstractList which in turn extends AbstractCollection. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. No, It requires creation of atleast one Class. Creating an object of that class is not compulsory as we can write all our logic within main method which is static. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. It is a class level variable that is shared among the objects of that class. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. Constructor has the same name as class name whereas instance initialization block just have a body without any name or visibility type. instance initialization blocks are useful if we want to have some code run regardless of which constructor is used or if we want to do some instance initialization for anonymous classes. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. Default methods results in multiple inheritance of behavior and not of state. In case we try to implement multiple interfaces with default method having same name and signature, and don't override it in implementation class, it will throw an error. For example - interface MyInterface { public void default myMethod(){ } } interface MyInterface2 { public void default myMethod(){ } } class MyClass implements MyInterface,MyInterface2 { } This code will compilation error "Duplicate Default Method" if we specify the definition of myMethod() in myClass, compiler won't complain and there is no conflict and MyClass can use overridden definition. But if we don't override myMethod() in MyClass, Java would be in conflict as to what definition should be carried to MyClass and hence throws compilation error. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. We can refer to a function using this operator like System.out.println(intList.stream().reduce(Math::max).get()); | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Yes, compiler won't complain but at runtime it will give an error saying "Error: Main method not found in class". Even though we can use this method as any other private method, it cannot be invocate by executing the class. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. x==y means that both references have same type and are pointing to same memory location and hence would always mean that they have same value. x.equals(y) is not required in this case. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. if x==y turns out to be true x.equals(y) will be true too. If x.equals(y) could be true even if x==y is true or not. So the only possible outcomes are 1 || 1 = 1 0 || 1 = 1 0 || 0 = 0 i.e the outcome of x.equals(y) check for x==y is not required in this if statement. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. With Java 7 or Later. If you don't declare the list to be of specific type , it treats it as list of objects. int 1 is auto boxed to Integer and "1" is String and hence both are objects. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Yes, everything except primitive types are objects in Java. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. No, If both Parent and Derived are outer classes. public class Vehicle { private static String manufacturingDate = "2016"; } public class Car extends Vehicle{ public static void main(String args[]){ System.out.println(manufacturingDate); // error - The field Vehicle.manufacturingDate is not visible } } Yes, If derived is the inner class of Parent. public class Vehicle { private static String manufacturingDate = "2016"; static public class Car extends Vehicle{ public static void main(String args[]){ System.out.println(manufacturingDate); // no problem } } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Yes, a Class is supposed to define all abstract methods declared in the interface. With Java 8 , Interfaces can have default methods which need not be implemented by the implementing class. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. IdentityHashMap is a class that implements AbstractMap and provides a data structure with Elements having Key Value pair, just like HashMap. It is similar to HashMap except that it uses reference equality when comparing elements. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Buffer is cleared in 2 circumstances, i.e 1. naturally when the buffer is filled and 2. explicitly when the method flush is called ( for flushing the residual ) Ideally we just need to call flush once at the end of file writing so that the residual content should be dumped to file. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Implementing Comparable interface means that the elements of the class are comparable i.e the class provides the implementation of compareTo method that would help comparing the elements. This is usually required if we are planning to sort elements of a collection, If compareTo method is not defined , the sorting class / method could never understand a way to compare its elements in order to sort them. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. Multiple Inheritance refers to the concept of a class inheriting multiple classes. Example - Class C extends Class A ,Class B. This is not allowed in Java. Multilevel Inheritance refers to the concept of Inheritance in a chain. Example - Class B extends Class A, Class C extends Class B. This is permitted in Java. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. As the name suggest size is the size of collection / data structure i.e number of elements or memory utilized by the collection. Index is the position of an element in a collection or data structure. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Classpath is the parameter for JVM to look for java classes ( .class files ) that are to be looad by class loader | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. = is the assignment operator that assigns the result of the expression on the right to the variable on the left, whereas == is the operator to check object equality to see if the reference on left and right are pointing to the same object. For primitive types, its used to check if both variables holds the same value. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. For objects or references, == operator check if the reference on left and right points to the same object. For primitive types or variables, == operator check if the variable on left and right holds the same value. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Enums in Java are used to declare predefined objects and then reuse them. they offer many benefits 1. Enum instance are type safe and thread safe. 2. Enum instances are singleton and hence reused. 3. If we use Enums with Switch , It makes sure that the passed argument is either of its instance and hence provides a safeguard. 4. If we use Enum with Sorted Collections we can sort the elements with a predefined priorities ( as per constant declaration in enum ) 5. We can use Enum as a Factory by defining its constructor. 6. We can store related constant data within enum. For example - If we know the values for the map upfront, we can alternatively use an enum. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Here is the list of classes that implements Collections Interface - http://www.buggybread.com/2015/02/java-collections-classes-that-implement.html Having Collection interface to extend Cloneable interface would mean necessarily implement clone method by all implementing classes. As not all collection classes allow duplicate elements, it makes no sense to clone elements for them. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. As with all other objects its garbage collected after its usage unless its rethrown. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. 1. Switching Overheads - Even though multi threading aims at improving performance by reducing the wait time and hence improving overall throughput, there is a cost of switching resources between threads and sometime this cost can surpass the benefits if there isnt much wait for IO or external communication. 2. Debugging is hard with multi threaded code. 3. Deadlock - Execution of multi threaded code many a times lead to deadlock due to shared resources. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. java.util.Collection | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. URI stands for Uniform Resource Indicator URL stands for Uniform Resource Locator URN stands for Uniform Resource Name URI = URL + URN For ex - http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php?keyword=url This is URI. The string from start till .php is URL whereas keyword=url is URN. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
![]() ![]() | ||||