1. The Java interpreter is used for the execution of the source code.

True

False

2) On successful compilation a file with the class extension is created.

a) True

b) False

3) The Java source code can be created in a Notepad editor.

a) True

b) False

4) The Java Program is enclosed in a class definition.

a) True

b) False

5) What declarations are required for every Java application?

6) What are the two parts in executing a Java program and their purposes?

7) What are the three OOPs principles and define them?

8) What is a compilation unit?

9) In order for a source code file, containing the public class Test, to successfully compile, which of the following must be true?

It must have a package statement

It must be named Test.java

It must import java.lang

It must declare a public class named Test

10) What are identifiers and what is naming convention?

11) What is the return type of program’s main ( ) method?

12) What is the argument type of program’s main ( ) method?

13) Which characters are as first characters of an identifier?

14) What are different comments?

1) /* --

2) /** --

*/

15) What is the difference between constructor method and method?

16) What is the use of bin and lib in JDK?

Data types, variables and Arrays

17) What is meant by variable?

18) What are the kinds of variables in Java? What are their uses?

19) How are the variables declared?

20) What are variable types?

21) How do you assign values to variables?

22) What is an array?

23) How do you declare an array?

24) Java supports multidimensional arrays.

a)True

b)False

25) An array of arrays can be created.

a)True

b)False

26) Which operator is to create and concatenate string?

27) Which of the following are primitive types?

Byte

String

Integer

Float

28) What is the range of the char type?

0 to 216

0 to 215

0 to 216-1

0 to 215-1

29) Converting of primitive types to objects can be explicitly.

a)True

b)False

30) How do we change the values of the elements of the array?

31) What is final variable?

32) What is static variable?

Operators

33) The ++ operator is used for incrementing and the -- operator is used for

Decrementing.

a)True

b)False

34) Comparison/Logical operators are used for testing and magnitude.

a)True

b)False

35) Character literals are stored as unicode characters.

a)True

b)False

36) What are the Logical operators?

37) What is the % operator?

38) Which Java operator is right associativity?

39) What is the result of expression 5.45 + "3,2"?

The double value 8.6

The string ""8.6"

The long value 8.

The String "5.453.2"

40) What are the values of x and y ?

x = 5; y = ++x;

41) What are the values of x and z?

x = 5; z = x++;

Control Statements

42)public static void main(String args[]) {

int i = 20;

int j = 55;

int z = 0;

z = i < j ? i : j; // ternary operator

System.out.println("The value assigned is " + z);

}

}

What is output of the above program?

43) The switch statement does not require a break.

a)True

b)False

44) The conditional operator is otherwise known as the ternary operator.

a)True

b)False

45) The while loop repeats a set of code while the condition is false.

a)True

b)False

46) The do-while loop repeats a set of code atleast once before the condition is tested.

a)True

b)False

47) What are difference between break and continue?

48) The for loop repeats a set of statements a certain number of times until a condition is matched.

a)True

b)False

Classes and Methods

49) The new operator creates a single instance named class and returns a

reference to that object.

a)True

b)False

50) A class is a template for multiple objects with similar features.

a)True

b)False

51) What is mean by garbage collection?

52) What are methods and how are they defined?

53) What is calling method?

54) How can class be imported to a program?

55) What is a constructor?

56) Which keyword is used to create an instance of a class?

57) Which method is used to garbage collect an object?

58) What is casting?

59) Which of the following features are common to both Java & C++?

A.The class declaration

b.The access modifiers

c.The encapsulation of data & methods with in objects

d.The use of pointers

60) Which of the following statements accurately describe the use of access modifiers within a class definition?

a. They can be applied to both data & methods

b. They must precede a class's data variables or methods

c. They can follow a class's data variables or methods

d. They can appear in any order

e. They must be applied to data variables first and then to methods

61) The this reference is used in conjunction with ___methods.

a. static

b. non-static

62) Which of the following operators are used in conjunction with the this and super references?

a. The new operator

b. The instanceof operator

c. The dot operator

63) When may a constructor be called without specifying arguments?

a. When the default constructor is not called

b. When the name of the constructor differs from that of the class

c. When there are no constructors for the class

64) Because finalize () belongs to the java.lang.Object class, it is present in all ___.

a. objects

b. classes

c. methods

Packages and interface

65) How do you achieve multiple inheritance in Java?

66) Name interfaces without a method?

67) What is the difference between ‘throw’ and ‘throws’ ?And it’s application?

