Interview Questions and Answers - Order By Newest Q31. TreeMap orders the elements on which field ?
Ans. Keys Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   map   treemap Q32. How TreeMap orders the elements if the Key is a String ?
Ans. As String implements Comparable, It refers to the String compareTo method to identify the order relationship among those elements. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   comparable interface   treemap   compareto Q33. Can we add heterogeneous elements into TreeMap ?
Ans. No, Sorted collections don't allow addition of heterogeneous elements as they are not comparable. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   comparable interface   treemap Q34. Will it create any problem if We add elements with key as user defined object into the TreeMap ?
Ans. It won't create any problem if the objects are comparable i.e we have that class implementing Comparable interface. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   treemap   comparable interface Q35. Can we have null keys in TreeMap ? Core Java
Ans. No, results in exception. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   treemap Asked in 6 Companies Basic   frequent Ans. Yes. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   treemap   yes-no Q37. Which interface TreeMap implements ?
Ans. TreeMap implements NavigableMap, SortedMap, Serializable and Clonable. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   treemap Q38. What is lazy fetching in Hibernate ? Hibernate
Ans. Lazy fetching is the technique of not loading the child objects when parent objects are loaded. By default Hibernate does not load child objects. One can specify whether to load them or not while doing the association. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   lazy fetching   architecture Asked in 11 Companies   frequent Try 2 Question(s) Test Q39. What will be the output of this code ? Set mySet = new TreeSet(); mySet.add("4567"); mySet.add("5678"); mySet.add("6789"); for(String s: mySet){ System.out.println(s); }
Ans. 4567 5678 6789 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   set   treeset   coding   code Q40. public class BuggyBread1{
public static void main (String args[]) {
Set<String> mySet = new TreeSet<String>();
mySet.add(""1"");
mySet.add(""2"");
mySet.add(""111"");
for(String d: mySet){
System.out.println(d);
}
}
} Core Java
Ans. 1
111
2
TreeSet maintains the elements in the ascending order which is identified by the compareTo method. compareTo method in String has been defined such that it results in the natural alphabetic Order. Here the elements in the TreeSet are of String and not of Integer. In String Natural Order, 111 comes before 2 as ascii of 1st character first determines the order. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   code   coding   set   treeset   string   integer Q41. public class BuggyBread1{
public static void main (String args[]) {
Set<Integer> mySet = new TreeSet<Integer>();
mySet.add(1);
mySet.add(2);
mySet.add(111);
for(Integer d: mySet){
System.out.println(d);
}
}
} Core Java
Ans. 1
2
111
TreeSet maintains the elements in the ascending order which is identified by the compareTo method. compareTo method in Integer has been defined such that it results in the natural numerical Order. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   code   coding   set   treeset Q42. How can we see Dependencies for the project and where exactly they are defined ? Maven
Ans. Using mvn dependency:tree Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  maven   maven repository   maven dependencies   dependency tree Q43. How many elements will be there in TreeSet after the last line and Why ? TreeSet set = new TreeSet(); set .add(new String("abc")); set .add(new String("abc")); Core Java
Ans. One. As we haven't specified the type of TreeSet, it being evaluated with the first element insertion. Once it's identified that it's of type String and as no comparator has been defined, the comparison is done using the String compareTo method. String compareTo method compares the elements by the content / value. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   set   treeset   string   compareto   coding   code Q44. Which takes more memory - float or Float ? Core Java
Ans. float is a native data type whereas Float is a class. A Float object will always take more memory than float variable as there are metadata overheads with the objects. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   data type   float Asked in 3 Companies basic   frequent Q45. Which tree is used to implement TreeMap in Java?
Ans. Red Black Tree Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   treemap   map expert Q46. If we add Enum constants to a sorted collection ( Treemap , TreeSet ), What will be the order in which they will be maintained ? a. Sorted Collection wont maintain them in any order. b. Insertion Order c. Order in which constants are declared. d. Natural Sorting Order.
Ans. Order in which constants are declared. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  enum   collections   sorted collections   treemap   treeset   compareto   comparable   java Q47. Write code to sort elements of a set
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=952 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  set  collections  sorting  treeset  code  coding Q48. Difference between Array and ArrayList ? Core Java
Ans. <a href="http://javahungry.blogspot.com/2015/03/difference-between-array-and-arraylist-in-java-example.html" rel="nofollow">http://javahungry.blogspot.com/2015/03/difference-between-array-and-arraylist-in-java-example.html</a> Sample Code for ArrayList Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  array  arraylist Asked in 11 Companies basic   frequent Q49. What is the problem with this code
double x=10.04;
int a = x;
Ans. It will give an error saying 'cannot convert from double to int' Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q50. What are the different ways to handle an exception ? Core Java
Ans. 1. Wrap the desired code in try block followed by a catch / finally to catch the exception
2. Declare the throws clause with exceptions that the code is expected to throw as an indication to the calling method to take care of it. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  exception handling Asked in 4 Companies Try 1 Question(s) Test Q51. What are the core OOPs concepts ? Core Java
Ans. Abstraction, Encapsulation, Polymorphism , Composition and Inheritance Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  core oops concepts Asked in 65 Companies basic   frequent Q52. Write code to check if a Binary tree is symmetrical Algorithm
This question was recently asked at 'Amazon'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  binary tree Asked in 1 Companies Ans. Graph contain cycles whereas Trees cannot. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  graph  trees  data structures  tree vs graph This question was recently asked at 'Amazon'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Tree  Data structures Asked in 1 Companies Q55. What is difference between clustered and non clustered index? Database
Ans. The clustered index determines how the data is stored in the rows of a table.The non-clustered index stores the data at a single place and the indexes are stored at another place. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  clustered vs non clustered index  index  database index Asked in 1 Companies Ans. Oracle having following types of joins these are also called 8i joins. There are:
1. Equi (or) Inner join
2. Non Equi join
3.Self join
4.Outer join
Oracle also support the 9i (or) ANSI standard joins.There are:
1.Inner join
2.Left outer join
3.Right outer join
4.Full outer join
5.Natural join Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  sql joins  sql Asked in 2 Companies Q57. Write a method that returns maximum depth of a tree ? Algorithm
This question was recently asked at 'One Click Retail'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  tree  data structure  maximum depth of tree Asked in 1 Companies Q58. What is the difference between TreeSet and TreeMap ? Core Java
Ans. TreeSet contains only values as elements whereas TreeMap contains Key value pairs. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  reeMap  TreeSet  Collections  sorted collection Asked in 1 Companies   rare Q59. How to sort objects based on one of the field ? Core Java
Ans. Using comparable and comparator and sorted collections like TreeSet or TreeMap.
or
use stream api from java 8 onwards which internally refers to comparable and comparator through lambda expressions Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  sort  sorting  comprator  comparable  treeset  treemap  sorting collections Asked in 1 Companies Basic   frequent Q60. What are the disadvantages of binary search trees? Algorithm
This question was recently asked at 'ServiceNow'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  binary search tree Asked in 1 Companies