250+ TOP MCQs on Java.lang – Void, Process & System Class and Answers

Java MCQs on Void, Process & System classes of Java Programming Language.

1. Which of these class have only one field ‘TYPE’?
a) Void
b) Process
c) System
d) Runtime

Answer: a
Clarification: The Void class has one field, TYPE, which holds a reference to the Class object for the type void.

2. Which of the following method of Process class can terminate a process?
a) void kill()
b) void destroy()
c) void terminate()
d) void exit()

Answer: b
Clarification: Kills the subprocess. The subprocess represented by this Process object is forcibly terminated.

3. Standard output variable ‘out’ is defined in which class?
a) Void
b) Process
c) Runtime
d) System

Answer: d
Clarification: Standard output variable ‘out’ is defined in System class. out is usually used in print statement i:e System.out.print().

4. Which of these class can encapsulate an entire executing program?
a) Void
b) Process
c) Runtime
d) System

Answer: b
Clarification: None.

5. Which of the following is method of System class is used to find how long a program takes to execute?
a) currenttime()
b) currentTime()
c) currentTimeMillis()
d) currenttimeMillis()

Answer: c
Clarification: None.

6. Which of these class holds a collection of static methods and variables?
a) Void
b) Process
c) Runtime
d) System

Answer: d
Clarification: System class holds a collection of static methods and variables. The standard input, output and error output of java runtime is stored in the in, out and err variables of System class.

7. What will be the output of the following Java code?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             long start, end;   
  6.             start = System.currentTimeMillis();
  7.             for (int i = 0; i < 10000000; i++);
  8.             end = System.currentTimeMillis();
  9.             System.out.print(end - start);
  10.         }
  11.     }

a) 0
b) 1
c) 1000
d) System Dependent

Answer: d
Clarification: end time is the time taken by loop to execute it can be any non zero value depending on the System.
Output:

$ javac Output.java
$ java Output
78

8. What will be the output of the following Java code?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             byte a[] = { 65, 66, 67, 68, 69, 70 };
  6.             byte b[] = { 71, 72, 73, 74, 75, 76 };  
  7.             System.arraycopy(a , 0, b, 0, a.length);
  8.             System.out.print(new String(a) + " " + new String(b));
  9.         }
  10.     }

a) ABCDEF ABCDEF
b) ABCDEF GHIJKL
c) GHIJKL ABCDEF
d) GHIJKL GHIJKL

Answer: a
Clarification: System.arraycopy() is a method of class System which is used to copy a string into another string.
Output:

$ javac Output.java
$ java Output
ABCDEF ABCDEF

9. What will be the output of the following Java code?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             byte a[] = { 65, 66, 67, 68, 69, 70 };
  6.             byte b[] = { 71, 72, 73, 74, 75, 76 };  
  7.             System.arraycopy(a, 2, b, 1, a.length-2);
  8.             System.out.print(new String(a) + " " + new String(b));
  9.         }
  10.     }

a) ABCDEF GHIJKL
b) ABCDEF GCDEFL
c) GHIJKL ABCDEF
d) GCDEFL GHIJKL

Answer: b
Clarification: None.
Output:

$ javac Output.java
$ java Output
ABCDEF GCDEFL

10. What will be the output of the following Java code?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             byte a[] = { 65, 66, 67, 68, 69, 70 };
  6.             byte b[] = { 71, 72, 73, 74, 75, 76 };  
  7.             System.arraycopy(a, 1, b, 3, 0);
  8.             System.out.print(new String(a) + " " + new String(b));
  9.         }
  10.     }

a) ABCDEF GHIJKL
b) ABCDEF GCDEFL
c) GHIJKL ABCDEF
d) GCDEFL GHIJKL

Answer: a
Clarification: Since last parameter of System.arraycopy(a,1,b,3,0) is 0 nothing is copied from array a to array b, hence b remains as it is.
Output:

$ javac Output.java
$ java Output
ABCDEF GHIJKL