MULTI THREADING

68) What are the two types of multitasking?

69) What are the two ways to create the thread?

Inheritance

70) What is the difference between superclass & subclass?

71) Which of the following statements correctly describes an interface?

a)It's a concrete class

b)It's a superclass

c)It's a type of abstract class

72) An interface contains __ methods

a)Non-abstract

b)Implemented

c)unimplemented

73) Which of the following is not a wrapper class?

String

Integer

Boolean

Character

74) What is the output of the following program?

Public class Question {

Public static void main(String args[]) {

String s1 = "abc";

String s2 = "def";

String s3 = s1.concat(s2.toUpperCase( ) );

System.out.println(s1+s2+s3);

}

}

abcdefabcdef

abcabcDEFDEF

abcdefabcDEF

None of the above

75) Which of the following methods are methods of the String class?

Delete( )

Append( )

Reverse( )

Replace( )

76)Which of the following methods cause the String object referenced by s to be changed?

s.concat( )

s.toUpperCase( )

s.replace( )

s.valueOf( )

77) Given the following declarations

String s1=new String("Hello")

String s2=new String("there");

String s3=new String();

Which of the following are legal operations?

s3=s1 + s2;

s3=s1 - s2;

c) s3=s1 & s2
d) s3=s1 && s2

78) Which of the following will output -4.0

System.out.println(Math.floor(-4.7));

System.out.println(Math.round(-4.7));

System.out.println(Math.ceil(-4.7));

d) System.out.println(Math.Min(-4.7));

79) Which of the following are valid statements

a) public class MyCalc extends Math
b) Math.max(s);
c) Math.round(9.99,1);
d) Math.mod(4,10);

e) None of the above.

80)Which of the following statements are true?

a.When you construct an instance of File, if you do not use the filenaming b.semantics of the local machine, the constructor will throw an IOException.

When you construct an instance of File, if the corresponding file does not exist on the local file system, one will be created.

c.When an instance of File is garbage collected, the corresponding file on the local file system is deleted.

d.None of the above.

81.Which of the following are true?

a.The event-inheritance model has replaced the event-delegation model.

b.The event-inheritance model is more efficient than the event-delegation model.

c.The event-delegation model uses event listeners to define the methods of event-handling classes.

d.The event-delegation model uses the handleEvent( ) method to support event handling.

82)Which of the following is the highest class in the event-delegation model?

java.util.EventListener

java.util.EventObject

java.awt.AWTEvent

java.awt.event.AWTEvent

83)When two or more objects are added as listeners for the same event, which listener is first invoked to handle the event?

The first object that was added as listener.

The last object that was added as listener.

There is no way to determine which listener will be invoked first.

It is impossible to have more than one listener for a given event.

84)Which of the following components generate action events?

Buttons

Labels

Check boxes

Windows

85)Which of the following are true?

A TextField object may generate an ActionEvent.

A TextArea object may generate an ActionEvent.

A Button object may generate an ActionEvent.

A MenuItem object may generate an ActionEvent.

86)Which of the following are true?

The MouseListener interface defines methods for handling mouse clicks.

The MouseMotionListener interface defines methods for handling mouse clicks.

The MouseClickListener interface defines methods for handling mouse clicks.

The ActionListener interface defines methods for handling the clicking of a button.

87) What tags are mandatory when creating HTML to display an applet

name, height, width

code, name

codebase, height, width

d) code, height, width

88) What are the immediate super classes of the following classes?

a) Container class

b) MenuComponent class

c) Dialog class

d) Applet class

e) Menu class

89) Which method is method to set the layout of a container?

StartLayout( )

InitLayout( )

LayoutContainer( )

SetLayout( )

90) Which method returns the preferred size of a component?

GetPreferredSize( )

GetPreferred( )

GetRequiredSize( )

GetLayout( )

What will be the result of compiling the following code:

91)public class Test {

public static void main (String args []) {

int age;

age = age + 1;

System.out.println("The age is " + age);

}

}

1) Compiles and runs with no output

2) Compiles and runs printing out The age is 1

3) Compiles but generates a runtime error

4) Does not compile

5) Compiles but generates a compile time error

92)Which of these is the correct format to use to create the literal char value a?

(multiple)

1) 'a'

2) "a"

3) new Character(a)

4) \000a

93)What is the legal range of a byte integral type?

1) 0 - 65, 535

2) (-128) - 127

3) (-32,768) - 32,767

4) (-256) - 255

