You are on page 1of 18

JAVA SET 1 MULTIPLE CHOICE QUESTION

1. Identify the exception which occurs when creating a DataInputStream for a


nonexistent file.

A) FileNotExist

B) FileNotExistException

C) FileNotFound

D) FileNotFoundException

2. Name the method can be used to write data.

A) close

B) print

C) exist

D) rename

3. After the following program is finished, how many bytes are written to the
file new.data.

import java.io.*;

public class Test {

public static void main(String[] args) throws IOException {

DataOutputStream output = new DataOutputStream(

new FileOutputStream("new.dat"));

output.writeChars("ABCD");

output.close();

}
}

A) 2

B) 8

C) 16

D) 4

4. ________ class contains the method for checking whether a file exists.

A) File

B) PrintWriter

C) Scanner

D) System

5. Identify the output of this program.

public static void main(String args[])

StringBuffer s1 = new StringBuffer("Hello");

StringBuffer s2 = s1.reverse();

System.out.println(s2);

A) Hello

B) olleH

C) HelloolleH

D) olleHHello
6. Identify the correct method of ArrayList class that is used to obtain present
size of an object.

A) size()

B) length()

C) index()

D) capacity()

7. Among the following statements,which one loads the JDBC-ODBC driver?

A) Class.forName(sun.jdbc.odbc.JdbcOdbcDriver)

B) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")

C) Class.loadClass(sun.jdbc.odbc.JdbcOdbcDriver)

D) Class.loadClass("sun.jdbc.odbc.JdbcOdbcDriver")

8. StringBuffer sb = new StringBuffer("WELCOME"); What will be the


capacity of the object sb ?

A) 7

B) 16

C) 9

D) 32/23

9. _____________ is a superclass of TextField and TextArea classes that is


used to create single-line or multiline textfields respectively

A) TextBox

B) CheckBox

C) TextComponent

D) Choice
10. AppletViewer tool is available in which of the folder of JDK

A) bin

B) lib

C) source

D) class

11. To append data to an existing file, use _____________ to construct a


FileOutputStream for file out.dat.

A) new FileOutputStream("out.dat")

B) new FileOutputStream("out.dat", false)

C) new FileOutputStream("out.dat", true)

D) new FileOutputStream(true, "out.dat")

12. Interpret the method that can be used to read a whole line from a file.

A) next

B) nextLine

C) nextInt

D) nextDouble

13. Identify the correct statement that creates an instance of File on Window for
the file c:\temp.txt.

A) new File("c:\temp.txt")

B) new File("c:\\temp.txt")

C) new File("c:/temp.txt")

D) new File("c://temp.txt")

14. The output from the following code is __________.


java.util.ArrayList<String> list = new java.util.ArrayList<>();

list.add("New York"); list.add("Atlanta"); list.add("Dallas");


System.out.println(list);

A) [New York]

B) [New York, Atlanta]

C) [New York, Atlanta, Dallas]

D) [New York, Dallas]

15. ____________________ returns true.

A) "peter".compareToIgnoreCase("Peter")

B) "peter".compareToIgnoreCase("peter")

C) "peter".equalsIgnoreCase("Peter")

D) "peter".equalsignoreCase("peter")

16. Assume s is " abc ", the method __________ returns a new string "abc".

A) s.trim(s)

B) trim(s)

C) String.trim(s)

D) s.trim()

17. Interpret the output for the following code snippet.

System.out.println("Java is neat".replaceAll("is", "AAA"));

A) JavaAAAneat

B) JavaAAA neat

C) Java AAA neat

D) Java AAAneat
18. The _______ method in the applet is invoked when the user leaves the page
that contains the applet.

A) init

B) start

C) stop

D) destroy

19. To use an applet in the HTML document, you use __________ in the
<applet> tag.

A) .java source code file

B) .class bytecode

C) .exe executable file

D) .html file

20. AWT stands for

A) All Window Tools

B) All Writing Tools

C) Abstract Window Toolkit

D) Abstract Writing Toolkit