250+ TOP MCQs on Serialization – 1 and Answers

This set of Java Multiple Choice Questions & Answers (MCQs) on “Serialization – 1”.

1. 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

Answer: a
Clarification: Serialization is the process of writing the state of an object to a byte stream. This is used when you want to save the state of your program to a persistent storage area.

2. Which of these process occur automatically by the java runtime system?
a) Serialization
b) Garbage collection
c) File Filtering
d) All of the mentioned

Answer: a
Clarification: Serialization and deserialization occur automatically by java runtime system, Garbage collection also occur automatically but is done by CPU or the operating system not by the java runtime system.

3. Which of these is an interface for control over serialization and deserialization?
a) Serializable
b) Externalization
c) FileFilter
d) ObjectInput

Answer: b
Clarification: None.

4. Which of these interface extends DataOutput interface?
a) Serializable
b) Externalization
c) ObjectOutput
d) ObjectInput

Answer: c
Clarification: ObjectOutput interface extends the DataOutput interface and supports object serialization.

5. 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()

Answer: b
Clarification: None.

6. 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()

Answer: d
Clarification: writeObject() is used to write an object into invoking stream, it can be input stream or output stream.

7. What will be the output of the following Java program?

  1.     import java.io.*;
  2.     class serialization 
  3.     {
  4.         public static void main(String[] args) 
  5.         {
  6.             try 
  7.             {
  8.                 Myclass object1 = new Myclass("Hello", -7, 2.1e10);
  9. 	        FileOutputStream fos = new FileOutputStream("serial");
  10. 	        ObjectOutputStream oos = new ObjectOutputStream(fos);
  11.                 oos.writeObject(object1);
  12.                 oos.flush();
  13.                 oos.close();
  14. 	    }
  15. 	    catch(Exception e) 
  16.             {
  17. 	        System.out.println("Serialization" + e);
  18.                 System.exit(0);
  19.             }
  20. 	    try  
  21.             {
  22.                 Myclass object2;
  23. 	        FileInputStream fis = new FileInputStream("serial");
  24. 	        ObjectInputStream ois = new ObjectInputStream(fis);
  25.                 object2 = (Myclass)ois.readObject();
  26.                 ois.close();
  27. 	        System.out.println(object2);		    	
  28. 	    }
  29. 	    catch (Exception e) 
  30.             {
  31.                 System.out.print("deserialization" + e);
  32. 	        System.exit(0);
  33. 	    }
  34.         }
  35.     }
  36.     class Myclass implements Serializable 
  37.     {
  38. 	String s;
  39. 	int i;
  40. 	double d;
  41.         Myclass (String s, int i, double d)
  42.         {
  43. 	    this.d = d;
  44. 	    this.i = i;
  45. 	    this.s = s;
  46. 	}
  47.     }

a) s=Hello; i=-7; d=2.1E10
b) Hello; -7; 2.1E10
c) s; i; 2.1E10
d) Serialization

Answer: a
Clarification: None.
Output:

$ javac serialization.java
$ java serialization
s=Hello; i=-7; d=2.1E10

8. What will be the output of the following Java program?

  1.     import java.io.*;
  2.     class serialization 
  3.     {
  4.         public static void main(String[] args) 
  5.         {
  6.             try 
  7.             {
  8.                 Myclass object1 = new Myclass("Hello", -7, 2.1e10);
  9. 	        FileOutputStream fos = new FileOutputStream("serial");
  10. 	        ObjectOutputStream oos = new ObjectOutputStream(fos);
  11.                 oos.writeObject(object1);
  12.                 oos.flush();
  13.                 oos.close();
  14. 	    }
  15. 	    catch(Exception e) 
  16.             {
  17. 	        System.out.println("Serialization" + e);
  18.                 System.exit(0);
  19.             }
  20. 	    try
  21.             {
  22. 	        int x;
  23. 	        FileInputStream fis = new FileInputStream("serial");
  24. 	        ObjectInputStream ois = new ObjectInputStream(fis);
  25.                 x = ois.readInt();
  26.                 ois.close();
  27. 	        System.out.println(x);		    	
  28. 	    }
  29. 	    catch (Exception e)
  30.             {
  31.                 System.out.print("deserialization");
  32. 	        System.exit(0);
  33. 	    }
  34.         }
  35.     }
  36.     class Myclass implements Serializable
  37.     {
  38. 	String s;
  39. 	int i;
  40. 	double d;
  41.         Myclass(String s, int i, double d)
  42.         {
  43. 	    this.d = d;
  44. 	    this.i = i;
  45. 	    this.s = s;
  46. 	}
  47.     }