94)What will be the result of compiling the following code:

public class Test {

static int age;

public static void main (String args []) {

age = age + 1;

System.out.println("The age is " + age);

}

}

1) Compiles and runs with no output

2) Compiles and runs printing out The age is 1

3) Compiles but generates a runtime error

4) Does not compile

5) Compiles but generates a compile time error

95)Which of the following are correct?

1) 128 >> 1 gives 64

2) 128 >>> 1 gives 64

3) 128 >> 1 gives -64

4) 128 >>> 1 gives -64

96)Which of the following return true?

1) "john" == new String("john")

2) "john".equals("john")

3) "john" = "john"

4) "john".equals(new Button("john"))

97)What is the result of compiling and running the following code:

public class Test {

static int total = 10;

public static void main (String args []) {

new Test();

}

public Test () {

System.out.println("In test");

System.out.println(this);

int temp = this.total;

if (temp > 5) {

System.out.println(temp);

}

}

}

Which of the following is correct:

1) String temp [] = new String {"j" "a" "z"};

2) String temp [] = { "j " " b" "c"};

3) String temp = {"a", "b", "c"};

4) String temp [] = {"a", "b", "c"};

98)What is the correct declaration of an abstract method that is intended to be public:

1) public abstract void add();

2) public abstract void add() {}

3) public abstract add();

4) public virtual add();

99)Which of the following can be used to define a constructor for this class, given the following code:

public class Test {

...

}

1) public void Test() {...}

2) public Test() {...}

3) public static Test() {...}

4) public static void Test() {...}

100.What is the result of executing the following code, using the parameters 4 and 0:

public void divide(int a, int b) {

try {

int c = a / b;

} catch (Exception e) {

System.out.print("Exception ");

} finally {

System.out.println("Finally");

}

1) Prints out: Exception Finally

2) Prints out: Finally

3) Prints out: Exception

4) No output

101)Which of the following is a legal return type of a method overloading the following method:

public void add(int a) {...}

1) void

2) int

3) Can be anything

102)Which of the following statements is correct for a method which is overriding the following method:

public void add(int a) {...}

1) the overriding method must return void

2) the overriding method must return int

3) the overriding method can return whatever it likes

103)Given the following classes defined in separate files, what will be the effect of compiling and running this class Test?

class Vehicle {

public void drive() {

System.out.println("Vehicle: drive");

}

}

class Car extends Vehicle {

public void drive() {

System.out.println("Car: drive");

}

}

public class Test {

public static void main (String args []) {

Vehicle v;

Car c;

v = new Vehicle();

c = new Car();

v.drive();

c.drive();

v = c;

v.drive();

}

}

1) Generates a Compiler error on the statement v= c;

2) Generates runtime error on the statement v= c;

3) Prints out:

Vehicle: drive

Car: drive

Car: drive

4) Prints out:

Vehicle: drive

Car: drive

Vehicle: drive

104)Where in a constructor, can you place a call to a constructor defined in the super class?

1) Anywhere

2) The first statement in the constructor

3) The last statement in the constructor

4) You can't call super in a constructor

105)Which variables can an inner class access from the class which encapsulates it?

(multiple)

1) All static variables

2) All final variables

3) All instance variables

4) Only final instance variables

5) Only final static variables

106)What class must an inner class extend:

1) The top level class

2) The Object class

3) Any class or interface

4) It must extend an interface

107)In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected:

1. public class Test {

2. public static void main (String args []) {

3. Employee e = new Employee("Bob", 48);

4. e.calculatePay();

5. System.out.println(e.printDetails());

6. e = null;

7. e = new Employee("Denise", 36);

8. e.calculatePay();

9. System.out.println(e.printDetails());

10. }

11. }

1) Line 10

2) Line 11

3) Line 7

4) Line 8

5) Never

108)What is the name of the interface that can be used to define a class that can execute within its own thread?

1) Runnable

2) Run

3) Threadable

4) Thread

5) Executable

109)What is the name of the method used to schedule a thread for execution?

1) init();

2) start();

3) run();

4) resume();

5) sleep();

110)Which methods may cause a thread to stop executing?

(multiple)

1) sleep();

2) stop();

3) yield();

4) wait();

5) notify();

6) notifyAll()

7) synchronized()

111)Which of the following would create a text field able to display 10 characters (assuming a fixed size font) displaying the initial string "hello":

1) new TextField("hello", 10);

2) new TextField("hello");

