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. true false true Just like Strings, java maintains an integer constant pool too. So 1 will be maintained in integer constant pool and hence reference int2 will point to same integer in pool. String pool is only for string literals ( defined by "" ) and not for newly created objects and hence str1 == str2 will return false as they are separate objects in memory. String pool is used for storing string literals so that they can be reused and str3 and str4 will point to same string literal in string pool. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. When it is no longer referenced or it looses all references which were earlier pointing to it. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. We cannot explicitly initiate destruction of an object as no destroy method is available in java. Only Garbage collection can destroy an object. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Synchronized List locks the whole list to provide synchronization and thread safety during the read or write operation, while, CopyOnWriteArrayList doesn’t lock the whole list during these operations. The CopyOnWriteArrayList class works according to its name i.e. copy-on-write which performs different actions for reading and write operations. For every write operation (add, set, remove, etc), it makes a new copy of the elements in the list. and for the read operations (get, iterator, listIterator, etc), it works on a different copy. So there is no additional overhead during a read operation and its read operation is faster than Collections.SynchronizedList(). Thus, COWAL is better for reading operation than Synchronized List. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. http://www.devinline.com/2015/10/Lock-Vs-synchronized-in-java.html | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. It will print "true" with integers as well as strings. The reason is "Integer constant pool" and "String pool" String pool maintains pool of string literals. When a string literal is used for the first time, a new string object is created and is added to the pool. Upon it's subsequent usage , the reference for the same object is returned. Similarly java uses integer constant pool. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Public constructor is simple and easy as it's the default way of object creation. So there are no additional coding overheads as compiler provides the default constructor if none is provided by coder. With static final methods, it facilitates loose coupling by segregating the responsibility of object creation to a separate method. Validation can be done on the constructor arguments before calling it. Moreover if any adaption on the arguments is required that can achieved easily with factory method.On the flip side, there is coding overhead and additional method call. | ||||
![]() ![]() | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. We can get an array out of ArrayList by using toArray() method of an array list. String a[] = arrayList.toArray(); | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Livelock is when two threads or processes get deadlocked because they try to perform the same action to come out of a potential deadlock. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. mutual exclusion i.e the resource is not shareable and hence a process should have exclusive access to it at a particular time Hold and Wait i.e the process doesn't release all existing resources held by it before requesting for another one. No preemption i.e noone can forcefully release a resource held by another process and the process should voluntarily release the resource held by it. Circular Wait - For ex, P1 is waiting on resource to be released by P2, P2 is waiting on resource to be released by P3 and P3 is waiting on the resource to be released by P1 | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Yes. Both concepts are independent of each other. Overriding depends on the methods with same name and signature whereas Overloading on same name but with different signatures. All definitions of an overloaded method can be individually overridden in the derived class. For example - Class A has overloaded methods "public void myMethod(String str)" and "public void myMethod(int x)" We can have derived class ClassB extends ClassA and hence can override both methods myMethod(String str) and myMethod(int x) in ClassB | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. This is used to achieve runtime polymorphism in java. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Enumeration can iterate only legacy collections like Vector , HashTable and Stack whereas Iterator can iterate both legacy and non legacy collections. Enumeration is less safer than Iterator Enumeration is fail safe whereas Iterator is fail fast Iterator allows for removal of element while traversal whereas Enumeration doesn't have remove method. Enumerations were introduced in Java 1 whereas Iterators were introduced with Java 2 Enumerations have methods like hasMoreElements and nextElement whereas Iterators have methods like hasNext, next and remove | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. It means that Java is compiled to byte code that is platform independent and hence can be run anywhere or any machine. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. It means that now individual modules will be built independently instead of complete jdk built in a single jar file. So we will have multiple jars instead of single jar. Moreover this organization would result in lighter applications as they can just built themselves with the required jars and hence ignoring the not required and legacy modules. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. The projects aims to organize the Java source code into independent modules and hence facilitate building them independently.So now we will have multiple core java jars instead of single one. This way of organizing the code would offer following advantages 1. Will make applications lighter as only required modules will be built with the application. Moreover there are some legacy packages currently which anyone hardly use. 2. Reuse same class whole identifiers across different modules. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. JVM and JDK are getting smaller. New command line tool called jshell that will add native support and popularize a Java way to REPL (Read-Eval-Print-Loop) private methods in interfaces Introduction of the module system or project Jigsaw JavaDoc Search Light version of JSON API HTTP2 client | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Such a class still can have member elements which can be inherited and hence facilitate code reuse. Moreover Abstract class can have non final static elements whereas interfaces are only allowed to have static final elements. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Authentication / Authorization URL forwarding Auditing / Logging Localization | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. It is used for intercepting the request. It's primary use is to implement security policy. All or specific request types can be intercepted and hence forwarded to authentication / authorization module so as to facilitate authorized requests to application. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Hibernate mapping configurations are used for mapping hibernate entities and corresponding DB Tables. Conventionally Entities and Table can share the same name and hence framework can provide implicit mapping instead of explicit mapping through configurations. Though it may result in little loss of flexibility in extreme cases but will work with all applications following the convention. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Yes, It may result in some loss of flexibility as the application has to follow all conventions. Moreover it can contradict with other design paradigms or principles used in the application or framework. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Convention over configuration is a way of software design used by frameworks that attempt to decrease the number of decisions that a developer is required to make without necessarily losing flexibility. The objective is to reduce the unnecessary configurations and follow conventions to accomplish that. For example - DB Entity and DB Table name conventionally should be same and hence shouldn't require configuring mapping between the two. "Spring Boot" and "Ruby on Rails" have adopted this design principle. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Goto statement results in unstructured jumps in control from one code location to another and hence makes the code very difficult to read , maintain and debug. Moreover Goto can always be replaced using other statements like break / continue and hence results in structured movement of programming control. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Yes , as both code and its meta information reside in the same file, it promotes better readability and maintenability. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Annotations are used to specify meta information about the code. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Protocol buffers are language-neutral, platform-neutral, mechanism for serializing structured data. It is developed by google. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() ![]() | ||||