a) -7
b) Hello
c) 2.1E10
d) deserialization

Answer: d
Clarification: x = ois.readInt(); will try to read an integer value from the stream ‘serial’ created before, since stream contains an object of Myclass hence error will occur and it will be catched by catch printing deserialization.
Output:

$ javac serialization.java
$ java serialization
deserialization

9. What will be the output of the following Java program?

  1.     import java.io.*;
  2.     class Chararrayinput
  3.     {
  4.         public static void main(String[] args) 
  5.         {
  6. 	    String obj  = "abcdefgh";
  7.             int length = obj.length();
  8.             char c[] = new char[length];
  9.             obj.getChars(0, length, c, 0);
  10.             CharArrayReader input1 = new CharArrayReader(c);
  11.             CharArrayReader input2 = new CharArrayReader(c, 1, 4);
  12.             int i;
  13.             int j;
  14.             try 
  15.             {
  16. 		while ((i = input1.read()) == (j = input2.read()))
  17.                 {
  18.                     System.out.print((char)i);
  19.                 }
  20.        	    } 
  21.             catch (IOException e) 
  22.             {
  23.                 e.printStackTrace();
  24. 	    }
  25. 	}
  26.     }

a) abc
b) abcd
c) abcde
d) None of the mentioned

Answer: d
Clarification: No output is printed. CharArrayReader object input1 contains string “abcdefgh” whereas object input2 contains string “bcde”, when while((i=input1.read())==(j=input2.read())) is executed the starting character of each object is compared since they are unequal control comes out of loop and nothing is printed on the screen.
Output:

$ javac Chararrayinput.java
$ java Chararrayinput

10. What will be the output of the following Java program?

  1.     import java.io.*;
  2.     class streams
  3.     {
  4.         public static void main(String[] args) 
  5.         {
  6.             try
  7.             {
  8. 	        FileOutputStream fos = new FileOutputStream("serial");
  9. 	        ObjectOutputStream oos = new ObjectOutputStream(fos);
  10.                 oos.writeFloat(3.5);
  11.                 oos.flush();
  12.                 oos.close();
  13. 	    }
  14. 	    catch(Exception e)
  15.             {
  16. 	        System.out.println("Serialization" + e);
  17.                 System.exit(0);
  18.             }
  19. 	    try 
  20.             {
  21. 	        float x;
  22. 	        FileInputStream fis = new FileInputStream("serial");
  23. 	        ObjectInputStream ois = new ObjectInputStream(fis);
  24.                 x = ois.readInt();
  25.                 ois.close();
  26. 	        System.out.println(x);		    	
  27. 	    }
  28. 	    catch (Exception e)
  29.             {
  30.                 System.out.print("deserialization");
  31. 	        System.exit(0);
  32. 	    }
  33.         }
  34.     }

a) 3
b) 3.5
c) serialization
d) deserialization

Answer: b
Clarification: oos.writeFloat(3.5); writes in output stream which is extracted by x = ois.readInt(); and stored in x hence x contains 3.5.
Output:

$ javac streams.java
$ java streams
3.5

250+ TOP MCQs on Remote Method Invocation (RMI) and Answers

This set of Java Multiple Choice Questions & Answers (MCQs) on “Remote Method Invocation (RMI)”.