3) new textField(10);

4) new TextField();

112)Which of the following methods are defined on the Graphics class:

(multiple)

1) drawLine(int, int, int, int)

2) drawImage(Image, int, int, ImageObserver)

3) drawString(String, int, int)

4) add(Component);

5) setVisible(boolean);

6) setLayout(Object);

113)Which of the following layout managers honours the preferred size of a component:

(multiple)

1) CardLayout

2) FlowLayout

3) BorderLayout

4) GridLayout

114)Given the following code what is the effect of a being 5:

public class Test {

public void add(int a) {

loop: for (int i = 1; i < 3; i++){

for (int j = 1; j < 3; j++) {

if (a == 5) {

break loop;

}

System.out.println(i * j);

}

}

}

}

1) Generate a runtime error

2) Throw an ArrayIndexOutOfBoundsException

3) Print the values: 1, 2, 2, 4

4) Produces no output

115)What is the effect of issuing a wait() method on an object

1) If a notify() method has already been sent to that object then it has no effect

2) The object issuing the call to wait() will halt until another object sends a notify() or notifyAll() method

3) An exception will be raised

4) The object issuing the call to wait() will be automatically synchronized with any other objects using the receiving object.

116)The layout of a container can be altered using which of the following methods:

(multiple)

1) setLayout(aLayoutManager);

2) addLayout(aLayoutManager);

3) layout(aLayoutManager);

4) setLayoutManager(aLayoutManager);

117)Using a FlowLayout manager, which is the correct way to add elements to a container:

1) add(component);

2) add("Center", component);

3) add(x, y, component);

4) set(component);

118)Given that a Button can generate an ActionEvent which listener would you expect to have to implement, in a class which would handle this event?

1) FocusListener

2) ComponentListener

3) WindowListener

4) ActionListener

5) ItemListener

119)Which of the following, are valid return types, for listener methods:

1) boolean

2) the type of event handled

3) void

4) Component

120)Assuming we have a class which implements the ActionListener interface, which method should be used to register this with a Button?

1) addListener(*);

2) addActionListener(*);

3) addButtonListener(*);

4) setListener(*);

121)In order to cause the paint(Graphics) method to execute, which of the following is the most appropriate method to call:

1) paint()

2) repaint()

3) paint(Graphics)

4) update(Graphics)

5) None - you should never cause paint(Graphics) to execute

122)Which of the following illustrates the correct way to pass a parameter into an applet:

1) <applet code=Test.class age=33 width=100 height=100>

2) <param name=age value=33>

3) <applet code=Test.class name=age value=33 width=100 height=100>

4) <applet Test 33>

123)Which of the following correctly illustrate how an InputStreamReader can be created:

(multiple)

1) new InputStreamReader(new FileInputStream("data"));

2) new InputStreamReader(new FileReader("data"));

3) new InputStreamReader(new BufferedReader("data"));

4) new InputStreamReader("data");

5) new InputStreamReader(System.in);

124)What is the permanent effect on the file system of writing data to a new FileWriter("report"), given the file report already exists?

1) The data is appended to the file

2) The file is replaced with a new file

3) An exception is raised as the file already exists

4) The data is written to random locations within the file

Answer : 2

125)What is the effect of adding the sixth element to a vector created in the following manner:

new Vector(5, 10);

1) An IndexOutOfBounds exception is raised.

2) The vector grows in size to a capacity of 10 elements

3) The vector grows in size to a capacity of 15 elements

4) Nothing, the vector will have grown when the fifth element was added

Answer : 3

126)What is the result of executing the following code when the value of x is 2:

switch (x) {

case 1:

System.out.println(1);

case 2:

case 3:

System.out.println(3);

case 4:

System.out.println(4);

}

1) Nothing is printed out

2) The value 3 is printed out

3) The values 3 and 4 are printed out

4) The values 1, 3 and 4 are printed out

Answer : 3

127)What is the result of compiling and running the Second class?

Consider the following example:

class First {

public First (String s) {

System.out.println(s);

}

}

public class Second extends First {

public static void main(String args []) {

new Second();

}

}

1) Nothing happens

2) A string is printed to the standard out

3) An instance of the class First is generated

4) An instance of the class Second is created

5) An exception is raised at runtime stating that there is no null parameter constructor in class First.

6) The class second will not compile as there is no null parameter constructor in the class First

Answer : 6

128)What is the result of executing the following fragment of code:

boolean flag = false;

