YouTube Icon

Interview Questions.

Top 100+ Java.util Interview Questions And Answers - May 31, 2020

fluid

Top 100+ Java.util Interview Questions And Answers

Question 1. Which Standard Collection Classes Implements A Dynamic Array?

Answer :

ArrayList magnificence implements a dynamic array by means of extending AbstractList elegance.

Question 2. Which Method Can Be Used To Increase The Capacity Of Arraylist Object Manually?

Answer :

When we add an detail, the potential of ArrayList item will increase mechanically, but we will increase it manually to designated period x by the usage of feature ensureCapacity(x);

Adv Java Interview Questions
Question three. Which Method Is Used To Reduce The Capacity Of An Arraylist Object?

Answer :

trimTosize() is used to lessen the dimensions of the array that underlines an ArrayList object.

Question four. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Arraylist 
three. Public Static Void Main(string Args[]) 
four. Arraylist Obj = New Arraylist();
five. Obj.Add("a");
6. Obj.Add("b");
7. Obj.Add("c");
8. Obj.Add(1, "d");
nine. System.Out.Println(obj);
10. 
11. 

Answer :

obj is an object of class ArrayList therefore it is an dynamic array which could boom and decrease its size. Obj.Upload(“X”) provides to the array detail X and obj.Add(1,”X”) provides detail x at index role 1 in the list, Hence obj.Add(1,”D”) stores D at index function 1 of obj and shifts the preceding price saved at that position by 1.

Output:

$ javac Arraylist.Java
$ java Arraylist
[A, D, B, C]

Adv Java Tutorial
Question five. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Output 
3. Public Static Void Main(string Args[]) 
4. Arraylist Obj = New Arraylist();
five. Obj.Upload("a");
6. Obj.Ensurecapacity(3);
7. System.Out.Println(obj.Size());
8. 
Nine. 

Answer :

Although obj.EnsureCapacity(3); has manually multiplied the ability of obj to three but the fee is saved only at index zero, consequently obj.Length() returns the full quantity of elements saved within the obj i:e 1, it has nothing to do with ensureCapacity().

Output:

$ javac Output.Java
$ java Output
1

J2EE Interview Questions
Question 6. What Is The Output Of This Program?

1. Class Output 
2. Public Static Void Main(string Args[]) 
three. Arraylist Obj = New Arraylist();
4. Obj.Add("a");
five. Obj.Upload("d");
6. Obj.Ensurecapacity(3);
7. Obj.Trimtosize();
eight. System.Out.Println(obj.Size());
9. 
10. 

Answer :

trimTosize() is used to reduce the dimensions of the array that underlines an ArrayList object.

Output:

$ javac Output.Java
$ java Output
2

Question 7. Which Of These Classes Implements Set Interface?

Answer :

HashSet and TreeSet implements Set interface wherein as LinkedList and ArrayList implements List interface.

J2EE Tutorial Core Java Interview Questions
Question eight. Which Of These Methods Can Be Used To Delete The Last Element In A Linkedlist Object?

Answer :

removeLast() and removeFirst() techniques are used to get rid of factors in give up and starting of a connected listing.

Question 9. Which Method Is Used To Change An Element In A Linkedlist Object?

Answer :

An element in a LinkedList object may be changed by way of first the use of get() to achieve the index or vicinity of that object and the passing that area to approach set() together with its new cost.

JSP Interview Questions
Question 10. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Linkedlist 
three. Public Static Void Main(string Args[]) 
4. Linkedlist Obj = New Linkedlist();
5. Obj.Upload("a");
6. Obj.Add("b");
7. Obj.Upload("c");
8. Obj.Addfirst("d");
nine. System.Out.Println(obj);
10. 
Eleven. 

Answer :

obj.AddFirst(“D”) approach is used to add ‘D’ to the start of a LinkedList item obj.

Output:

$ javac Linkedlist.Java
$ java Linkedlist
[D, A, B, C]

Core Java Tutorial
Question eleven. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Output 
3. Public Static Void Main(string Args[]) 
four. Hashset Obj = New Hashset();
five. Obj.Add("a");
6. Obj.Upload("b");
7. Obj.Add("c");
eight. System.Out.Println(obj + " " + Obj.Length());
nine. 
10. 

Answer :

HashSet obj creates an hash item which implements Set interface, obj.Size() gives the wide variety of elements saved in the item obj which in this example is 3.

