1. Which of these class object uses key to store value?
a) Dictionary
b) Map
c) Hashtable
d) All if the mentioned
2. Which of these method is used to insert value and its key?
a) put()
b) set()
c) insertElement()
d) addElement()
3. Which of these is the interface of legacy is implemented by Hashtable and Dictionary classes?
a) Map
b) Enumeration
c) HashMap
d) Hashtable
4. Which of these is a class which uses String as a key to store the value in object?
a) Array
b) ArrayList
c) Dictionary
d) Properties
5. Which of these methods is used to retrieve the elements in properties object at specific location?
a) get()
b) Elementat()
c) ElementAt()
d) getProperty()
6. What is the output of this program?
1.import java.util.*;
2.class hashtable {
3. public static void main(String args[]) {
4. Hashtable obj = new Hashtable();
5. obj.put(“A”, new Integer(3));
6. obj.put(“B”, new Integer(2));
7. obj.put(“C”, new Integer(8));
8. System.out.print(obj.contains(new Integer(5)));
9. }
10.}
a) 0
b) 1
c) true
d) false
7. What is the output of this program?
1.import java.util.*;
2.class hashtable {
3. public static void main(String args[]) {
4. Hashtable obj = new Hashtable();
5. obj.put(“A”, new Integer(3));
6. obj.put(“B”, new Integer(2));
7. obj.put(“C”, new Integer(8));
8. obj.clear();
9. System.out.print(obj.size());
10. }
11.}
a) 0
b) 1
c) 2
d) 3
8. What is the output of this program?
1.import java.util.*;
2.class hashtable {
3. public static void main(String args[]) {
4. Hashtable obj = new Hashtable();
5. obj.put(“A”, new Integer(3));
6. obj.put(“B”, new Integer(2));
7. obj.put(“C”, new Integer(8));
8. obj.remove(new String(“A”));
9. System.out.print(obj);
10. }
11.}
a) {C=8, B=2}
b) [C=8, B=2]
c) {A=3, C=8, B=2}
d) [A=3, C=8, B=2]
9. What is the output of this program?
1.import java.util.*;
2.class hashtable {
3. public static void main(String args[]) {
4. Hashtable obj = new Hashtable();
5. obj.put(“A”, new Integer(3));
6. obj.put(“B”, new Integer(2));
7. obj.put(“C”, new Integer(8));
8. System.out.print(obj.toString());
9. }
10.}
a) {C=8, B=2}
b) [C=8, B=2]
c) {A=3, C=8, B=2}
d) [A=3, C=8, B=2]
10. 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();
5. obj.put(“AB”, new Integer(3));
6. obj.put(“BC”, new Integer(2));
7. obj.put(“CD”, new Integer(8));
8. System.out.print(obj.keySet());
9. }
10.}
a) {AB, BC, CD}
b) [AB, BC, CD]
c) [3, 2, 8]
d) {3, 2, 8}
11. Which of these is a process of writing the state of an object to a byte stream?
a) Serialization
b) Externalization
c) File Filtering
d) All of the mentioned
12. Which of these process occur automatically by java run time system?
a) Serialization
b) Garbage collection
c) File Filtering
d) All of the mentioned
13. Which of these is an interface for control over serialization and deserialization?
a) Serializable
b) Externalization
c) FileFilter
d) ObjectInput
14. Which of these interface extends DataOutput interface?
a) Serializable
b) Externalization
c) ObjectOutput
d) ObjectInput
15. Which of these is a method of ObjectOutput interface used to finalize the output state so that any buffers are cleared?
a) clear()
b) flush()
c) fflush()
d) close()
16. Which of these is method of ObjectOutput interface used to write the object to input or output stream as required?
a) write()
b) Write()
c) StreamWrite()
d) writeObject()
17. What is the output of this program?
1.import java.io.*;
2.class serialization {
3. public static void main(String[] args) {
4. try {
5. Myclass object1 = new Myclass(“Hello”, -7, 2.1e10);
6. FileOutputStream fos = new FileOutputStream(“serial”);
7. ObjectOutputStream oos = new ObjectOutputStream(fos);
8. oos.writeObject(object1);
9. oos.flush();
10. oos.close();
11. }
12. catch(Exception e) {
13. System.out.println(“Serialization” + e);
14. System.exit(0);
15. }
16. try {
17. Myclass object2;
18. FileInputStream fis = new FileInputStream(“serial”);
19. ObjectInputStream ois = new ObjectInputStream(fis);
20. object2 = (Myclass)ois.readObject();
21. ois.close();
22. System.out.println(object2);
23. }
24. catch (Exception e) {
25. System.out.print(“deserialization” + e);
26. System.exit(0);
27. }
28. }
29.}
30.class Myclass implements Serializable {
31. String s;
32. int i;
33. double d;
34. Myclass (String s, int i, double d){
35. this.d = d;
36. this.i = i;
37. this.s = s;
38. }
39.}
a) s=Hello; i=-7; d=2.1E10
b) Hello; -7; 2.1E10
c) s; i; 2.1E10
d) Serialization
18. What is the output of this program?
1.import java.io.*;
2.class serialization {
3. public static void main(String[] args) {
4. try {
5. Myclass object1 = new Myclass(“Hello”, -7, 2.1e10);
6. FileOutputStream fos = new FileOutputStream(“serial”);
7. ObjectOutputStream oos = new ObjectOutputStream(fos);
8. oos.writeObject(object1);
9. oos.flush();
10. oos.close();
11. }
12. catch(Exception e) {
13. System.out.println(“Serialization” + e);
14. System.exit(0);
15. }
16. try {
17. int x;
18. FileInputStream fis = new FileInputStream(“serial”);
19. ObjectInputStream ois = new ObjectInputStream(fis);
20. x = ois.readInt();
21. ois.close();
22. System.out.println(x);
23. }
24. catch (Exception e) {
25. System.out.print(“deserialization”);
26. System.exit(0);
27. }
28. }
29.}
30.class Myclass implements Serializable {
31. String s;
32. int i;
33. double d;
34. Myclass(String s, int i, double d){
35. this.d = d;
36. this.i = i;
37. this.s = s;
38. }
39.}
a) -7
b) Hello
c) 2.1E10
d) deserialization
19. What is the output of this program?
1.import java.io.*;
2.class Chararrayinput {
3. public static void main(String[] args) {
4. String obj = “abcdefgh”;
5. int length = obj.length();
6. char c[] = new char[length];
7. obj.getChars(0, length, c, 0);
8. CharArrayReader input1 = new CharArrayReader(c);
9. CharArrayReader input2 = new CharArrayReader(c, 1, 4);
10. int i;
11. int j;
12. try {
13. while ((i = input1.read()) == (j = input2.read())) {
14. System.out.print((char)i);
15. }
16. }
17. catch (IOException e) {
18. e.printStackTrace();
19. }
20. }
21.}
a) abc
b) abcd
c) abcde
d) None of the mentioned
20. What is the output of this program?
1.import java.io.*;
2.class streams {
3. public static void main(String[] args) {
4. try {
5. FileOutputStream fos = new FileOutputStream(“serial”);
6. ObjectOutputStream oos = new ObjectOutputStream(fos);
7. oos.writeFloat(3.5);
8. oos.flush();
9. oos.close();
10. }
11. catch(Exception e) {
12. System.out.println(“Serialization” + e);
13. System.exit(0);
14. }
15. try {
16. float x;
17. FileInputStream fis = new FileInputStream(“serial”);
18. ObjectInputStream ois = new ObjectInputStream(fis);
19. x = ois.readInt();
20. ois.close();
21. System.out.println(x);
22. }
23. catch (Exception e) {
24. System.out.print(“deserialization”);
25. System.exit(0);
26. }
27. }
28.}
a) 3
b) 3.5
c) serialization
d) deserialization
21. Which of interface contains all the methods used for handling thread related operations in Java?
a) Runnable interface
b) Math interface
c) System interface
d) ThreadHandling interface
22. Which of these class is used to make a thread?
a) String
b) System
c) Thread
d) Runnable
23. Which of these interface is implemented by Thread class?
a) Runnable
b) Connections
c) Set
d) MapConnections
24. Which of these method of Thread class is used to suspend a thread for a period of time?
a) sleep()
b) terminate()
c) suspend()
d) stop()
25. toRadian() and toDegree() methods were added by which version of Java?
a) Java 1.0
b) Java 1.5
c) Java 2.0
d) Java 3.0
26. What is the output of this program?
1.class newthread implements Runnable {
2. Thread t1,t2;
3. newthread() {
4. t1 = new Thread(this,”Thread_1″);
5. t2 = new Thread(this,”Thread_2″);
6. t1.start();
7. t2.start();
8. }
9. public void run() {
10. t2.setPriority(Thread.MAX_PRIORITY);
11. System.out.print(t1.equals(t2));
12. }
13.}
14.class multithreaded_programing {
15. public static void main(String args[]) {
16. new newthread();
17. }
18.}
a) true
b) false
c) truetrue
d) falsefalse
27. What is the output of this program?
1.class newthread implements Runnable {
2. Thread t;
3. newthread() {
4. t = new Thread(this,”New Thread”);
5. t.start();
6. }
7. public void run() {
8. t.setPriority(Thread.MAX_PRIORITY);
9. System.out.println(t);
10. }
11.}
12.class multithreaded_programing {
13. public static void main(String args[]) {
14. new newthread();
15. }
16.}
a) Thread[New Thread,0,main]
b) Thread[New Thread,1,main]
c) Thread[New Thread,5,main]
d) Thread[New Thread,10,main]
28. What is the output of this program?
1.class newthread implements Runnable {
2. Thread t;
3. newthread() {
4. t = new Thread(this,”My Thread”);
5. t.start();
6. }
7.}
8.class multithreaded_programing {
9. public static void main(String args[]) {
10. new newthread();
11. }
12.}
a) My Thread
b) Thread[My Thread,5,main]
c) Compilation Error
d) Runtime Error
29. What is the output of this program?
1.class newthread implements Runnable {
2. Thread t;
3. newthread() {
4. t = new Thread(this,”My Thread”);
5. t.start();
6. }
7. public void run() {
8. System.out.println(t.getName());
9. }
10.}
11.class multithreaded_programing {
12. public static void main(String args[]) {
13. new newthread();
14. }
15.}
a) My Thread
b) Thread[My Thread,5,main]
c) Compilation Error
d) Runtime Error
30. What is the output of this program?
1.class newthread implements Runnable {
2. Thread t;
3. newthread() {
4. t = new Thread(this,”My Thread”);
5. t.start();
6. }
7. public void run() {
8. System.out.println(t);
9. }
10.}
11.class multithreaded_programing {
12. public static void main(String args[]) {
13. new newthread();
14. }
15.}
a) My Thread
b) Thread[My Thread,5,main]
c) Compilation Error
d) Runtime Error
Answers
1-d | 2-a | 3-a | 4-d | 5-d |
6-d | 7-a | 8-b | 9-c | 10-b |
11-a | 12-a | 13-b | 14-c | 15-b |
16-d | 17-a | 18-d | 19-d | 20-b |
21-d | 22-c | 23-a | 24-a | 25-c |
26-d | 27-d | 28-c | 29-a | 30-b |