JAVA SET 2 MULTIPLE CHOICE QUESTION

1 The extension name of a Java bytecode file is

A) .java

B) .obj
C) .class

D) .exe

2. All Java applications must have a method __________.

A) public static Main(String[] args)

B) public static Main(String args[])

C) public static void main(String[] args)

D) public void main(String[] args)

3. The JVM stores the array in an area of memory, called _______, which is
used for dynamic memory allocation where blocks of memory are allocated and
freed in an arbitrary order.

A) dynamic memory

B) memory block

C) heap

D) stack

4. Given the declaration Circle[] x = new Circle[10], which of the following


statement is most accurate.

A) x contains an array of ten int values.

B) x contains an array of ten objects of the Circle type.

C) x contains a reference to an array and each element in the array


can hold a reference to a Circle object.

D) x contains a reference to an array and each element in the array can


hold a Circle object.

5. Name the exception type does the following program throw.


public class Test {

public static void main(String[] args) {

System.out.println(1 / 0); } }

A) ArithmeticException

B) ArrayIndexOutOfBoundsException

C) StringIndexOutOfBoundsException

D) ClassCastException

6. Infer how many times will the following code print "Welcome to Java".

int count = 0;

while (count++ < 10) {

System.out.println("Welcome to Java");

A) 8

B) 9

C) 10

D) 11

7. The relationship between an interface and the class that implements it is

A) Composition

B) Aggregation

C) Inheritance

D) Association

8. Encapsulation means ______________.


A) that data fields should be declared private.

B) that a class can extend another class.

C) that a variable of supertype can refer to a subtype object.

D) that a class can contain another class.

9. StringBuffer sb = new StringBuffer("WELCOME"); What will be the


capacity of the object sb ?

A) 7

B) 16

C) 9

D) 32/23

10. ________ class contains the method for checking whether a file exists.

A) File

B) PrintWriter

C) Scanner

D) System

11. To append data to an existing file, use _____________ to construct a


FileOutputStream for file out.dat.

A) new FileOutputStream("out.dat")

B) new FileOutputStream("out.dat", false)

C) new FileOutputStream("out.dat", true)

D) new FileOutputStream(true, "out.dat")

12. Identify the correct statement that creates an instance of File on Window for
the file c:\temp.txt.

A) new File("c:\temp.txt")
B) new File("c:\\temp.txt")

C) new File("c:/temp.txt")

D) new File("c://temp.txt")

13. Identify the exception which occurs when creating a DataInputStream for a
nonexistent file.

A) FileNotExist

B) FileNotExistException

C) FileNotFound

D) FileNotFoundException

14. Assume

Calendar calendar = new GregorianCalendar(). __________ returns the month of


the year.

A) calendar.get(Calendar.MONTH)

B) calendar.get(Calendar.MONTH_OF_YEAR)

C) calendar.get(Calendar.WEEK_OF_MONTH)

D) calendar.get(Calendar.WEEK_OF_YEAR)

15. Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the
following methods will cause the list to become [Beijing, Chicago, Singapore]?

A) x.add("Chicago")

B) x.add(0, "Chicago")

C) x.add(1, "Chicago")

D) x.add(2, "Chicago")

16. Assume s is " abc ", the method __________ returns a new string "abc".
A) s.trim(s)

B) trim(s)

C) String.trim(s)

D) s.trim()

17. AWT stands for

A) All Window Tools

B) All Writing Tools

C) Abstract Window Toolkit

D) Abstract Writing Toolkit

18. _____________ is a superclass of TextField and TextArea classes that is


used to create single-line or multiline textfields respectively

A) TextBox

B) CheckBox

C) TextComponent

D) Choice

19. AppletViewer tool is available in which of the folder of JDK

A) bin

B) lib

C) source

D) class

20. Among the following statements,which one loads the JDBC-ODBC driver?

A) Class.forName(sun.jdbc.odbc.JdbcOdbcDriver)

B) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
C) Class.loadClass(sun.jdbc.odbc.JdbcOdbcDriver)