Output:

$ javac Output.Java
$ java Output
[A, B, C] 3

Oracle 11g Interview Questions
Question 12. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Output 
3. Public Static Void Main(string Args[]) 
4. Treeset T = New Treeset();
five. T.Upload("three");
6. T.Add("nine");
7. T.Add("1");
eight. T.Add("four");
nine. T.Upload("8");
10. System.Out.Println(t);
eleven. 
12. 

Answer :

TreeSet magnificence uses set to save the values added with the aid of feature upload in ascending order the usage of tree for garage

Output:

$ javac Output.Java
$ java Output
[1, 3, 4, 8, 9]

Adv Java Interview Questions
Question 13. Which Classes Provide Implementation Of Map Interface?

Answer :

AbstractMap, WeakHashMap, HashMap and TreeMap provide implementation of map interface.

JSP Tutorial
Question 14. Which Methods Can Be Used To Obtain Set Of All Keys In A Map?

Answer :

keySet() strategies is used to get a fixed containing all of the keys used in a map. This approach offers set view of the keys in the invoking map.

Question 15. Which Method Is Used Add An Element And Corresponding Key To A Map?

Answer :

Maps revolve round  fundamental operations – get() and positioned(). To place a price right into a map, use placed(), specifying the important thing and the cost. To obtain a cost, call get() , passing the important thing as an issue. The fee is returned.

Java-Springs Interview Questions
Question sixteen. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Maps 
three. Public Static Void Main(string Args[]) 
4. Hashmap Obj = New Hashmap();
five. Obj.Placed("a", New Integer(1));
6. Obj.Positioned("b", New Integer(2));
7. Obj.Put("c", New Integer(3));
eight. System.Out.Println(obj.Keyset());
nine. 
10. 

Answer :

keySet() technique returns a fixed containing all the keys used inside the invoking map. Here keys are characters A, B & C. 1, 2, three are the values given to those keys.

Output:

$ javac Maps.Java
$ java Maps
[A, B, C]

Oracle 11g Tutorial
Question 17. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Maps 
three. Public Static Void Main(string Args[]) 
four. Hashmap Obj = New Hashmap();
five. Obj.Put("a", New Integer(1));
6. Obj.Positioned("b", New Integer(2));
7. Obj.Placed("c", New Integer(three));
8. System.Out.Println(obj.Get("b"));
9. 
10. 

Answer :

obj.Get(“B”) technique is used to reap the cost associated with key “B”, that's 2.

Output:

$ javac Maps.Java
$ java Maps
2

JMS(Java Message Service) Interview Questions
Question 18. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Maps 
3. Public Static Void Main(string Args[]) 
four. Treemap Obj = New Treemap();
five. Obj.Positioned("a", New Integer(1));
6. Obj.Placed("b", New Integer(2));
7. Obj.Positioned("c", New Integer(three));
8. System.Out.Println(obj.Entryset());
9. 
10. 

Answer :

obj.EntrySet() technique is used to obtain a fixed that includes the entries in the map. This technique provides set view of the invoking map.

Output:

$ javac Maps.Java
$ java Maps
[A=1, B=2, C=3]

J2EE Interview Questions
Question 19. Which Classes Implements Set Interface?

Answer :

HashSet and TreeSet implements Set interface wherein as LinkedList and ArrayList implements List interface.

Java-Springs Tutorial
Question 20. Which Method Is Used To Make All Elements Of An Equal To Specified Value?

Answer :

fill() method assigns a price to all of the elements in an array, in other phrases it fills the array with exact fee.

MYSQL DBA Interview Questions
Question 21. Which Methods Can Be Used To Search An Element In A List?

Answer :

binaryserach() method uses binary search to discover a special value. This approach must be applied to looked after arrays.

Question 22. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Arraylist 
three. Public Static Void Main(string Args[]) 
four. Arraylist Obj1 = New Arraylist();
five. Arraylist Obj2 = New Arraylist();
6. Obj1.Upload("a");
7. Obj1.Add("b");
eight. Obj2.Upload("a");
9. Obj2.Add(1, "b");
10. System.Out.Println(obj1.Equals(obj2));
11. 
12. 

Answer :