1. What is Remote method invocation (RMI)?
a) RMI allows us to invoke a method of java object that executes on another machine
b) RMI allows us to invoke a method of java object that executes on another Thread in multithreaded programming
c) RMI allows us to invoke a method of java object that executes parallely in same machine
d) None of the mentioned

Answer: a
Clarification: Remote method invocation RMI allows us to invoke a method of java object that executes on another machine.

2. Which of these package is used for remote method invocation?
a) java.applet
b) java.rmi
c) java.lang.rmi
d) java.lang.reflect

Answer: b
Clarification: None.

3. Which of these methods are member of Remote class?
a) checkIP()
b) addLocation()
c) AddServer()
d) None of the mentioned

Answer: d
Clarification: Remote class does not define any methods, its purpose is simply to indicate that an interface uses remote methods.

4. Which of these Exceptions is thrown by remote method?
a) RemoteException
b) InputOutputException
c) RemoteAccessException
d) RemoteInputOutputException

Answer: a
Clarification: All remote methods throw RemoteException.

5. Which of these class is used for creating a client for a server-client operations?
a) serverClientjava
b) Client.java
c) AddClient.java
d) ServerClient.java

Answer: c
Clarification: None.

6. Which of these package is used for all the text related modifications?
a) java.text
b) java.awt
c) java.lang.text
d) java.text.modify

Answer: a
Clarification: java.text provides capabilities for formatting, searching and manipulating text.

7. What will be the output of the following Java code?

  1.     import java.lang.reflect.*;
  2.     class Additional_packages 
  3.     {	 
  4.          public static void main(String args[]) 
  5.          {
  6. 	     try 
  7.              {
  8. 	         Class c = Class.forName("java.awt.Dimension");
  9. 		 Constructor constructors[] = c.getConstructors();
  10. 		 for (int i = 0; i < constructors.length; i++)
  11. 		     System.out.println(constructors[i]);
  12. 	     }
  13. 	     catch (Exception e)
  14.              {
  15.              System.out.print("Exception");
  16.              }
  17.         }
  18.     }

a) Program prints all the constructors of ‘java.awt.Dimension’ package
b) Program prints all the possible constructors of class ‘Class’
c) Program prints “Exception”
d) Runtime Error

Answer: a
Clarification: None.
Output:

$ javac Additional_packages.java
$ java Additional_packages
public java.awt.Dimension(java.awt.Dimension)
public java.awt.Dimension()
public java.awt.Dimension(int,int)

8. What will be the output of the following Java code?

  1.     import java.lang.reflect.*;
  2.     class Additional_packages 
  3.     {	 
  4.          public static void main(String args[])
  5.          {
  6. 	     try 
  7.              {
  8. 	         Class c = Class.forName("java.awt.Dimension");
  9. 		 Field fields[] = c.getFields();
  10. 		 for (int i = 0; i < fields.length; i++)
  11. 		     System.out.println(fields[i]);
  12. 	     }
  13. 	     catch (Exception e)
  14.              {
  15.              System.out.print("Exception");
  16.              }
  17.         }    
  18.     }

a) Program prints all the constructors of ‘java.awt.Dimension’ package
b) Program prints all the methods of ‘java.awt.Dimension’ package
c) Program prints all the data members of ‘java.awt.Dimension’ package
d) program prints all the methods and data member of ‘java.awt.Dimension’ package

Answer: c
Clarification: None.
Output:

$ javac Additional_packages.java
$ java Additional_packages
public int java.awt.Dimension.width
public int java.awt.Dimension.height

9. What is the length of the application box made in the following Java program?

  1.     import java.awt.*;
  2.     import java.applet.*;
  3.     public class myapplet extends Applet 
  4.     {
  5.         Graphic g;
  6.         g.drawString("A Simple Applet",20,20);    
  7.     }

a) 20
b) Default value
c) Compilation Error
d) Runtime Error

