Font size
WorksheetsJava TEST
Total questions: 195
Worksheet time: 3hrs 23mins
It is used to store two types of values, i.e., true or false. This data type is commonly used as a flag in code logic.
boolean
byte
char
String
It can store 8-bit signed two’s complement integer. The range lies between -128 to 127
byte
boolean
char
string
This data type is used to store a single 16-bit Unicode character. It stores just one character in simple words, and the word Unicode is used because java uses the Unicode system, not the ASCII system. The size of this data type is 16bits (2 bytes).
byte
boolean
char
int
It is a data type that stores 32 bit(4 bytes) two’s complement integer, i.e., its range lies within (-2^31 to 2^32 – 1).
int
float
double
String
Similar to ‘int,’ it is also used to store integer values but within 16-bit (2 bytes) signed two’s complement. Its range lies within (-2^15 to 2^16-1).
int
long
short
byte
It is 64 bit two’s complement integer and its range lies within (-2^63 to2^64 – 1) i.e. ( -9,223,372,036,854,775,808 to 9,223,372,036,854,775,808).
int
short
long
byte
It is a data type that holds data with more precision, i.e., floating-point numbers. It is a single-precision 32-bit (4 bytes) IEEE754 floating-point.
int
float
double
char
It is a double-precision 64-bit (8 bytes) IEEE754 floating point.
float
double
long
int
It is a sequence of characters.
char
string
boolean
int
An element of a program that defines the type of data that a variable will hold
variable
expression
operator
data type
Is "X" printed?
YES
NO
Is "X" printed?
YES
NO
Is "X" printed?
YES
NO
Given : a = 1, b = 2
if ( missing ) print "X"
Select ALL expressions which can be used for missing to result in an "X" being printed.
a < 2
a != b
a > b
b >= a
b == a
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 output will be produced by the following segment of code?
Too Low
Too High
Syntax Error
No Output - Logic Error
What output will be produced by the following segment of code?
Too Low
Too High
Syntax Error
No Output - Logic Error
What output will be produced by the following segment of code?
Too Low
Too High
Syntax Error
No Output - Logic Error
What output will be produced by the following segment of code?
Too Low
Too High
Syntax Error
No Output - Logic Error
If x = 5 and y = 10, evaluate the following:
((x != 5) || (y == 9))
True
False
4 % 6
4
6
2
3
6 % 4
4
6
2
3
int a = 7;
int b = 2 + a;
b = 9
b = 2
b = 7
b = 5
int a = 5;
a++;
What is a now?
4
7
5
6
int a = 5;
a--;
What is a now?
4
3
5
6
What will print?
System.out.println( 1 / 4 );
0
0.25
1
4
What will print?
System.out.println( 1.0 / 4 );
0
0.25
1
4
What will print?
System.out.println( (double) 1 / 4 );
0
0.25
1
4
int x = 4;
x *= 10;
Which is true?
x is now 40
x is now 10
x is still 4
x is now 14
What is the value of b after this code segment?
int a = 4;
int b = a++;
a = a * 2;
b /= 2;
2
4
5
8
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
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]
[
...;
]
A condition in Javacould be any of the following:
a >, <, ==, >=, <= relation
str1.equals(str2)
str1.equalsIgnoreCase(str2)
str.length()
While loops are used when ...
You are not sure how many times exactly a loop should iterate
You want a loop to repeat while the condition is true
You don't like for loops
You don't like to wait for things
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
Write method header to Return a sales commission, given the sales amount and the commission rate
public static double getCommission(double salesAmount)
public static double getCommission(double salesAmount, double commissionRate)
double getCommission(double salesAmount, double commissionRate)
public static double(double salesAmount, double commissionRate)
Write method header Display the calendar for a month, given the month and year
public static void (int month, int year, int day)
public static void printCalendar(int year)
public static void printCalendar(int month, int year)
void printCalendar(int month, int year)
Write method header to Return a square root of a number
public static void double sqrt(value)
public static void double sqrt(double value)
public static double sqrt(value)
public static double sqrt(double value)
Write method header to Display a message a specified number of times
public static printMessage(int times, ntimes)
public static void (String message, int times)
public static void printMessage(String message, int times)
public static void printMessage(int times)
Write method header to Return the monthly payment, given the loan amount, number of years, and annual interest rate.
public static monthlyPayment(double loan, int numberOfYears, double annualInterestRate)
public static void double monthlyPayment(double loan, int numberOfYears, double annualInterestRate)
public static double monthlyPayment()
public static double monthlyPayment(double loan, int numberOfYears, double annualInterestRate)
Write method header to Return the corresponding uppercase letter, given a lowercase letter
public static char getUpperCase(char letter)
public static void char getUpperCase(char letter)
public static void getUpperCase(char letter)
public static char getUpperCase()
Java was developed by ...............
Alan Tuning
James Gosling
Charles Babbage
None of the above
Earlier name of Java was ....................
Coffee
Tree
Oak
JavaScript
Which of the following is used to identify the Java Programming Language ?
Map
Sun
Window
Cup of Coffee
Which of the following is NOT a data types in java
int
String
number
double
What is right way of defining String variable?
String name = "John";
String name = "John"
String name = John;
String name "John";
float myFloatNum = 5.99f;
System.out.println(myFloatNum);
What will be the output?
5.99
5.99f
"5.99"
"5.99"f
int x = 5;
int y = 6
int z = 50;
System.out.println(x + y + z);
What will be the output?
61
5650
66
x + y + z
Which of the following is the right way of defining char variable?
char myGrade = 'B';
char myGrade = "B";
char myGrade 'B';
char myGrade = "B"
int sum1 = 100 + 50;
int sum2 = sum1 + 250;
int sum3 = sum2 + sum2;
System.out.println(sum3);
What will be the final output?
950
800
sum2sum2
sum1250
Which of the following is assignment operator?
==
=
=+
++
int x = 10;
x = x + 5;
System.out.println(x);
What will be the output?
15
5
55
x5
x /= 3
Which of the below statements matches with above statement?
x = 3 / x
x = x / 3
x / 3
x /x = 3
int x = 4.4;
int y = 5.5;
System.out.println(x == y);
What will be the output?
4.4
true
false
5.5
What is the output of below code?
int x = 5;
System.out.println(x++);
System.out.println(x);
5
5
6
6
5
6
6
5
Which of these keywords is used to make a class?
class
struct
int
none of the mentioned
What is the extension of compiled java classes?
.java
.class
.txt
.js
Which component is used to compile, debug and execute java program?
JVM
JDK
JIT
JRE
Evaluate the following Java expression, if x=3, y=5, and z=10:
++z + y - y + z + x++
24
23
20
25
What does the expression float a = 35 / 0 return?
0
Not a number
Infinity
Run time exception
Which means wild card, or 'all the things'?
//
!
*
wc
Which line never changes?
public static void main(String[] args){
public class ThisGame{
Scanner input = new Scanner(System.in);
Boolean AndrewIsHere = false;
Which of the following class is used to read input during execution?
Array
String
Scanner
Main
Which of the following is the best description of a "relational operator"?
Comparison symbols used in logical expressions
Mathematical symbols used to calculate numeric results
Links that control the relationships between objects
None of these are true
Given two numbers A and B, which of the following expressions will be true when "A is less than B"?
A < B
A > B
A == B
A != B
Given two numbers A and B, which of the following expressions will be true when "A is equal to B"?
A != B
A == B
A = B
A.eq(B)
Given the following code, what will be displayed when the program is run?
int A = 5; int B = 10;
System.out.print(A != B);
System.out.print(" ");
System.out.print(A < B);
true false
false false
true true
false true
Which of the following expressions (A, B, C) is considered a logical expression?
A) 6 + 4
B) (6 + 4) >= 10
C) 4 < 10
A only
B and C only
A, B, and C
C only
What happens if you do not follow an if() statement with opening and closing curly braces?
All following statements that are indented to the right are part of the if() body
This is a compile-time syntax error
You must follow immediately with another if() statement
The next statement only is part of the if() body
What is the difference between the following three if() statements?
double sodaCost = 2.50;
if (sodaCost > 2.00)
System.out.println("I'll have water instead");
if (sodaCost > 2.00)
System.out.println("I'll have water instead");
if (sodaCost > 2.00)
System.out.println("I'll have water instead");
Only the second one is valid; the other two produce compile-time errors
Impossible to tell without running the program
The second two if() statements are nested inside the first and will only run if the first is true
All three work exactly the same way and produce the same output
Given the following boolean value, how would you write an if() statement that will execute if that value is true?
boolean run_me = true;
All of these will work
if (run_me)
if (run_me == true)
if (run_me != false)
Given the following code, which of these if() statements will produce a compile-time error?
int value = 12;
All of these are compile-time errors
if (value = 13)
if (value + 1)
if (value += 5)
What will be displayed when the following statements are run?
String pet = "cat";
if (pet.equals("dog")) {
System.out.println("WOOF"); }
if (pet.equals("dog") == false) {
System.out.println("MEOW"); }
MEOW
WOOF
WOOF MEOW
MEOW WOOF
Given the if() / else if() code outlined below, when will the statements in the body of the "else if()" be run?
if () {
// body of if()
}
else if () {
// body of else if()
}
When both logical expressions are true
When logical expression 1 is false and logical expression 2 is true
When logical expression 1 is true and logical expression 2 is false
When both logical expressions are false
Given the if() / else if() / else code outlined below, when will the statements in the body of the "else" be run?
if () { // body of if() }
else if () { // body of else if() }
else { // body of else }
When logical expression 1 is false and logical expression 2 is true
When both logical expressions are false
When both logical expressions are true
When logical expression 1 is true and logical expression 2 is false
Given the nested if() code outlined below, when will the statements in the body of the inner "if()" be run?
if () {
if ()
{ // body of inner if() } }
When logical expression 1 is false and logical expression 2 is true
When both logical expressions are false
When logical expression 1 is true and logical expression 2 is false
When both logical expressions are true
Given the code outlined below, how many output lines would be displayed if the program runs? if () { System.out.println("Line A"); return; } else { System.out.println("Line B"); return; } System.out.println("Line C");
2 lines will always appear
1 line will always appear
3 lines will always appear
It depends on the result of the logical expression
Where is it permissible to add a nested if() statement?
Inside the body of an "if()" block
All of these are true
Inside the body of an "else if()" block
Inside the body of an "else" block
When would you be more likely to use a chain of if() / else if() / else statements instead of a switch()?
When your logic needs to test multiple variables
When your logic needs to test multiple variables
Both of these are true
When your logic needs to test multiple variables
In a switch() statement, what comes between the "case" keyword and the colon?
An object reference
A specific number, letter, or quoted-string value
A logical expression
A mathematical expression
When the code below runs, what message will be displayed on the screen?
char grade = 'A';
switch(grade) {
case 'A':
System.out.println("90 - 100");
break;
case 'B':
System.out.println("80 - 89");
break;
case 'C':
System.out.println("70- 79");
break; }
80 - 89
90 - 100
70 - 79
Nothing will appear
What happens in a switch() statement if you leave out the "break" statement between the first and second cases?
switch(value) {
case 1: // statements in first case
case 2: // statements in second case }
Java will report a compile-time syntax error
If the first case is a match, the program will flow through from that case and execute the second case body as well
The program will only execute the statements in the first case
The program will only execute the statements in the second case
What message will appear on the screen when the following code is run?
String sport = "BASKETBALL";
switch (sport) {
case "basketball":
System.out.println("I love to play hoops");
break;
case "baseball":
System.out.println("My preferred position is pitcher");
break;
case "soccer":
System.out.println("I am a goal-scoring machine");
break;
default:
System.out.println("I've never played that sport");
break; }
I've never played that sport
I love to play hoops
My preferred position is pitcher
I am a goal-scoring machine
Is "X" printed?
YES
NO
Is "X" printed?
YES
NO
Is "X" printed?
YES
NO
Given : a = 1, b = 2
if ( missing ) print "X"
Select ALL expressions which can be used for missing to result in an "X" being printed.
a < 2
a != b
a > b
b >= a
b == a
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 output will be produced by the following segment of code?
Too Low
Too High
Syntax Error
No Output - Logic Error
What output will be produced by the following segment of code?
Too Low
Too High
Syntax Error
No Output - Logic Error
What output will be produced by the following segment of code?
Too Low
Too High
Syntax Error
No Output - Logic Error
What output will be produced by the following segment of code?
Too Low
Too High
Syntax Error
No Output - Logic Error
If x = 5 and y = 10, evaluate the following:
((x != 5) || (y == 9))
True
False
What would the new value of A be?
A=1;
a++;
1
2
3
4
What would the new value of A be?
A=1;
A--;
0
1
2
-1
What's the value of below?
int i=5;
System.out.println(i);
System.out.println(++i);
6
7
67
7
8
5
6
What does the following code output?
int x = 1;
System.out.println(x++);
1
2
compilation error
runtime error
Which statement(s) are equivalent to i = i + 1?
i += 1
i++
i -= 1
i--
What symbol represents the and operator in Java?
AND
and
&
&&
What symbol represents the or operator in Java?
OR
or
||
|
If a=2, b=5, c=3
Find result for : 8 * (a + b + c) – a % c
80
81
77
78
int a = 2, b = 2, c = 0;
double d = 30.1;
Find answer for = (a > b) &&(( c <d) || (c!=a))
35.9
80
true
false
It is a general programming language that is compatible for all computer system.
Netbeans
Visual Basic
HTML
Java
He is the developer of Java programming language
James Dosling
James Gosling
James Gostling
James Gusling
First java web browser
Netscape Browser
Hut Java
Hot Java
In 1800s, Island that is a main source and provider of coffee.
Java Island
Indonesia
Bali, Island
Java Programming
Company of the creator of Java Programming Language
Netscape Incorporated
Sun Microsystem
Sun System
Nescape Incorporated
Why James change the first name of programming language he created?
He discovered that a programming language already
existed that was named Visual Basic.
He discovered that a programming language already
existed that was named Java.
He discovered that a programming language already
existed that was named Oak.
He discovered that a programming language already
existed that was named Koa.
Java program that runs in a Web browser
Java system
Java Application
Java Servlet
Java Applets
In 1995, it is the Java web browser until it almost disappeared in 2002.
Nescape Incorporated
Java Programming Language
Netscape Browser
Java Applets
Logo of Java Programming
Company that uses oak operating system now.
Nokia
Samsung
Huawei
Apple
It is used to store two types of values, i.e., true or false. This data type is commonly used as a flag in code logic.
boolean
byte
char
String
It can store 8-bit signed two’s complement integer. The range lies between -128 to 127
byte
boolean
char
string
This data type is used to store a single 16-bit Unicode character. It stores just one character in simple words, and the word Unicode is used because java uses the Unicode system, not the ASCII system. The size of this data type is 16bits (2 bytes).
byte
boolean
char
int
It is a data type that stores 32 bit(4 bytes) two’s complement integer, i.e., its range lies within (-2^31 to 2^32 – 1).
int
float
double
String
Similar to ‘int,’ it is also used to store integer values but within 16-bit (2 bytes) signed two’s complement. Its range lies within (-2^15 to 2^16-1).
int
long
short
byte
It is 64 bit two’s complement integer and its range lies within (-2^63 to2^64 – 1) i.e. ( -9,223,372,036,854,775,808 to 9,223,372,036,854,775,808).
int
short
long
byte
It is a data type that holds data with more precision, i.e., floating-point numbers. It is a single-precision 32-bit (4 bytes) IEEE754 floating-point.
int
float
double
char
It is a double-precision 64-bit (8 bytes) IEEE754 floating point.
float
double
long
int
It is a sequence of characters.
char
string
boolean
int
An element of a program that defines the type of data that a variable will hold
variable
expression
operator
data type
What will be the output?
A
B
C
WHAT WILL BE THE OUTPUT?
A
B
C
D
WHAT WILL BE THE OUTPUT?
A
B
C
D
A
B
C
D
WHAT WILL BE THE OUTPUT?
A
B
C
D
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
Java is a
Procedure Oriented Language
Structure Oriented Language
Object_Oriented Language
Machine Language
The name of the following should be the file name in Java
Object Name
Variable Nam
Class Name
Array Name
Java program is
Interpreted
Compiled
A ___________ file is created after successful compilation of a Java program.
Object file
Array file
Class file
String file
Command to compile Java program
javax
javay
javac
Java
Command to run a Java program
javaa
java
jaava
jaavaa
JDK stands for
Java Developer Kit
Java Development Kit
Java Design Kit
Java Debugging Kit
JRE stands for
Java Run Environment
Java Run Execution
Java Runtime Environment
Java Ready Execution
Java is
Machine dependent language
Machine independent language
Java was originally named:
Coffee
Oak
New C++
Duke
In Java WORA stands for
Write Once Recall Anywhere
Write Once Return Anywhere
Write Once Read Anywhere
Write Once Run Anywhere
JVM stands for
Java Vital Machine
Java Virtual Machine
Java Vendor machine
Java programs ________________
are only compiled
are only compiled not interpreted
are only interpreted
are both compiled and interpreted
Main() method is not mandatory for a Java program
True
False
Java Programming was designed by ______
Sun MicroSystems
Mozilla Corporation
Microsoft
Amazon Inc.
Earlier name of Java Programming language was –
Eclipse
D
Oak
Netbean
Which of the following personality is called as father of Java Programming language –
Guido vom Russom
Larry Page
Bjarne Stroustrup
James Gosling
Which of the following is not OOPS concept in Java?
Inheritance
Encapsulation
Polymorphism
Compilation
Which concept of Java is a way of converting real world objects in terms of class?
Polymorphism
Encapsulation
Abstraction
Inheritance
Which concept of Java is achieved by combining methods and attribute into a class?
Encapsulation
Inheritance
Polymorphism
Abstraction
Java was developed in which year
1992
1993
1994
1995
Which component is used to compile, debug and execute java program?
JDK
JRE
JVM
JIT
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
In Java EE, EE stands for ___.
Entertainment Edition
Entrepreneur Edition
Enterprise Emperor
Enterprise Edition
