Unit 1
Unit 2
Unit 3
Unit 4
Unit 5
100

System.out.print(“Happy”);

System.out.println(“Birthday”);

System.out.println(“To You”);

A. Happy

    Birthday

    To You

B. Happy Birthday 

    To You

C. HappyBirthday

    To You

D. HappyBirthdayTo You

C. HappyBirthday

    To You

100

How should we effectively compare the value of these strings?

name1 = new String(“Jade”)

name2 = new String(“Jade”)

a. System.out.println(name1.equals(name2));

b. System.out.println(name1 == name2);

c. System.out.println(name1 == “Jade”);

a. System.out.println(name1.equals(name2));

100

What is the result of the following code?

int x = 5;

if (x > 3 && x < 10) {

    System.out.println("A");

} else {

    System.out.println("B");

}


A. A
B. B
C. Compile-time error
D. Runtime error

A. A

100

for (int i = 0, i < 5, i++) {

    System.out.println(“*”);

}

How many times does loop print the output?

a. 6

b. 5

c. 4

d. 7

b. 5

100

What is the default in Java?

a. Public

b. Private

c. Package

d. Field

c. package


200

What does (8/5)*0.5 evaluate to?

A. 1

B. 0.5

C. 2

D. 0.25

B. 0.5

200

r.nextFloat() returns a 

a. A decimal number between 0.0 (excluded) and 1.0 (included)

b. A decimal number between 0.0 (included) and 1.0 (included)

c. A decimal number between 0.0 (included) and 1.0 (excluded)

d. A decimal number between 0.0 (excluded) and 1.0 (excluded)

c. A decimal number between 0.0 (included) and 1.0 (excluded)

200

Consider the following code:

boolean a = true;

boolean b = false;

if (!a || b) {

    System.out.println("X");

} else {

    System.out.println("Y");

}


What is the output?
A. X
B. Y
C. Compile-time error
D. Runtime error

B. Y

200

What is the output of this loop?

for (int i = 0; i < 5; i++) {

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

}

a) 0 1 2 3 4

b) 1 2 3 4 5

c) 0 1 2 3

d) 1 2 3 4

a) 0 1 2 3 4

200

Stack memory is used to store ______.

a. Variables, primitives, and references

b. Objects

c. Garbage collection

d. Constructors

a. Variables, primitives, and references

300

What does 

int x = 40;

int y = 70;

System.out.print(x+(x/y));

A. 110

B. 40

C. 70

D. 80

B. 40

300

(public / static) methods can be invoked through the class name.

static

300

What is the output of the following code?

int a = 3;

double b = 3.0;

if (a == b && !(a != 3)) {

    System.out.println("Equal");

} else {

    System.out.println("Not Equal");

}


A. Equal
B. Not Equal
C. Compile-time error
D. Runtime error

A. Equal

300

int i= a random number such that 1<=i<=n;

for (int a = 2; a <= i; a++){

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

System.out.println("*");

}

}

What is the minimum number of times that * will be printed?

(A) 0 

(B) 1

(C) 2 

(D) n-1

 (E) n-2

B. 1

300

What is the default value for the boolean data type?



false

400

What does 

double u = 40.8

double f = 70.32; 

System.out.println(u*f);

A. 2869.056

B. 0.58

C. Nothing is printed due to an error

D. 2800

C. Nothing is printed due to an error

400

When comparing primitive types, which of the following operators should be used?

a. equals()

b. ==

c. compareTo()

d. None of the above

b. ==

400

What will the following code print?

int x = 4, y = 6;

if (x < y) {

    if (x % 2 == 0 && y % 2 == 0) {

        System.out.println("Even Pair");

    } else if (x % 2 != 0 || y % 2 != 0) {

        System.out.println("Odd Number Present");

    } else {

        System.out.println("Neither");

    }

} else {

    System.out.println("Invalid Range");

}


A. Even Pair
B. Odd Number Present
C. Neither
D. Invalid Range

A. Even Pair

400

Does the following code produce an infinite loop?


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

    for (int j = 0; j < 5; j++) {

        if (i == 5) {

            i = 0;

        }

    }

}


A. Yes, because i resets to 0 indefinitely.

B. No, because the outer loop will eventually stop.

C. Yes, because j never reaches 5.

D. Compilation error.

B. No, because the outer loop will eventually stop.

400

Which is the proper use of this keyword?

a. // other code //
private String color;
// other code //
public void getColor(String color) {
    this.color = color;

 }

b. // other code //

private String color;
// other code //

public void setColor(String color) {
    this.color = color;

 }

c. // other code //

private String color;
// other code //

public void Color(String color) {
    this.color = color;

 }

d. // other code //

package String color;
// other code //

public void setColor(String color) {
    this.color = color;

 }



b. // other code //

private String color;
// other code //

public void setColor(String color) {
    this.color = color;

 }

500

int a = 1 + 2;

double b = 1.0 + 3.5;

int c = 3 - 5;

double d = 24 * 1.0;

What is the value of d

A. 3

B. 4.5

C. -2

D. 24.0

D. 24.0

500

 Identify the error in this code:


String greeting = "Hello";

System.out.println(greeting.charAt(5));

indexOutOfBounds exception

500

What is the output of the following program?

public class BooleanTest {

    public static boolean test(int a, int b) {

        return (a > b) || (a * b < 10);

    }


    public static void main(String[] args) {

        if (test(2, 4)) {

            System.out.println("Pass");

        } else {

            System.out.println("Fail");

        }

    }

}


A. Pass
B. Fail
C. Compile-time error
D. Runtime error

A. Pass

500

What is the output? 

int[] arr = {2, 4, 6, 8};

for (int i = 0; i < arr.length; i++) {

    arr[i] = arr[i] + i;

}

for (int val : arr) {

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

}


A. 2 4 6 8

B. 2 5 8 12

C. 3 6 9 12

D. 2 5 7 9

B. 2 5 8 12

500

When a null object contains a field or method that needs to be accessed, the program crashed and throws a ____________ Exception.

NullPointer