obj1 and obj2 are an item of class ArrayList hence it's miles a dynamic array which could growth and reduce its size. Obj.Add(“X”) adds to the array element X and obj.Add(1,”X”) adds element x at index function 1 in the list, Both the items obj1 and obj2 comprise identical elements i:e A & B for this reason obj1.Equals(obj2) method returns true.

Output:

$ javac Arraylist.Java
$ java Arraylist
real

Java Tutorial
Question 23. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Array 
three. Public Static Void Main(string Args[]) 
four. Int Array[] = New Int [5];
five. For (int I = five; I > 0; I--)
6. Array[5 - I] = I;
7. Arrays.Sort(array);
eight. For (int I = zero; I < 5; ++i)
9. System.Out.Print(array[i]);;
10. 
11. 

Answer :

Arrays.Sort(array) method sorts the array into 1,2,3,4,5.

Output:

$ javac Array.Java
$ java Array
12345

Java applet Interview Questions
Question 24. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Array 
3. Public Static Void Main(string Args[]) 
4. Int Array[] = New Int [5];
5. For (int I = 5; I > zero; I--)
6. Array[5-i] = I;
7. Arrays.Fill(array, 1, 4, eight);
8. For (int I = zero; I < five ; I++)
9. System.Out.Print(array[i]);
10. 
Eleven. 

Answer :

array became containing five,4,3,2,1 however whilst method Arrays.Fill(array, 1, four, 8) is called it fills the index region beginning with 1 to four by means of cost 8 therefore array turns into five,8,8,eight,1.

Output:

$ javac Array.Java
$ java Array
58881

Core Java Interview Questions
Question 25. Which Class Object Can Be Used To Form A Dynamic Array?

Answer :

Vectors are dynamic arrays, it consists of many legacy strategies that aren't part of series framework, and as a result those strategies are not found in ArrayList. But each are used to shape dynamic arrays.

Java 8 Tutorial
Question 26. What Are Legacy Classes?

Answer :

Stack, Hashtable, Vector, Properties and Dictionary are legacy instructions.

Java Interview Questions
Question 27. Which Methods Is Used To Add Elements In Vector At Specific Location?

Answer :

addElement() is used to add facts inside the vector, to obtain the statistics we use elementAt() and to first and final element we use firstElement() and lastElement() respectively.

JSP Interview Questions
Question 28. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Vector 
3. Public Static Void Main(string Args[]) 
4. Vector Obj = New Vector(four,2);
five. Obj.Addelement(new Integer(3));
6. Obj.Addelement(new Integer(2));
7. Obj.Addelement(new Integer(5));
eight. System.Out.Println(obj.Elementat(1));
9. 
10. 

Answer :

obj.ElementAt(1) returns the price stored at index 1, that's 2.

Output:

$ javac vector.Java
$ java vector
2

Question 29. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Vector 
three. Public Static Void Main(string Args[]) 
4. Vector Obj = New Vector(four,2);
5. Obj.Addelement(new Integer(three));
6. Obj.Addelement(new Integer(2));
7. Obj.Addelement(new Integer(5));
8. Obj.Removeall(obj);
9. System.Out.Println(obj.Isempty());
10. 
11. 

Answer :

first of all factors three, 2, five are entered within the vector obj, but when obj.RemoveAll(obj); is completed all the factors are deleted and vector is empty, for this reason obj.IsEmpty() returns actual.

Output:

$ javac vector.Java
$ java vector
actual

Java 8 Interview Questions
Question 30. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Stack 
3. Public Static Void Main(string Args[]) 
four. Stack Obj = New Stack();
five. Obj.Push(new Integer(3));
6. Obj.Push(new Integer(2));
7. Obj.Pop();
eight. Obj.Push(new Integer(5));
nine. System.Out.Println(obj);
10. 
Eleven. 

Answer :

push() and pop() are general capabilities of the magnificence stack, push() inserts inside the stack and pop eliminates from the stack. 3 & 2 are inserted the use of push() the pop() is used which removes 2 from the stack alternatively push is used to insert five therefore stack includes elements 3 & five.

Output:

$ javac stack.Java
$ java stack
[3, 5]

Question 31. Which Class Object Uses Key To Store Value?

Answer :

Dictionary, Map & Hashtable all put in force Map interface for this reason all of them uses keys to shop cost inside the item.

Question 32. Which Is The Interface Of Legacy Is Implemented By Hash-desk And Dictionary Classes?

Answer :

