1. Which of these is a super class of all exceptional type classes?
a) String
b) RuntimeExceptions
c) Throwable
d) Cachable
2. Which of these class is related to all the exceptions that can be caught by using catch?
a) Error
b) Exception
c) RuntimeExecption
d) All of the mentioned
3. Which of these class is related to all the exceptions that cannot be caught?
a) Error
b) Exception
c) RuntimeExecption
d) All of the mentioned
4. Which of these handles the exception when no catch is used?
a) Default handler
b) finally
c) throw handler
d) Java run time system
5. Which of these keywords is used to manually throw an exception?
a) try
b) finally
c) throw
d) catch
6. What is the output of this program?
1.class exception_handling {
2. public static void main(String args[]) {
3. try {
4. System.out.print(“Hello” + ” ” + 1 / 0);
5. }
6. finally {
7. System.out.print(“World”);
8. }
9. }
10.}
a) Hello
b) World
c) Compilation Error
d) First Exception then World
7. What is the output of this program?
1.class exception_handling {
2. public static void main(String args[]) {
3. try {
4. int a, b;
5. b = 0;
6. a = 5 / b;
7. System.out.print(“A”);
8. }
9. catch(ArithmeticException e) {
10. System.out.print(“B”);
11. }
12. }
13.}
a) A
b) B
c) Compilation Error
d) Runtime Error
8. What is the output of this program?
1.class exception_handling {
2. public static void main(String args[]) {
3. try {
4. int a[] = {1, 2,3 , 4, 5};
5. for (int i = 0; i < 7; ++i)
6. System.out.print(a[i]);
7. }
8. catch(ArrayIndexOutOfBoundsException e) {
9. System.out.print(“0”);
10. }
11. }
12.}
a) 12345
b) 123450
c) 1234500
d) Compilation Error
9. What is the output of this program?
1.class exception_handling {
2. public static void main(String args[]) {
3. try {
4. int i, sum;
5. sum = 10;
6. for (i = -1; i < 3 ;++i)
7. sum = (sum / i);
8. }
9. catch(ArithmeticException e) {
10. System.out.print(“0”);
11. }
12. System.out.print(sum);
13. }
14.}
a) 0
b) 05
c) Compilation Error
d) Runtime Error
10. What is the output of this program?
1.class exception_handling {
2. public static void main(String args[]) {
3. try {
4. int a[] = {1, 2,3 , 4, 5};
5. for (int i = 0; i < 5; ++i)
6. System.out.print(a[i]);
7. int x = 1/0;
8. }
9. catch(ArrayIndexOutOfBoundsException e) {
10. System.out.print(“A”);
11. }
12. catch(ArithmeticException e) {
13. System.out.print(“B”);
14. }
15. }
16.}
a) 12345
b) 12345A
c) 12345B
d) Comiplation Error
11. Which of these package contains classes and interfaces for networking?
a) java.io
b) java.util
c) java.net
d) java.network
12. Which of these is a protocol for breaking and sending packets to an address across a network?
a) TCIP/IP
b) DNS
c) Socket
d) Proxy Server
13. How many ports of TCP/IP are reserved for specific protocols?
a) 10
b) 1024
c) 2048
d) 512
14. How many bits are in a single IP address?
a) 8
b) 16
c) 32
d) 64
15. Which of these is a full form of DNS?
a) Data Network Service
b) Data Name Service
c) Domain Network Service
d) Domian Name Service
16. Which of these class is used to encapsulate IP address and DNS?
a) DatagramPacket
b) URL
c) InetAddress
d) ContentHandler
17. What is the output of this program?
1.import java.net.*;
2.class networking {
3. public static void main(String[] args) throws UnknownHostException {
4. InetAddress obj1 = InetAddress.getByName(“sanfoundary.com”);
5. InetAddress obj2 = InetAddress.getByName(“sanfoundary.com”);
6. boolean x = obj1.equals(obj2);
7. System.out.print(x);
8. }
9.}
a) 0
b) 1
c) true
d) false
18. What is the output of this program?
1.import java.net.*;
2.class networking {
3. public static void main(String[] args) throws UnknownHostException {
4. InetAddress obj1 = InetAddress.getByName(“cisco.com”);
5. InetAddress obj2 = InetAddress.getByName(“sanfoundary.com”);
6. boolean x = obj1.equals(obj2);
7. System.out.print(x);
8. }
9.}
a) 0
b) 1
c) true
d) false
19. 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. FileInputStream fis = new FileInputStream(“serial”);
17. ObjectInputStream ois = new ObjectInputStream(fis);
18. ois.close();
19. System.out.println(ois.available());
20. }
21. catch (Exception e) {
22. System.out.print(“deserialization”);
23. System.exit(0);
24. }
25. }
26.}
a) 1
b) 2
c) 3
d) 4
20. What is the output of this program?
1.import java.net.*;
2.class networking {
3. public static void main(String[] args) throws UnknownHostException {
4. InetAddress obj1 = InetAddress.getByName(“cisco.com”);
5. System.out.print(obj1.getHostName());
6. }
7.}
a) cisco
b) cisco.com
c) www.cisco.com
d) None of the mentioned
21. Which of these package is used for text formatting in Java programming language?
a) java.text
b) java.awt
c) java.awt.text
d) java.io
22. Which of this class can be used to format dates and times?
a) Date
b) SimpleDate
c) DateFormat
d) textFormat
23. Which of these method returns an instance of DateFormat that can format time information?
a) getTime()
b) getTimeInstance()
c) getTimeDateinstance()
d) getDateFormatinstance()
24. Which of these class allows us to define our own formatting pattern for dates and time?
a) DefinedDateFormat
b) SimpleDateFormat
c) ComplexDateFormat
d) UsersDateFormat
25. Which of these formatting strings of SimpleDateFormat class is used to print AM or PM in time?
a) a
b) b
c) c
d) d
26. Which of these formatting strings of SimpleDateFormat class is used to print week of the year?
a) w
b) W
c) s
d) S
27. What is the output of this program?
1.import java.text.*;
2.import java.util.*;
3.class Date_formatting {
4. public static void main(String args[]) {
5. Date date = new Date();
6. SimpleDateFormat sdf;
7. sdf = new SimpleDateFormat(“mm:hh:ss”);
8. System.out.print(sdf.format(date));
9. }
10.}
Note : The program is executed at 3 hour 55 minutes and 4 sec (24 hours time).
a) 3:55:4
b) 3.55.4
c) 55:03:04
d) 03:55:04
28. What is the output of this program?
1.import java.text.*;
2.import java.util.*;
3.class Date_formatting {
4. public static void main(String args[]) {
5. Date date = new Date();
6. SimpleDateFormat sdf;
7. sdf = new SimpleDateFormat(“hh:mm:ss”);
8. System.out.print(sdf.format(date));
9. }
10.}
Note : The program is executed at 3 hour 55 minutes and 4 sec (24 hours time).
a) 3:55:4
b) 3.55.4
c) 55:03:04
d) 03:55:04
29. What is the output of this program?
1.import java.text.*;
2.import java.util.*;
3.class Date_formatting {
4. public static void main(String args[]) {
5. Date date = new Date();
6. SimpleDateFormat sdf;
7. sdf = new SimpleDateFormat(“E MMM dd yyyy”);
8. System.out.print(sdf.format(date));
9. }
10.}
Note: The program is executed at 3 hour 55 minutes and 4 sec on Monday, 15 July(24 hours time).
a) Mon Jul 15 2013
b) Jul 15 2013
c) 55:03:04 Mon Jul 15 2013
d) 03:55:04 Jul 15 2013
30. What is the output of this program?
1.import java.text.*;
2.import java.util.*;
3.class Date_formatting {
4. public static void main(String args[]) {
5. Date date = new Date();
6. SimpleDateFormat sdf;
7. sdf = new SimpleDateFormat(“z”);
8. System.out.print(sdf.format(date));
9. }
10.}
a) z
b) Jul
c) Mon
d) PDT
Answers
1-c | 2-b | a | 4-a | 5-c |
6-d | 7-b | 8-b | 9-c | 10-c |
11-c | 12-a | 13-b | 14-c | 15-d |
16-c | 17-c | 18-d | 19-d | 20-b |
21-a | 22-c | 23-b | 24-b | 25-a |
26-a | 27-c | 28-d | 29-a | 30-d |