Font size
WorksheetsJava New Test
Total questions: 110
Worksheet time: 2hrs 21mins
Which of
the following variable declaration would NOT compile in a java program?
int
var;
int VAR;
int var1;
int
1_var;.
Which
one is java token?
Identifiers
Operators
Literals
all the
above
Java
compiler javac translates Java source code into ………………………
Assembler
language
Byte
code
Machine
code
Bit
code
Which is
one of the relational operators?
<
>
==
all of the above
The
operator who also acts as a string concatenation _______
a)
/
b) *
c)
+
d) –
Strings
represent a sequence of _____________
Variable
Character
Data type
All the above
Which of the following is used to identify the Java Programming Language ?
Map
Sun
Window
Cup of Coffee
Earlier name of Java was ....................
Coffee
Tree
Oak
JavaScript
Java was developed by ...............
Alan Tuning
James Gosling
Charles Babbage
None of the above
Java is short for "JavaScript".
true
false
How do you insert COMMENTS in Java code?
# This is a comment
/* This is a comment
// This is a comment
Which data type is used to create a variable that should store text?
myString
String
Txt
string
How do you create a variable with the numeric value 5?
float x = 5;
x = 5;
int x = 5;
num x = 5
How do you create a variable with the floating number 2.8?
byte x = 2.8f
x = 2.8f;
float x = 2.8f;
int x = 2.8f;
Which operator is used to add together two values?
The + sign
The * sign
The & sign
The value of a string variable can be surrounded by single quotes.
true
false
Which operator can be used to compare two values?
><
=
==
<>
In Java EE, EE stands for ___.
Entertainment Edition
Entrepreneur Edition
Enterprise Emperor
Enterprise Edition
The icon of Java program is taken from ___.
a cup of coffee
a tornado that spits fire
a volcano under water
a candle with a flame
Which component is used to compile, debug and execute java program?
JDK
JRE
JVM
JIT
Java was developed in which year
1992
1993
1994
1995
Main() method is not mandatory for a Java program
True
False
Which of the following is NOT a numeric data type
int
double
float
decimal
Which company owns Java?
Oracle
Microsoft
Apple
Intel
Which function is used to input float value in Java using Scanner class?
scanner_object . nextFloat( )
scanner_object . nextInt( )
scanner_object . nextfloat( )
scanner_object . NextFloat( )
Which function is used to input int value in Java using Scanner class?
scanner_object . nextInteger( )
scanner_object . nextInt( )
scanner_object . nextint( )
scanner_object . NextInt( )
What prints out "I love Java" successfully?
System.out.println(I love Java);
Systemoutprintln("I love Java);
System.out.println("I love" + " Java");
System.out.println("I love Java")
What is love? Baby dont hurt me. Dont hurt me. No more.
Which declaration will throw an error?
double num = 8;
int averageGrade = 89.7;
boolean done = false;
String done = "true";
How would you declare a variable storing a person's name?
string name = "Elroy";
name String = "Elroy";
String name = Elroy;
String name = "Elroy";
Me llamo Elroy
How would you declare a variable storing the tax rate?
int taxRate = 5.1;
taxRate = "5.1";
double taxRate = 5.1;
double taxRate = "5.1";
I do hereby declare thee Sir Tax Rate
What values can a boolean variable store?
true
false
hum hum
4
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?
It is too hot
It is pleasant
It is hot but not too much
runtime error
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");
}
Error
Incorrect code
x is greater than y
Error
Incorrect code
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")
}
Hello World
Hello World
Error
Error
Hello world
What will be the output of above statement-
5
No output
6
Error
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)?
Equilateral triangle
Scalene triangle
Isosceles triangle
All of the above
In a switch case, when the switch value does not respond to any case then the execution transfers to:
break
default
loop
none
Condition is essentially formed using:
Arithmetic operators
Relational operators
Logical operators
None
Which of the following is a conditional statement?
if
if else
if else if
all of the above
Which of the following statement accomplishes ‘fall through’?
if else
switch
for
nested if
A Java program executes but doesn’t give the desired output. It is due to:
logical error
syntax error
run time error
none
Re-write above statement using ternary operator-
if(X<=Y)
X=Y;
else
Y=X;
if(X<=Y) then X=Y else Y=X;
if(X<=Y) ? X=Y : Y=X;
(X<=Y) ? X=Y : Y=X;
What will be the output of following statement-
System.out.println('A'=='a');
true
false
A==a
A=97
What will be the output of following snippet-
Both are not equal
Both are equal
Syntax error
runtime error
Select correct output-
y is 0
y is 2
y is 1
y is 10
Which of the following statements is true.
for every 'if' there should be an 'else'.
for every 'else' there should be an 'if'.
'if' block can exist without an 'else'
'if' statement can be used inside another 'if' statement
int marks = 80;
if( marks > 70 )
System.out.println("Distinction");
System.out.println("Congratulations");
else if( marks > 35 )
System.out.println("Pass");
Distinction
Congratulations
Pass
Distinction
Error ('else' without 'if')
If there is Only one statement to be executed in if else block, giving braces are
must
optional
The if -else statement executes a block of code if a specified condition is
true
false
both
none
System.exit(0); is a method used to......
terminate the program
terminate the loop
none
Nested ifs can be replaced with which logical operator?
||
&&
!
none
What is output by the code? Pretend it says System.out.println
2
3
4
5
6
What is ouptut by the code? Pretend it says System.out.println
2
3
4
5
6
What is output by the code?
123
12
1234
12345
4321
123
12
1234
12345
4321
Pretend it says System.out.println
1383
83
1813
181383
1318
1 2 4 8 16 32 64
1 2 4 8 16 32
2 4 8 16 32 64
2 4 8 16 32
4 8 16 32 64
200 66 22 7 2
66 22 7 2
200 66 22 2
200 66 22
7
2
5
7
9
13
20
-1 0 2 5
-1 0 3 7
-1 1 4 8
0 2 5 9
0 1 3 7
Which of the following is NOT a data types in java
int
String
number
double
A while loop carries on as long as...
The condition in the brackets is true
The condition in the brackets is false
i < 10
the for loop has not ended
A while loop has the following format:
while (condition)
{
...
}
while
{
...
}
continue while (condition)
{
...
}
while [condition]
[
...;
]
OUTPUT?
int i = 1;
while (i < 5) {
System.out.println("Hello");
i++;
}
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
While loops are not really important or necessary in Java
True
False
How many stars are printed?
7
3
4
5
Infinite Loop
In total, how many times is the inner loop executed?
5
10
15
50
Infinite Loop
How many times does the loop print a *
40
20
24
30
Infinite Loop
What does the following code print?
A rectangle of 8 rows with 5 stars per row
A rectangle of 8 rows with 4 stars per row
A rectangle of 6 rows with 5 stars per row
A rectangle of 6 rows with 4 stars per row
Infinite Looo
What does the following code print?
A rectangle of 9 rows with 5 stars per row
A rectangle of 6 rows with 6 stars per row
A rectangle of 7 rows with 5 stars per row
A rectangle of 7 rows with 6 stars per row
Infinite Loop
What does the following code print?
5 6 7 8 9
4 5 6 7 8 9 10 11 12
3 5 7 9 11
3 4 5 6 7 8 9 10 11 12
How many times does the following method print a *?
9
6
7
10
If a loop condition is never satisfied then the loop does not execute.
1 2 4 8 16 32 64
1 2 4 8 16 32
2 4 8 16 32 64
2 4 8 16 32
4 8 16 32 64
200 66 22 7 2
66 22 7 2
200 66 22 2
200 66 22
7
10
15
17
22
25
2
5
7
9
13
20
-1 0 2 5
-1 0 3 7
-1 1 4 8
0 2 5 9
0 1 3 7
0.0
-4.0
5
The program will end successfully, but nothing will be printed.
Nothing will be printed. Run-time error: ArithmeticException.
What will the following program segment display?
for(int a = 2; a <= 10; a += 3)
System.out.print(a+””);
2 5 8
2 5
2 5 8 11
2
int count = 0;
while (count < 10) {
System.out.println("Welcome to Java");
count++;
}
int x = 0;
while (x < 4) {
x = x + 1;
}
System.out.println("x is " + x);
T && T =
T
F
T && F =
T
F
F && F =
T
F
F || F =
T
F
F && T =
T
F
T || F =
T
F
F || T =
T
F
!T =
T
F
!T || T =
T
F
!T && T =
T
F
Is "X" printed?
YES
NO
Is "X" printed?
YES
NO
Is "X" printed?
YES
NO
Is "X" printed?
YES
NO
Click ALL answers which result in an "X" printed.
a = 3, b = 3, c = 3
a = 5, b = 4, c = 7
a = 1, b = 3, c = 5
a = 6, b = 4, c = 3
a = 5, b = 5, c = 3
What is output?
Jackson
Memorial
JacksonMemorial
There is no ouptut
What is output?
0
1
2
3
What is output?
-1
0
1
2
What is output?
-1
0
1
2