D) Class.loadClass("sun.jdbc.odbc.JdbcOdbcDriver")

JAVA SET 3 MULTIPLE CHOICE QUESTION

1 Suppose you define a Java class as follows:

public class Test {}

In order to compile this program, the source code should be stored in a file named

A) Test.class

B) Testfile.java

C) Testfile.class

D) Test.java

2. After the following program is finished, how many bytes are written to the
file new.data.

import java.io.*;

public class Test {

public static void main(String[] args) throws IOException {

DataOutputStream output = new DataOutputStream(

new FileOutputStream("new.dat"));

output.writeChars("ABCD");

output.close();

}
}

A) 2

B) 8

C) 16

D) 4

3. We can use the ________ method to force one thread to wait for another
thread to finish.

A) sleep(long milliseconds)

B) yield()

C) suspend()

D) join()

4. Suppose a Scanner object is created as follows:

Scanner sin= new Scanner(System.in);

Choose the method from the below to read an int value.

A) sin.nextInt();

B) sin.nextInteger();

C) sin.int();

D) sin.integer();

5. Among the following which is a correct interface.

A) interface A { void print() { }; }

B) abstract interface A { print(); }

C) abstract interface A { abstract void print() { };}


D) interface A { void print();}

6. Java compiler translates Java source code into _________.

A) Java bytecode

B) machine code

C) assembly code

D) another high-level language code

7. Among the following, which of classes cannot be extended

A) class A { }

B) class A { private A();}

C) final class A { }

D) class A { protected A();}

8. Which method can be used to create an output object for file temp.txt?

A) new PrintWriter("temp.txt")

B) new PrintWriter(temp.txt)

C) new PrintWriter(new File("temp.txt"))

D) new PrintWriter(File("temp.txt"))

9. The following loop displays _______________.

for (int i = 1; i <= 10; i++) {

System.out.print(i + " ");

i++;

A) 123456789
B) 1 2 3 4 5 6 7 8 9 10

C) 13579

D) 2 4 6 8 10

10. Interpret the method that can be used to read a whole line from a file.

A) next

B) nextLine

C) nextInt

D) nextDouble

11. Assume int[] t = {1, 2, 3, 4}. What is t.length?

A) 0

B) 3

C) 4

D) 5

12. _______ class contains the method for checking whether a file exists.

A) File

B) PrintWriter

C) Scanner

D) System

13. The output from the following code is __________.

java.util.ArrayList<String> list = new java.util.ArrayList<>();

list.add("New York"); list.add("Atlanta"); list.add("Dallas");


System.out.println(list);

A) [New York]
B) [New York, Atlanta]

C) [New York, Atlanta, Dallas]

D) [New York, Dallas]

14. The _______ method in the applet is invoked when the user leaves the page
that contains the applet.

A) init

B) start

C) stop

D) destroy

15. Suppose an ArrayList list contains {"red", "green", "red", "green"}. What is
list after the following code?

list.remove("red");

A) {"red", "green", "red", "green"}

B) {"green", "red", "green"}

C) {"green", "green"}

D) {"red", "green", "green"}

16. Predict the output of this program.

public static void main(String args[])

StringBuffer s1 = new StringBuffer("Hello");

StringBuffer s2 = s1.reverse();

System.out.println(s2);
}

A) Hello

B) olleH

C) HelloolleH

D) olleHHello

17. The default layout of the contentPane of a JApplet is __________.

A) FlowLayout

B) GridLayout

C) BorderLayout

D) BoxLayout

18. Interpret the output for the following code snippet.

System.out.println("Java is neat".replaceAll("is", "AAA"));

A) JavaAAAneat

B) JavaAAA neat

C) Java AAA neat

D) Java AAAneat

19. The interface __________ should be implemented to listen for a button


action event.

A) MouseListener

B) ActionListener

C) FocusListener

D) WindowListener
20. To use an applet in the HTML document, you use __________ in the
<applet> tag.

A) .java source code file

B) .class bytecode

C) .exe executable file

D) .html file

You might also like