Answer: c
Clarification: To implement the method drawString we need first need to define abstract method of AWT that is paint() method. Without paint() method we cannot define and use drawString or any Graphic class methods.

10. What will be the output of the following Java program?

  1.     import java.lang.reflect.*;
  2.     class Additional_packages
  3.     {	 
  4.          public static void main(String args[])
  5.          {
  6. 	     try
  7.              {
  8. 	         Class c = Class.forName("java.awt.Dimension");
  9. 		 Method methods[] = c.getMethods();
  10. 		 for (int i = 0; i < methods.length; i++)
  11. 		     System.out.println(methods[i]);
  12. 	     }
  13. 	     catch (Exception e)
  14.              {
  15.              System.out.print("Exception");
  16.              }
  17.         }
  18.     }

a) Program prints all the constructors of ‘java.awt.Dimension’ package
b) Program prints all the methods of ‘java.awt.Dimension’ package
c) Program prints all the data members of ‘java.awt.Dimension’ package
d) program prints all the methods and data member of ‘java.awt.Dimension’ package

Answer: b
Clarification: None.
Output:

$ javac Additional_packages.java
$ java Additional_packages
public int java.awt.Dimension.hashCode()
public boolean java.awt.Dimension.equals(java.lang.Object)
public java.lang.String java.awt.Dimension.toString()
public java.awt.Dimension java.awt.Dimension.getSize()
public void java.awt.Dimension.setSize(double,double)
public void java.awt.Dimension.setSize(int,int)
public void java.awt.Dimension.setSize(java.awt.Dimension)
public double java.awt.Dimension.getHeight()
public double java.awt.Dimension.getWidth()
public java.lang.Object java.awt.geom.Dimension2D.clone()
public void java.awt.geom.Dimension2D.setSize(java.awt.geom.Dimension2D)
public final native java.lang.Class java.lang.Object.getClass()
public final native void java.lang.Object.notify()
public final native void java.lang.Object.notifyAll()
public final native void java.lang.Object.wait(long)
public final void java.lang.Object.wait(long,int)
public final void java.lang.Object.wait()

250+ TOP MCQs on Multithreading Basics and Answers

Java MCQs on Basics of multithreading of Java Programming Language.

1. What is multithreaded programming?
a) It’s a process in which two different processes run simultaneously
b) It’s a process in which two or more parts of same process run simultaneously
c) It’s a process in which many different process are able to access same information
d) It’s a process in which a single process can access information from many sources

Answer: b
Clarification: Multithreaded programming a process in which two or more parts of the same process run simultaneously.

2. Which of these are types of multitasking?
a) Process based
b) Thread based
c) Process and Thread based
d) None of the mentioned

Answer: c
Clarification: There are two types of multitasking: Process based multitasking and Thread based multitasking.

3. Thread priority in Java is?
a) Integer
b) Float
c) double
d) long

Answer: a
Clarification: Java assigns to each thread a priority that determines hoe that thread should be treated with respect to others. Thread priority is integers that specify relative priority of one thread to another.

4. What will happen if two thread of the same priority are called to be processed simultaneously?
a) Anyone will be executed first lexographically
b) Both of them will be executed simultaneously
c) None of them will be executed
d) It is dependent on the operating system

Answer: d
Clarification: In cases where two or more thread with same priority are competing for CPU cycles, different operating system handle this situation differently. Some execute them in time sliced manner some depending on the thread they call.

5. Which of these statements is incorrect?
a) By multithreading CPU idle time is minimized, and we can take maximum use of it
b) By multitasking CPU idle time is minimized, and we can take maximum use of it
c) Two thread in Java can have the same priority
d) A thread can exist only in two states, running and blocked

Answer: d
Clarification: Thread exist in several states, a thread can be running, suspended, blocked, terminated & ready to run.

6. What will be the output of the following Java code?

  1.     class multithreaded_programing
  2.     {
  3.         public static void main(String args[])
  4.         {
  5.             Thread t = Thread.currentThread();
  6.             System.out.println(t);        
  7.         }
  8.     }

