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 Rating | ||||
![]() ![]() | ||||
| ||||
Ans. As with all other objects its garbage collected after its usage unless its rethrown. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
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. The simplest way is to ignore them if Maven enforcer plugin is complaining about it but it may lead to runtime problems later. We can do the dependency:tree to see from where these duplicate ones are coming and hence can exclude the duplicate one. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Yes , we have been using this plugin with our projects and its purpose is to warn and stop the Build if there are duplicates of the same package and class are being carried either directly or through transitive dependencies. the duplicate could be coming through different types of dependencies or through different versions of the same dependency. Its purpose is to make sure that there is only one copy thats being used at compile time and runtime and hence shouldnt later result in runtime problems. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
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. 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. = 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. public class BuggyBread { | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. Classpath is the parameter for JVM to look for java classes ( .class files ) that are to be looad by class loader | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
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. 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. 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. 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. 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. 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. 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. It make sense only if we intend to modify either of the object and would like to preserve original state in other. Otherwise we can reuse the original object by making it singleton. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Both are creational design patterns. Singleton is used when we would like to reuse an object if object is not supposed to hold request or thread specific information. Inversely Prototype is used in situations where we would like to reuse the object information but the request / thread may require it own data to be persisted. In short, Singleton is used in situations where we can live with single object being shared across multiple requests or threads whereas Prototype is used when we need duplicate copies of objects. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
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. 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. Cold Deployment is a conventional deployment mechanism that follows the multi step process to deploy code changes to the running app i.e Build -> Deploy - Restart. whereas Hot Deployment is deployment changes on the fly without need to first build , deploy and then restart. All these functions happens on the fly as soon as the changes are made to the code. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. It is the ability to deploy changes on the fly without need to first build , deploy and then restart. All these functions happens on the fly as soon as the changes are made to the code. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
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. We can refer to a function using this operator like System.out.println(intList.stream().reduce(Math::max).get()); | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. GET is supposed to get information from the server. Client sends the minimal information so that Server can respond with the response body on basis of request. For example - You want to get complete employment record for employee id 123 POST is supposed to send the information for submission. Payload or a Body is usually sent so that it can be persisted on the server. For example - Sending the complete information of an employee ( id, name , dept etc ) to the server for persisting it. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. No, even if there is no payload, you can't hit the POST request by typing it into browser address bar. You will need a client that can make a POST Request. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. It depends on whether the request object is persisted as it is or its first dismantled, modified or refactored and then inserted into DB. In first case, it should be a PUT request whereas in second case it should be a POST Request. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. PUT requests are only meant to place the object as it is on server. For example - You want a file to be uploaded and then placed in a particular folder or you want an Employee object to be persisted in the table. POST requests are also meant to transfer information from client to server but that information once received at the server is evaluated , modified or refactored before persisting. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Copy Constructor is used for creating a duplicate of another object. Duplicate object will have the same state of the copied object but will have independent values in different memory locations. Copy Constructor can be useful to create duplicates of immutable objects as the Original cannot be tampered. Moreover It can be useful if base copies are required for individual requests in threading. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. A publisher is part of build process that reports whether the build is stable or not. For example - Junit Test report publisher. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() ![]() | ||||