AmbitionBox
Discover Best Places to work in India
Discover best places to work
Compare & find best workplace
Bring your workplace to life
Highlight your company's perks
Read reviews for 6L+ companies
Rate your former or current company
Discover salaries for 8L+ companies
Calculate your take home salary
Check your market value
Help other jobseekers
Read interviews for 90K+ companies
Interviews questions for 1K+ colleges
Contribute your interview questions
Java Programming
Consider the following code fragment:
Integer w1 = new Integer(2);
Integer w2 = new Integer(2);
if(w1 == w2)
{
System.out.println("w1 is equal to w2!");
}
else
System.out.println("w1 is not equal to w2!");
What is the output of this code?
A. Compiler error
B. Runtime error
C. w1 is equal to w2!
D. w1 is not equal to w2!
1. ArrayList list = new ArrayList();
2. list.add(new ObjectOne());
3. list.add(new ObjectOne());
4. list.add(new ObjectOne());
5. Collections.sort(list);
6. class ObjectOne {
7. private int x = 0;
8. private int y = 0;
9. }
What is the output of this code fragment?
A. Compiler error at line 5
B. Runtime error at line 5
C. Compiler error at line 3
D. Runtime error at line 3
Which of the following is an illegal line of code?
A. HashMap hmap = new HashMap();
B. ArrayList list = new ArrayList();
C. List list2 = new ArrayList ();
D. All of the above
Which of the following collections can you use to store key-value pairs and is thread safe?
A. HashTable
B. HashMap
C. TreeMap
D. Vector
1. import java.io.*;
2. class MyClass{
3. public static void main(String[] args) throws IOException {
4. NumberStore ns = new NumberStore();
5. System.out.println("The number: " + ns.getInteger());
6. ns.setInteger(10);
7. System.out.println("The number: " + ns.getInteger());
8. }
10. class NumberStore {
11. int i =5;
12. public void setInteger(Integer x){
13. System.out.println("The number passed in is: " + x);
14. i = x;
15. }
16. public int getInteger( ){
17. return i;
18. }
19.}
What is the output?
A. Compiler error at line 6
B. Execution error at line 13
D. The number:5
The number passed in is:10
The number: 10
2. list.add(new Integer(1));
3. list.add(new Integer(2));
4. list.add(new Integer(3));
5. Iterator itr = list.iterator();
6. for(Integer wij:list){
7. System.out.println("number: " + wij);
What is the output from this code fragment?
A. number: 1
number: 2
number: 3
B. Compiler error at line 5
C. Compiler error at line 6
D. Runtime error
Which of the following statements is false?
A. A set is a collection that does not allow duplicates.
B. A map can store duplicate values.
C. A list is a collection that is ordered by index.
D. A list is a collection that cannot have duplicates.
Which of the following statements is not true about the hashcode?
A. The hashcode values of two equal objects must be equal.
B. The hashcode values of two unequal objects must be unequal.
C. If the hashcode values of two unequal objects are always unequal, it improves the performance.
D. A function that always returns a constant is not a very efficient function.
1. int i = 5;
2. printIt(i);
3. void printIt(Integer wi) {
4. int j = wi;
5. System.out.println("The value is: " + j);
6. }
A. The value is: 5
B. Compiler error at line 3
C. Compiler error at line 2
Which of the following classes implements the java.util.List interface?
A. Java.util.HashMapTable
B. Java.util.LinkedList
C. Java.util.HashTable
D. Java.util.OrderedList
Join India’s largest community to research company culture
Are you a student or working professional?
Student/Never worked
I am a student/I have never worked
Working Professional
I am working/I have worked before
What are your preferred job locations?
Popular Cities
Other Cities
Follow your preferred designations/job profiles
Suggestions based on your job profile
vs
Similar Companies