Dictionary, Map & Hashtable all put in force Map interface for this reason they all makes use of keys to store fee within the object.

Java Programmer Interview Questions
Question 33. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Hashtable 
three. Public Static Void Main(string Args[]) 
four. Hashtable Obj = New Hashtable();
five. Obj.Put("a", New Integer(3));
6. Obj.Positioned("b", New Integer(2));
7. Obj.Put("c", New Integer(eight));
eight. System.Out.Print(obj.Contains(new Integer(five)));
nine. 
10. 

Answer :

Hashtable object obj carries values 3, 2, eight when obj.Carries(new Integer(5)) is completed it searches for 5 within the hashtable since it isn't present fake is returned.

Output:

$ javac hashtable.Java
$ java hashtable
false

Oracle 11g Interview Questions
Question 34. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Hashtable 
three. Public Static Void Main(string Args[]) 
4. Hashtable Obj = New Hashtable();
five. Obj.Placed("a", New Integer(3));
6. Obj.Positioned("b", New Integer(2));
7. Obj.Put("c", New Integer(8));
eight. System.Out.Print(obj.Tostring());
9. 
10. 

Answer :

obj.ToString returns String equivalent of the hashtable, which can also be received via surely writing System.Out.Print(obj); as print gadget routinely coverts the obj to string equivalent.

Output:

$ javac hashtable.Java
$ java hashtable
A=three, C=8, B=2

Question 35. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Properties 
3. Public Static Void Main(string Args[]) 
4. Properties Obj = New Properties();
five. Obj.Put("ab", New Integer(3));
6. Obj.Placed("bc", New Integer(2));
7. Obj.Positioned("cd", New Integer(eight));
eight. System.Out.Print(obj.Keyset());
9. 
10. 

Answer :

obj.KeySet() returns a hard and fast containing all the keys utilized in properties object, right here obj incorporates keys AB, BC, CD therefore obj.KeySet() returns [AB, BC, CD].

Output:

$ javac properties.Java
$ java properties
[AB, BC, CD]

Question 36. Which Class Object Has Architecture Similar To That Of Array?

Answer :

Bitset elegance creates a unique type of array that holds bit values. This array can boom in size as wanted.

Java-Springs Interview Questions
Question 37. What Is A Method Of Class Date Which Is Used To Search Weather Object Contains A Date Before The Specified Date?

Answer :

earlier than() returns true if the invoking Date object incorporates a date that is earlier than one distinctive by way of date, otherwise it returns false.

Question 38. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Bitset 
3. Public Static Void Main(string Args[]) 
4. Bitset Obj = New Bitset(five);
5. For (int I = 0; I < 5; ++i)
6. Obj.Set(i);
7. Obj.Clear(2);
8. System.Out.Print(obj.Length() + " " + Obj.Length());
nine. 
10. 

Answer :

obj.Length() returns the period allotted to item obj at time of initialization and obj.Size() returns the scale of cutting-edge object obj, each BitSet detail is given 16 bits consequently the size is 4 * 16 = 64, while period remains five.

Output:

$ javac Bitset.Java
$ java Bitset
5 64

Question 39. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Bitset 
3. Public Static Void Main(string Args[]) 
4. Bitset Obj1 = New Bitset(five);
5. Bitset Obj2 = New Bitset(10);
6. For (int I = zero; I < five; ++i)
7. Obj1.Set(i);
eight. For (int I = 3; I < thirteen; ++i)
9. Obj2.Set(i);
10. Obj1.And(obj2);
eleven. System.Out.Print(obj1);
12. 
13. 

Answer :

obj1.And(obj2) returns an BitSet object which incorporates factors not unusual to each the item obj1 and obj2 and shops this BitSet in invoking object this is obj1. Hence obj1 incorporates three & four.

Output:

$ javac Bitset.Java
$ java Bitset
3, four

Question forty. What Is The Output Of This Program?

1. Import Java.Util.*;
2. Class Bitset 
3. Public Static Void Main(string Args[]) 
four. Bitset Obj = New Bitset(5);
5. For (int I = zero; I < 5; ++i)
6. Obj.Set(i);
7. Obj.Clean(2);
eight. System.Out.Print(obj);
nine. 
10. 

Answer :

Output:

$ javac Bitset.Java
$ java Bitset
zero, 1, 3, four

JMS(Java Message Service) Interview Questions




CFG