if (flag = true) {

System.out.println("true");

} else {

System.out.println("false");

}

1) true is printed to standard out

2) false is printed to standard out

3) An exception is raised

4) Nothing happens

Answer : 1

129)Consider the following classes. What is the result of compiling and running this class?

public class Test {

public static void test() {

this.print();

}

public static void print() {

System.out.println("Test");

}

public static void main(String args []) {

test();

}

}

(multiple)

1) The string Test is printed to the standard out.

2) A runtime exception is raised stating that an object has not been created.

3) Nothing is printed to the standard output.

4) An exception is raised stating that the method test cannot be found.

5) An exception is raised stating that the variable this can only be used within an instance.

6) The class fails to compile stating that the variable this is undefined.

Answer : 6

130)Examine the following class definition:

public class Test {

public static void test() {

print();

}

public static void print() {

System.out.println("Test");

}

public void print() {

System.out.println("Another Test");

}

}

What is the result of compiling this class:

1) A successful compilation.

2) A warning stating that the class has no main method.

3) An error stating that there is a duplicated method.

4) An error stating that the method test() will call one or other of the print() methods.

Answer : 3

131)What is the result of compiling and executing the following Java class:

public class ThreadTest extends Thread {

public void run() {

System.out.println("In run");

suspend();

resume();

System.out.println("Leaving run");

}

public static void main(String args []) {

(new ThreadTest()).start();

}

}

1) Compilation will fail in the method main.

2) Compilation will fail in the method run.

3) A warning will be generated for method run.

4) The string "In run" will be printed to standard out.

5) Both strings will be printed to standard out.

6) Nothing will happen.

Answer : 4

132)Given the following sequence of Java statements, Which of the following options are true:

1. StringBuffer sb = new StringBuffer("abc");

2. String s = new String("abc");

3. sb.append("def");

4. s.append("def");

5. sb.insert(1, "zzz");

6. s.concat(sb);

7. s.trim();

(multiple)

1) The compiler would generate an error for line 1.

2) The compiler would generate an error for line 2.

3) The compiler would generate an error for line 3.

4) The compiler would generate an error for line 4.

5) The compiler would generate an error for line 5.

6) The compiler would generate an error for line 6.

7) The compiler would generate an error for line 7.

Answer : 4,6

133)What is the result of executing the following Java class:

import java.awt.*;

public class FrameTest extends Frame {

public FrameTest() {

add (new Button("First"));

add (new Button("Second"));

add (new Button("Third"));

pack();

setVisible(true);

}

public static void main(String args []) {

new FrameTest();

}

}

1) Nothing happens. Three buttons are displayed across a window.

3) A runtime exception is generated (no layout manager specified).

4) Only the "first" button is displayed.

5) Only the "second" button is displayed.

6) Only the "third" button is displayed.

Answer : 6

134)Consider the following tags and attributes of tags, which can be used with the <AAPLET> and </APPLET> tags?

1. CODEBASE

2. ALT

3. NAME

4. CLASS

5. JAVAC

6. HORIZONTALSPACE

7. VERTICALSPACE

8. WIDTH

9. PARAM

10. JAR

(multiple)

1) line 1, 2, 3

2) line 2, 5, 6, 7

3) line 3, 4, 5

4) line 8, 9, 10

5) line 8, 9

Answer : 1,5

135)Which of the following is a legal way to construct a RandomAccessFile:

1) RandomAccessFile("data", "r");

2) RandomAccessFile("r", "data");

3) RandomAccessFile("data", "read");

4) RandomAccessFile("read", "data");

Answer : 1

136)Carefully examine the following code, When will the string "Hi there" be printed?

public class StaticTest {

static {

System.out.println("Hi there");

}

public void print() {

System.out.println("Hello");

}

public static void main(String args []) {

StaticTest st1 = new StaticTest();

st1.print();

StaticTest st2 = new StaticTest();

st2.print();

}

}

1) Never.

2) Each time a new instance is created.

3) Once when the class is first loaded into the Java virtual machine.

4) Only when the static method is called explicitly.

Answer : 3

137)What is the result of the following program:

public class Test {

public static void main (String args []) {

boolean a = false;

if (a = true)

System.out.println("Hello");

else

System.out.println("Goodbye");

}

}

1) Program produces no output but terminates correctly.

2) Program does not terminate.

3) Prints out "Hello"

4) Prints out "Goodbye"

Answer : 3

138)Examine the following code, it includes an inner class, what is the result: