wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java New Test

Total questions: 110

Worksheet time: 2hrs 21mins

Name
Class
Date
1.

Which of

the following variable declaration would NOT compile in a java program?

a)

int

var;

b)

int VAR;

c)

int var1;

d)

int

1_var;.

2.

Which

one is java token?

a)

Identifiers

b)

Operators

c)

Literals

d)

all the

above

3.

Java

compiler javac translates Java source code into ………………………

a)

Assembler

language

b)

Byte

code

c)

Machine

code

d)

Bit

code

4.

Which is

one of the relational operators?

a)

<

b)

>

c)

==

d)

all of the above

5.

The

operator who also acts as a string concatenation _______

a)

a)

/

b)

b) *

c)

c)

+

d)

d) –

6.

Strings

represent a sequence of _____________

a)

Variable

b)

Character

c)

Data type

d)

All the above

7.

Which of the following is used to identify the Java Programming Language ?

a)

Map

b)

Sun

c)

Window

d)

Cup of Coffee

8.
JVM Stands for __________________.
a)
Java Virtual Memory
b)
Java Virtual Management
c)
Java Virtual Machanism
d)
Java Virtual Machine
9.
Platform independent code file created from Source file is understandable by _______________.
a)
Applet
b)
Compiler
c)
JRE
d)
JVM
10.
Which of the following converts human readable file into platform independent code file in Java?
a)
Applet
b)
Compiler
c)
JRE
d)
JVM
11.
Following file is human readable in Java programming language.
a)
.class
b)
.jar
c)
.obj
d)
.java
12.
Java Programming promises programmer - "Write Once, Run Anywhere".
a)
false
b)
true
13.
The first public implementation was _____________.
a)
Java 1.0
b)
Java 0.1
c)
Java Premium 1.0
d)
Java 1.1
14.
Java was publicly released in _______________ .
a)
May 27, 1994
b)
May 27, 1995
c)
May 27, 1993
d)
May 27, 1992
15.
Java Programming was designed by _________________
a)
Sun Microsystems
b)
Microsoft
c)
Mozilla Corporation
d)
Amazon Inc.
16.

Earlier name of Java was ....................

a)

Coffee

b)

Tree

c)

Oak

d)

JavaScript

17.

Java was developed by ...............

a)

Alan Tuning

b)

James Gosling

c)

Charles Babbage

d)

None of the above

18.

Java is short for "JavaScript".

a)

true

b)

false

19.

How do you insert COMMENTS in Java code?

a)

# This is a comment

b)

