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. Yes, Runtime Polymprohism requires either Class inheritance or Interface implementation. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Inheritance , Runtime Polymorphism and Composition. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. set1.stream().filter(p->p.element1.equals("Hello")).findAny().isPreent(); or set1.stream().map(A::getElement1).anyMatch("Hello"::equals) | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Step 1 - We can create a Registry Class having Map of all created objects as key and References list as value. Step 2 - Whenever we create an object , we should update the Registry in the constructor to add the new object. Step 3 - Whenever we assign a new reference to the object , we need to update the entry in Map. Similarly if the reference get's removed ( end of scope etc ), we need to remove the entry of reference from the list. Step 4 - We can have threaded code to monitor the Map to see if any object looses all it's references and should call the method to destroy object and clean the memory. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. We can store the references in a collection by adding to those objects in the collection. We can create a class "ObjectRegistry" with a collection or multiple collections with a search algorithm to look for the already collected objects. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Loose Coupling Facilitates designing complex applications by making them modular. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Generics are a facility of generic programming that were added to the Java programming language in 2004 within J2SE5.0. They allow "a type or method to operate on objects of various types while providing compile-time type safety. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. String has an argument constructor that take char array as argument and creates a string. There is no constructor available with String that takes in a character and creates a String. We can use StringBuilder which has a char argument constructor. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. There is a method toCharArray() within String class that can be used to convert string to char array. string.toCharArray(); String class has an argument constructor that takes a char array and create a string new String(charArray); | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. static members are stored in method area of heap objects are stored on heap object references are stored on stack local or method variables are stored on stack | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Interfaces don't have member elements and method definitions that could cause diamond problem. With Java 8, Interfaces have default method definitions. This could have created diamond problem but Java introduced a compile time check for "duplicate default methods" in case same method is derived from multiple interfaces and no definition is overridden by the class. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Because when we say y = x, the value of x is copied to another memory location and then y points to that new memory location. Unlike object references that once assigned point to same object in memory, value is copied in case of variable assignment. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. final when assigned to object references doesn't make them immutable. It means that the references cannot be de-referenced. final when applied to variables means that the value cannot be changed. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. final keyword have meaning only to referenced and not the value. It means that the specified reference cannot be dereferenced. It doesn't control the value assigned to the memory that's being referenced. This is the reason that final object references doesn't mean that the object is immutable but means that the reference cannot be changed to point to new object. In case of primitive types too, when we assign a reference to another, values are passed and not the object reference, and hence a new placeholder is created in memory with the same value. That is why final to that context means that you cannot change the assigned memory and there is no way we can have that memory place have another value. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. 65 to 90 for capital case alphabets 97 to 122 for lower case alphabets | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. 1. We can compare the ascii value of the character. Ascii for Capital case character is from 65 to 90. 2. We can compare to see if lowerCase of the character is not equal to character itself. For example - if character is 'a' the following code new StringBuilder(char).toString().toLowerCase().equals(new StringBuilder(char) will return true and hence char is lower case if character is 'A' the following code new StringBuilder(char).toString().toLowerCase().equals(new StringBuilder(char) will return false and hence char is upper case | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. We can use StringBuilder. StringBuilder accepts char as the argument for it's constructor. new StringBuilder('').toString(); | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. No but we have it in StringBuilder. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. https://github.com/jahe/spring-boot-multiple-datasources | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. 1 2 0 0 0 ArrayIndexOutOfBoundException: 5 As array index starts with 0 and ends with the index of (size - 1), the index 5 is inaccessible for the array and hence will throw the exception. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. 1 2 0 0 0 As arrays are not dynamically expanded , we have declared the array for size 10. As we have only initialized only 2 values , it will print rest as their default values. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class LinkedList { Node start = null; Node head = null; class Node { Integer body; Node nextNode; Node(Integer value) { body = value; } } private void addNodeToEnd(Integer value) { if (start == null) { start = new Node(value); head = start; head.nextNode = null; return; } while (head.nextNode != null) { head = head.nextNode; } head.nextNode = new Node(value); } private void deleteNode(Integer value) { head = start; while (head.nextNode != null) { if(head.nextNode.body == value){ head.nextNode = head.nextNode.nextNode; } head = head.nextNode; } } private void traverse() { head = start; while (head != null) { System.out.println(head.body); head = head.nextNode; } } public static void main(String[] args) { LinkedList ll = new LinkedList(); ll.addNodeToEnd(5); ll.addNodeToEnd(10); ll.addNodeToEnd(15); ll.traverse(); ll.deleteNode(10); ll.traverse(); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class LinkedList { Node start = null; Node head = null; class Node{ Integer body; Node nextNode; Node(Integer value){ body = value; } } private void insertInMiddle(Integer value){ head = start; if(start == null) { start = new Node(value); head = start; head.nextNode = null; return; } while(head.body < value){ if(head.nextNode == null || head.nextNode.body >= value){ Node newNode = new Node(value); newNode.nextNode = head.nextNode; head.nextNode = newNode; break; } head = head.nextNode; } } private void traverse(){ head = start; while(head != null){ System.out.println(head.body); head = head.nextNode; } } public static void main(String[] args){ LinkedList ll = new LinkedList(); ll.insertInMiddle(5); ll.insertInMiddle(10); ll.insertInMiddle(15); ll.insertInMiddle(7); ll.traverse(); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class LinkedList { Node start = null; Node head = null; class Node { Integer body; Node nextNode; Node(Integer value) { body = value; } } private void addNodeToEnd(Integer value) { if (start == null) { start = new Node(value); head = start; head.nextNode = null; return; } while (head.nextNode != null) { head = head.nextNode; } head.nextNode = new Node(value); } private void traverse() { head = start; while (head != null) { System.out.println(head.body); head = head.nextNode; } } public static void main(String[] args) { LinkedList ll = new LinkedList(); ll.addNodeToEnd(5); ll.addNodeToEnd(10); ll.addNodeToEnd(15); ll.traverse(); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Each has it's own advantages Batching requires less resources but may result in loosing whole batch in case of failure whereas concurrency even though is little more expensive in terms of resources but would result in minimal loss in case of failure. In case messages are to be consumed in a particular order, batching them in that order and then consuming them makes better sense. if incoming messages are not continuous , it makes more sense to do concurrency as we need not wait for all messages to form a batch and flush. Though time sensitivity can be added but that would add unnecessary complexity. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. if statements nested within another if or else blocks are called nested if statements. if(condition1) { if(condition2){ } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. if statement is used to do 2 direction branching whereas switch is used to do multi direction branching in Java. Yes we can replace all switch statements with nested if statements. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() ![]() | ||||