WorksheetsJava Quiz_1
Total questions: 48
Worksheet time: 48mins
What is the process of converting a variable of one data type into another in Java?
Type casting
Data transformation
Behavioral Modeling
Type conversion
Which type of casting occurs automatically when assigning a value of a smaller data type to a variable of a larger data type?
Explicit casting
Implicit casting
Type conversion
Data transformation
When is explicit casting required in Java?
When declaring a variable
When performing arithmetic operations
When converting a variable of a larger data type to a smaller data type
When converting a variable of a smaller data type to a larger data type
What method is used to find the length of a string in Java?
lengthOf()
size()
length()
count()
Which method is used to concatenate two strings in Java?
concat()
combine()
merge()
join()
What is the escape sequence character used to insert a double quote in a string?
\s
\"
\d
\q
In Java, how can you take input from the user?
Using the Input class
Using the Scanner class
Using the Console class
Using the UserInput class
Which conditional statement in Java allows you to provide an alternative block of code to be executed if the if condition is false?
else if
switch
for
while
What keyword is used to exit the switch statement once a matching case is found?
exit
stop
break
end
What is the default case used for in a switch statement?
To specify the code that should be executed if none of the case values match the value of the expression being evaluated
To specify the first case that should be executed
To specify the last case that should be executed
To specify the case with the highest value
Which method is used to compare two strings in Java?
compare()
equals()
match()
verify()
What is the value stored in x?
double x = (int) (1.8 * 2.0)
3.0
3
3.6
Error
What is the value stored in x?
int x = 1.8 * 2.0
3
2
3.6
Error
What is the value of:
(int) (1 + 1 + 1 + 1 + 1.0 + 1 + 1 / 8)
1
0
0.875
Which of these is valid?
line 1 int x = 2/2;
line 2 double y = 2;
line 1
line 2
neither of these
both of these
double x = 2.0;
int y = 3;
int z = 4;
x=( (double) y + z) /2
translates to:
(3.0 + 4) /2 = 3.0
(3.0 + 4) /2 = 3.5
(3.0 + 4.0)/2 = 3.5
7.0/2 =3.5
Which of the following are relational operators. Select all that apply.
<=
>
!
#
=
Java was originally named:
Coffee
Oak
New C++
Duke
Which of the following is NOT a numeric data type
int
double
float
decimal
Where does a java program start executing instructions from:
class
source file
main method
object
The name of the following should be the file name in Java
Object Name
Variable Nam
Class Name
Array Name
Java program does not run without below function
user()
system()
main()
void()
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
How would you declare a variable that tells you that someone passed a class?
boolean passed = 'true';
boolean passed = true;
passed = true;
String passed = "true";
Which declaration will throw an error?
double num = 8;
int averageGrade = 89.7;
boolean done = false;
String done = "true";
Java is a
Procedure Oriented Language
Structure Oriented Language
Object_Oriented Language
Machine Language
What is the output of the following code?
int x = 5;
while (x > 0) {
System.out.print(x);
x--;
}
54321
5432
54321
5432
What is the value of x after the following code is executed?
int x = 2;
for (int i = 0; i < 3; i++) {
x += 2;
}
6
8
10
12
What is the purpose of 'continue' statement in Java?
To skip the remaining code in the loop and move to the next iteration
To terminate the loop and move to the next statement after the loop
To restart the loop from the beginning
To check a condition and decide whether to continue the loop or not
In Java, what is the use of 'do-while' loop?
To execute a block of code as long as the specified condition is true
To execute a block of code at least once and then repeatedly execute it as long as the specified condition is true
To execute a block of code a specific number of times
To execute a block of code based on multiple conditions
What is the purpose of 'for-each' loop in Java?
To iterate through a collection of elements such as arrays or lists
To execute a block of code as long as the specified condition is true
To execute a block of code a specific number of times
To execute a block of code based on multiple conditions
What is the output of the following code snippet?
int[][] arr = {{1, 2, 3}, {4, 5, 6}};
System.out.println(arr[1][2]);
3
4
5
6
How do you declare a 2D array in Java?
int[] arr = new int[3][3];
int[][] arr = new int[3][3];
int[3][3] arr;
int arr[][] = new int[3][3];
What is the output of the following code?
int[][] arr = {{1, 2, 3}, {4, 5, 6}};
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
System.out.print(arr[i][j] + " ");
}
}
1 2 3 4 5 6
1 4 2 5 3 6
1 2 3
1 4 2 5 3
What is the purpose of a nested loop in Java?
To iterate through a collection of elements such as arrays or lists
To execute a block of code as long as the specified condition is true
To execute a block of code a specific number of times
To execute a block of code based on multiple conditions
What is the value of x after the following code is executed?
int x = 0;
do {
System.out.print(x);
x++;
} while (x < 5);
01234
12345
43210
54321
What is the output of the following code?
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
System.out.print(i + j);
}
}
012345
0123
001122
0012
What is the output of the following code snippet?
int[][] arr = {{1, 2, 3}, {4, 5, 6}};
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
System.out.print(arr[i][j] + " ");
}
}
1 2 3 4 5 6
1 4 2 5 3 6
1 2 3
1 4 2 5 3
What is the purpose of 'continue' statement in Java?
To skip the remaining code in the loop and move to the next iteration
To terminate the loop and move to the next statement after the loop
To restart the loop from the beginning
To check a condition and decide whether to continue the loop or not
What is the output of the following code?
int[][] arr = {{1, 2, 3}, {4, 5, 6}};
System.out.println(arr[1][2]);
3
4
5
6