/* This is a comment

c)

// This is a comment

20.

Which data type is used to create a variable that should store text?

a)

myString

b)

String

c)

Txt

d)

string

21.

How do you create a variable with the numeric value 5?

a)

float x = 5;

b)

x = 5;

c)

int x = 5;

d)

num x = 5

22.

How do you create a variable with the floating number 2.8?

a)

byte x = 2.8f

b)

x = 2.8f;

c)

float x = 2.8f;

d)

int x = 2.8f;

23.

Which operator is used to add together two values?

a)

The + sign

b)

The * sign

c)

The & sign

24.

The value of a string variable can be surrounded by single quotes.

a)

true

b)

false

25.

Which operator can be used to compare two values?

a)

><

b)

=

c)

==

d)

<>

26.

In Java EE, EE stands for ___.

a)

Entertainment Edition

b)

Entrepreneur Edition

c)

Enterprise Emperor

d)

Enterprise Edition

27.

The icon of Java program is taken from ___.

a)

a cup of coffee

b)

a tornado that spits fire

c)

a volcano under water

d)

a candle with a flame

28.

Which component is used to compile, debug and execute java program?

a)

JDK

b)

JRE

c)

JVM

d)

JIT

29.

Java was developed in which year

a)

1992

b)

1993

c)

1994

d)

1995

30.

Main() method is not mandatory for a Java program

a)

True

b)

False

31.

Which of the following is NOT a numeric data type

a)

int

b)

double

c)

float

d)

decimal

32.

Which company owns Java?

a)

Oracle

b)

Microsoft

c)

Google

d)

Apple

e)

Intel

33.

Which function is used to input float value in Java using Scanner class?

a)

scanner_object . nextFloat( )

b)

scanner_object . nextInt( )

c)

scanner_object . nextfloat( )

d)

scanner_object . NextFloat( )

34.

Which function is used to input int value in Java using Scanner class?

a)

scanner_object . nextInteger( )

b)

scanner_object . nextInt( )

c)

scanner_object . nextint( )

d)

scanner_object . NextInt( )

35.

What prints out "I love Java" successfully?

a)

System.out.println(I love Java);

b)

Systemoutprintln("I love Java);

c)

System.out.println("I love" + " Java");

d)

System.out.println("I love Java")

e)

What is love? Baby dont hurt me. Dont hurt me. No more.

36.

Which declaration will throw an error?

a)

double num = 8;

b)

int averageGrade = 89.7;

c)

boolean done = false;

d)

String done = "true";

37.

How would you declare a variable storing a person's name?

a)

string name = "Elroy";

b)

name String = "Elroy";

c)

String name = Elroy;

d)

String name = "Elroy";

e)

Me llamo Elroy

38.

How would you declare a variable storing the tax rate?

a)

int taxRate = 5.1;

b)

taxRate = "5.1";

c)

double taxRate = 5.1;

d)

double taxRate = "5.1";

e)

I do hereby declare thee Sir Tax Rate

39.

What values can a boolean variable store?

a)

true

b)

false

c)

hum hum

d)

4

40.

public void main()

{

double temp = 56.0;

if (temp <=54.0 && temp>40)

System.out.println(“It is too hot”);

else if ( temp<40 || temp>30)

System.out.println(“It is hot but not too much”);

else

System.out.println(“It is pleasant”);

}


What will be the output?

a)

It is too hot

b)

It is pleasant

c)

It is hot but not too much

d)

runtime error

41.

PREDICT THE OUTPUT:

int x = 20;

int y = 18;

if(x>y)

System.out.println("x is greater than y");

else

{

System.out.println("Error");

System.out.println("Incorrect code");

}

a)

Error

b)

Incorrect code

c)

x is greater than y

d)

Error

Incorrect code

42.

PREDICT THE OUTPUT:

int x = 60;

int y = 90;

if (y%x == 0 && y-x==30)

{

System.out.println("Hello World");

}

else

{

System.out.println("Error")

}

a)

Hello World

b)

Hello World

Error

c)

Error

d)

Hello world

43.

What will be the output of above statement-

a)

5

b)

No output

c)

6

d)

Error

44.

5. If a, b and c are the sides of a triangle then which of the following statement is true for:

if(a==b && a==c && b==c)?

a)

Equilateral triangle

b)

Scalene triangle

c)

Isosceles triangle

d)

All of the above

45.

In a switch case, when the switch value does not respond to any case then the execution transfers to:

a)

break

b)

default

c)

loop

d)

none

46.

Condition is essentially formed using:

a)

Arithmetic operators

b)

Relational operators

c)

Logical operators

d)

None

47.

Which of the following is a conditional statement?

a)

if

b)

if else

c)

if else if

d)

all of the above

48.

Which of the following statement accomplishes ‘fall through’?

a)

if else

b)

switch

c)

for

d)

nested if

49.

A Java program executes but doesn’t give the desired output. It is due to:

a)

logical error

b)

syntax error

c)

run time error

d)

none

50.

Re-write above statement using ternary operator-

if(X<=Y)

X=Y;

else

Y=X;

a)

if(X<=Y) then X=Y else Y=X;

b)

if(X<=Y) ? X=Y : Y=X;

c)

(X<=Y) ? X=Y : Y=X;

51.

What will be the output of following statement-

System.out.println('A'=='a');

a)

true

b)

false

c)

A==a

d)

A=97

52.

What will be the output of following snippet-

a)

Both are not equal

b)

Both are equal

c)

Syntax error

d)

runtime error

53.

Select correct output-

a)

y is 0

b)

y is 2

c)

y is 1

d)

y is 10

54.

Which of the following statements is true.

a)

for every 'if' there should be an 'else'.

b)

for every 'else' there should be an 'if'.

c)

'if' block can exist without an 'else'

d)

'if' statement can be used inside another 'if' statement

55.

int marks = 80;

if( marks > 70 )

System.out.println("Distinction");

System.out.println("Congratulations");

else if( marks > 35 )

System.out.println("Pass");

a)

Distinction

Congratulations

b)

Pass

c)

Distinction

d)

Error ('else' without 'if')

56.

If there is Only one statement to be executed in if else block, giving braces are

a)

must

b)

optional

57.

The if -else statement executes a block of code if a specified condition is

a)

true

b)

false

c)

both

d)

none

58.

System.exit(0); is a method used to......

a)

terminate the program

b)

terminate the loop

c)

none

59.

Nested ifs can be replaced with which logical operator?

a)

||

b)

&&

c)

!

d)

none

60.

What is output by the code? Pretend it says System.out.println

a)

2

b)

3

c)

4

d)

5

e)

6

61.

What is ouptut by the code? Pretend it says System.out.println

a)

2

b)

3

c)

4

d)

5

e)

6

62.

What is output by the code?

a)

123

b)

12

c)

1234

d)

12345

e)

4321

63.
a)

123

b)

12

c)

1234

d)

12345

e)

4321

64.

Pretend it says System.out.println

a)

1383

b)

83

c)

1813

d)

181383

e)

1318

65.
a)

1 2 4 8 16 32 64

b)

1 2 4 8 16 32

c)

2 4 8 16 32 64

d)

2 4 8 16 32

e)

4 8 16 32 64

66.
a)

200 66 22 7 2

b)

66 22 7 2

c)

200 66 22 2

d)

200 66 22

e)

7

67.

2

a)

5

b)

7

c)

9

d)

13

e)

20

68.
a)

-1 0 2 5

b)

-1 0 3 7

c)

-1 1 4 8

d)

0 2 5 9

e)

0 1 3 7

69.

Which of the following is NOT a data types in java

a)

int

b)

String

c)

number

d)

double

70.

A while loop carries on as long as...

a)

The condition in the brackets is true

b)

The condition in the brackets is false

c)

i < 10

d)

the for loop has not ended

71.

A while loop has the following format:

a)

while (condition)

{

...

}

b)

while

{

...

}

c)

continue while (condition)

{

...

}

d)

while [condition]

[

...;

]

72.

OUTPUT?

int i = 1;

while (i < 5) {

System.out.println("Hello");

i++;

}

a)

Hello

Hello

Hello

Hello

Hello

b)

Hello

Hello

Hello

Hello

c)

Hello

Hello

Hello

d)

Hello

73.

While loops are not really important or necessary in Java

a)

True

b)

False

74.

How many stars are printed?

a)

7

b)

3

c)

4

d)

5

e)

Infinite Loop

75.

In total, how many times is the inner loop executed?

a)

5

b)

10

c)

15

d)

50

e)

Infinite Loop

76.

How many times does the loop print a *

a)

40

b)

20

c)

24

d)

30

e)

Infinite Loop

77.

What does the following code print?

a)

A rectangle of 8 rows with 5 stars per row

b)

A rectangle of 8 rows with 4 stars per row

c)

A rectangle of 6 rows with 5 stars per row

d)

A rectangle of 6 rows with 4 stars per row

e)

Infinite Looo

78.

What does the following code print?

a)

A rectangle of 9 rows with 5 stars per row

b)

A rectangle of 6 rows with 6 stars per row

c)

A rectangle of 7 rows with 5 stars per row

d)

A rectangle of 7 rows with 6 stars per row

e)

Infinite Loop

79.

What does the following code print?

a)

5 6 7 8 9

b)

4 5 6 7 8 9 10 11 12

c)

3 5 7 9 11

d)

3 4 5 6 7 8 9 10 11 12

80.

How many times does the following method print a *?

a)

9

b)

6

c)

7

d)

10

81.
True/False
If a loop condition is never satisfied then the loop does not execute.
a)
True
b)
False
82.
a)

1 2 4 8 16 32 64

b)

1 2 4 8 16 32

c)

2 4 8 16 32 64

d)

2 4 8 16 32

e)

4 8 16 32 64

83.
a)

200 66 22 7 2

b)

66 22 7 2

c)

200 66 22 2

d)

200 66 22

e)

7

84.
a)

10

b)

15

c)

17

d)

22

e)

25

85.

2

a)

5

b)

7

c)

9

d)

13

e)

20

86.
a)

-1 0 2 5

b)

-1 0 3 7

c)

-1 1 4 8

d)

0 2 5 9

e)

0 1 3 7

87.
a)

0.0

b)

-4.0

c)

5

d)

The program will end successfully, but nothing will be printed.

e)

Nothing will be printed. Run-time error: ArithmeticException.

88.

What will the following program segment display?


for(int a = 2; a <= 10; a += 3)

System.out.print(a+””);

a)

2 5 8

b)

2 5

c)

2 5 8 11

d)

2

89.
How many times will the following code print "Welcome to Java"?
int count = 0;
while (count < 10) {
 System.out.println("Welcome to Java");
 count++;
}
a)
8
b)
9
c)
10
d)
0
90.
What is the output of the following code?
int x = 0;
while (x < 4) {
 x = x + 1;
}
System.out.println("x is " + x);
a)
0
b)
1
c)
3
d)
4
91.
Boolean values are: 
a)
True / False
b)
Yes / No
c)
Right / Wrong
92.

T && T =

a)

T

b)

F

93.

T && F =

a)

T

b)

F

94.

F && F =

a)

T

b)

F

95.

F || F =

a)

T

b)

F

96.

F && T =

a)

T

b)

F

97.

T || F =

a)

T

b)

F

98.

F || T =

a)

T

b)

F

99.

!T =

a)

T

b)

F

100.

!T || T =

a)

T

b)

F

101.

!T && T =

a)

T

b)

F

102.

Is "X" printed?

a)

YES

b)

NO

103.

Is "X" printed?

a)

YES

b)

NO

104.

Is "X" printed?

a)

YES

b)

NO

105.

Is "X" printed?

a)

YES

b)

NO

106.

Click ALL answers which result in an "X" printed.

a)

a = 3, b = 3, c = 3

b)

a = 5, b = 4, c = 7

c)

a = 1, b = 3, c = 5

d)

a = 6, b = 4, c = 3

e)

a = 5, b = 5, c = 3

107.

What is output?

a)

Jackson

b)

Memorial

c)

JacksonMemorial

d)

There is no ouptut

108.

What is output?

a)

0

b)

1

c)

2

d)

3

109.

What is output?

a)

-1

b)

0

c)

1

d)

2

110.

What is output?

a)

-1

b)

0

c)

1

d)

2