a) Thread[5,main]
b) Thread[main,5]
c) Thread[main,0]
d) Thread[main,5,main]

Answer: d
Clarification: None.
Output:

$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[main,5,main]

7. What is the priority of the thread in the following Java Program?

  1.     class multithreaded_programing 
  2.     {
  3.         public static void main(String args[])
  4.         {
  5.             Thread t = Thread.currentThread();
  6.             System.out.println(t);        
  7.         }
  8.     }

a) 4
b) 5
c) 0
d) 1

Answer: b
Clarification: The output of program is Thread[main,5,main], in this priority assigned to the thread is 5. It’s the default value. Since we have not named the thread they are named by the group to they belong i:e main method.
Output:

$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[main,5,main]

8. What is the name of the thread in the following Java Program?

  1.     class multithreaded_programing
  2.     {
  3.         public static void main(String args[])
  4.         {
  5.             Thread t = Thread.currentThread();
  6.             System.out.println(t);        
  7.         }
  8.     }

a) main
b) Thread
c) System
d) None of the mentioned

Answer: a
Clarification: The output of program is Thread[main,5,main], Since we have not explicitly named the thread they are named by the group to they belong i:e main method. Hence they are named ‘main’.
Output:

$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[main,5,main]

250+ TOP MCQs on Packages and Answers

Java MCQs on packages of Java Programming Language.

1. Which of these keywords is used to define packages in Java?
a) pkg
b) Pkg
c) package
d) Package

Answer: c
Clarification: None.

2. Which of these is a mechanism for naming and visibility control of a class and its content?
a) Object
b) Packages
c) Interfaces
d) None of the Mentioned.

Answer: b
Clarification: Packages are both naming and visibility control mechanism. We can define a class inside a package which is not accessible by code outside the package.

3. Which of this access specifies can be used for a class so that its members can be accessed by a different class in the same package?
a) Public
b) Protected
c) No Modifier
d) All of the mentioned

Answer: d
Clarification: Either we can use public, protected or we can name the class without any specifier.

4. Which of these access specifiers can be used for a class so that its members can be accessed by a different class in the different package?
a) Public
b) Protected
c) Private
d) No Modifier

Answer: a
Clarification: None.

5. Which of the following is the correct way of importing an entire package ‘pkg’?
a) import pkg.
b) Import pkg.
c) import pkg.*
d) Import pkg.*

Answer: c
Clarification: Operator * is used to import the entire package.

6. Which of the following is an incorrect statement about packages?
a) Package defines a namespace in which classes are stored
b) A package can contain other package within it
c) Java uses file system directories to store packages
d) A package can be renamed without renaming the directory in which the classes are stored

Answer: d
Clarification: A package can be renamed only after renaming the directory in which the classes are stored.

7. Which of the following package stores all the standard java classes?
a) lang
b) java
c) util
d) java.packages

Answer: b
Clarification: None.

8. What will be the output of the following Java program?

  1.     package pkg;
  2.     class display 
  3.     {
  4.         int x;
  5.         void show() 
  6.         {
  7.             if (x > 1)
  8.                 System.out.print(x + " ");
  9.         }
  10.     }
  11.     class packages 
  12.     {
  13.         public static void main(String args[]) 
  14.         {
  15.             display[] arr=new display[3];
  16.             for(int i=0;i<3;i++)
  17.                 arr[i]=new display();
  18.             arr[0].x = 0;      
  19.             arr[1].x = 1;
  20.             arr[2].x = 2;
  21.             for (int i = 0; i < 3; ++i)
  22.                 arr[i].show();
  23.          }
  24.     }

Note : packages.class file is in directory pkg;
a) 0
b) 1
c) 2
d) 0 1 2

Answer: c
Clarification: None.
Output:

$ javac packages.java
$ java packages
2

9. What will be the output of the following Java program?

  1.     package pkg;
  2.     class output 
  3.     {
  4.         public static void main(String args[])
  5.         { 
  6.             StringBuffer s1 = new StringBuffer("Hello");
  7.             s1.setCharAt(1, x);
  8.             System.out.println(s1);
  9.         }
  10.     }

a) xello
b) xxxxx
c) Hxllo
d) Hexlo

Answer: c
Clarification: None.
Output:

$ javac output.java
$ java output
Hxllo

10. What will be the output of the following Java program?

  1.     package pkg;
  2.     class output 
  3.     {
  4.         public static void main(String args[])
  5.         {
  6.             StringBuffer s1 = new StringBuffer("Hello World");
  7.             s1.insert(6 , "Good ");
  8.             System.out.println(s1);
  9.         }
  10.    }

Note : Output.class file is not in directory pkg.
a) HelloGoodWorld
b) HellGoodoWorld
c) Compilation error
d) Runtime error

Answer: d
Clarification: Since output.class file is not in the directory pkg in which class output is defined, program will not be able to run.
output:

$ javac output.java
$ java output 
can not find file output.class

Advanced 250+ TOP MCQs on JDBC and Answers

This set of Advanced Java Multiple Choice Questions & Answers (MCQs) on “JDBC”.

1. Which of the following contains both date and time?
a) java.io.date
b) java.sql.date
c) java.util.date
d) java.util.dateTime

Answer: d
Clarification: java.util.date contains both date and time. Whereas, java.sql.date contains only date.

2. Which of the following is advantage of using JDBC connection pool?
a) Slow performance
b) Using more memory
c) Using less memory
d) Better performance

Answer: d
Clarification: Since the JDBC connection takes time to establish. Creating connection at the application start-up and reusing at the time of requirement, helps performance of the application.

3. Which of the following is advantage of using PreparedStatement in Java?
a) Slow performance
b) Encourages SQL injection
c) Prevents SQL injection
d) More memory usage

Answer: c
Clarification: PreparedStatement in Java improves performance and also prevents from SQL injection.

4. Which one of the following contains date information?
a) java.sql.TimeStamp
b) java.sql.Time
c) java.io.Time
d) java.io.TimeStamp

Answer: a
Clarification: java.sql.Time contains only time. Whereas, java.sql.TimeStamp contains both time and date.

5. What does setAutoCommit(false) do?
a) commits transaction after each query
b) explicitly commits transaction
c) does not commit transaction automatically after each query
d) never commits transaction

Answer: c
Clarification: setAutoCommit(false) does not commit transaction automatically after each query. That saves a lot of time of the execution and hence improves performance.

6. Which of the following is used to call stored procedure?
a) Statement
b) PreparedStatement
c) CallableStatment
d) CalledStatement

Answer: c
Clarification: CallableStatement is used in JDBC to call stored procedure from Java program.

7. Which of the following is used to limit the number of rows returned?
a) setMaxRows(int i)
b) setMinRows(int i)
c) getMaxrows(int i)
d) getMinRows(int i)

Answer: a
Clarification: setMaxRows(int i) method is used to limit the number of rows that the database returns from the query.

8. Which of the following is method of JDBC batch process?
a) setBatch()
b) deleteBatch()
c) removeBatch()
d) addBatch()

Answer: d
Clarification: addBatch() is a method of JDBC batch process. It is faster in processing than executing one statement at a time.

9. Which of the following is used to rollback a JDBC transaction?
a) rollback()
b) rollforward()
c) deleteTransaction()
d) RemoveTransaction()

Answer: a
Clarification: rollback() method is used to rollback the transaction. It will rollback all the changes made by the transaction.

10. Which of the following is not a JDBC connection isolation levels?
a) TRANSACTION_NONE
b) TRANSACTION_READ_COMMITTED
c) TRANSACTION_REPEATABLE_READ
d) TRANSACTION_NONREPEATABLE_READ

Answer: d
Clarification: TRANSACTION_NONREPEATABLE_READ is not a JDBC connection isolation level.