More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
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.
Help us improve. Please let us know the company, where you were asked this question :
Q1114. Does an ArrayList allow elements of different types ? If not, Why the following code works
List list1 = new ArrayList<>();
list1.add(1);
list1.add("1");
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.
Help us improve. Please let us know the company, where you were asked this question :
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
}
}
}
Help us improve. Please let us know the company, where you were asked this question :
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.
Help us improve. Please let us know the company, where you were asked this question :
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.
Help us improve. Please let us know the company, where you were asked this question :
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.
Help us improve. Please let us know the company, where you were asked this question :
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.
Help us improve. Please let us know the company, where you were asked this question :
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.
Help us improve. Please let us know the company, where you were asked this question :
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.
Help us improve. Please let us know the company, where you were asked this question :
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.
Help us improve. Please let us know the company, where you were asked this question :
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.
Help us improve. Please let us know the company, where you were asked this question :
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.
Help us improve. Please let us know the company, where you were asked this question :
Ans. the web URI starts with the protocol which is http in this case, javasearch.buggybread.com is the domain in this case which is a subdomain of buggybread.com, /InterviewQuestions is the path, questionSearch.php is the resource, searchOption and keyword are query params.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Its 2048 and Yes it applies to get request but not POST. As in Get Request , elements are passed as part of the url, this limit applies to Get requests.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Array List works on Array and when we add an element in middle of the list, Array List need to update the index of all subsequent elements. I the capacity is full, it even may need to move the whole list to a new memory location . Linked List works on Double linked list algorithm and all it has to do is to adjust the address of the previous and next elements.
Help us improve. Please let us know the company, where you were asked this question :