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. Enums in Java is a facility to have objects upfront and use them as constants. Even if such a facility is not available , a workaround could be achieved. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Collections in Java is nothing but a library implementation for data structures and algorithm. If it's not available , we might have to include some other library or provide our own implementation. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. It depends on how we are serializing. The Serialization API doesn't worry about private variables and convert it into binary representation. If we are using a library to map it to JSON / XML using XML Mappers, it may create trouble. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. At that bucket, it will form a linked list depending on what equals method evaluates for that object. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. List is an interface whereas ArrayList is an implementation of List. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Base Class is a relative term. For example - Class Vehicle is a Base class of Class Car. Even though Base class is derived in this case , there is no restriction on instantiation of Vehicle class. Abstract Class is a class that is meant only to be a Base Class and not allowed to be instantiated. Abstract Class is a Base Class that isn't allowed to be instantiated and is only meant for carrying definition to derived class and help participate in runtime polymorphism. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Abstract Class is a class that's only allowed to be a Base class for it's usage. It can never be instantiated on it's own. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Yes, an abstract class can extend another class. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. object / native type returned can only be one but an object can comprise of a array , collection or a group of different value types. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Default size is 10. Regard how size will increase. Inside add() method there is one method called ensureCapacity() which will check list has enough size available. This ensureCapacity() method if found size of list need to increase then it will call grow() method which will create new list of extra size and copy existing list data to new one and return. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Inline functions , just like C++ Macros is an optimized technique used by compiler to reduce the execution time. If the function is working on pre identified values ( which aren't resolved at runtime ), the function can execute the method and evaluate the outcome at compile time only instead of making a function call at runtime. In Java, the optimizations are usually done at the runtime or JVM level. At runtime, the JVM perform some analysis to determine which methods to inline. Java compiler would never inline any method and there is no way in java for the developer to explicitly define inlining of methods as it's take intrinsically care of during runtime only. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. No. They are never inherited and therefore are not subject to hiding or overriding. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. No. When we declare a method static, it means that "this belongs to class as whole and not particular instance". The whole purpose of constructor is to initialize a object and hence there is no sense having static constructor. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. We can return value for one problem solving or computation and set the value for other in some member element. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. str.equals("") this statement will throw NullPointerException if str is null where as "".equals(str) works fine even if str is null | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. CustomArrayList myarrayList = new CustomArrayList(); myarrayList.add("Value 1"); myarrayList.add("Value 2"); myarrayList.add("Value 3"); for (String string : myarrayList) { System.out.println(string); } package sample.utils; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class CustomArrayList implements Iterable { private ArrayList mylist = new ArrayList(); public void add(T t) { this.mylist.add(t); } @Override public Iterator iterator() { return new CustomIterator(mylist); } class CustomIterator implements Iterator { private int indexPosition = 0; private List internalList; public CustomIterator(List internalList) { this.internalList = internalList; } @Override public boolean hasNext() { if (internalList.size() >= indexPosition 1) { return true; } return false; } @Override public E next() { E val = internalList.get(indexPosition); indexPosition ; return val; } } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. All threads share a common heap. Each thread has a private stack, which it can quickly add and remove items from. This makes stack based memory fast, but if you use too much stack memory, as occurs in infinite recursion, you will get a stack overflow. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. If we do not mention, Cloneable Interface to the Class which we want to Clone then we get this exception, only if we try to clone an object Like: public class TestClone{ @Override protected Object clone() throws CloneNotSupportedException { return super.clone(); } } In Main, You try to do: TestClone clone = new TestClone(); TestClone clone2 = (TestClone) clone.clone(); You will get CloneNotSupportedException. Just add -> public class TestClone implements Cloneable { and things are fixed. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Yes, an abstract class can have a constructor in Java. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. No HashMap isn't synchronized. ConcurrentHashMap and Hashtable are synchronized. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Yes, ConcurrentHashMap is synchronized. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. "equals" is the method of object class which is supposed to be overridden to check object equality. x.equals(y) means the references x and y are holding objects that are equal. The compareTo() method is used for comparing two objects in Java. It is usually defined for the classes whose objects needs to be ordered through Comparable interface or need to be part of an ordered collection like TreeSet or TreeMap. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. "equals" is the method of object class which is supposed to be overridden to check object equality. x.equals(y) means the references x and y are holding objects that are equal with the equality defined by the definition of equals method. Hashcode is used for bucketing in Hash implementations like HashMap, HashTable, HashSet etc. The value received from hashcode() is used as bucket number for storing elements. This bucket number is the address of the element inside the set/map. when you do contains() then it will take the hashcode of the element, then look for the bucket where hashcode points to and if more than 1 element is found in the same bucket (multiple objects can have the same hashcode) then it uses the equals() method to evaluate if object are equal, and then decide if contain() is true or false, or decide if element could be added in the set or not. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. "equals" method is the method of object class that needs to be overridden to check object equality. This is not specific to any class like String. equalsignorecase is the method of String class that provides a definition that ignores the case of characters during comparison. The only difference between them in String class is that the equals() methods considers the case while equalsIgnoreCase() methods ignores the case during comparison. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. 1. Creating a class helps in specifying operations on the Strings like length , sub string , concatenation etc. 2. It acts as a Wrapper class for "Array of Characters" and hence facilitates it's usage in collections, assignment to null. 3. Immutability of String objects facilitates in reuse , security and caching. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() ![]() | ||||