Font size
WorksheetsJava
Total questions: 51
Worksheet time: 30mins
Is a high-level, class-based, object-oriented programming language. It is a general-purpose programming language intended to let programmers write once, run anywhere (WORA).
Java
JavaScript
C++
C#
What was the original name of the programming language now known as Java?
Green
Oak
Silk
Sun
Used for developing general-purpose applications for desktops, servers, and small-scale applications.
Java SE
Java EE
Java ME
Java FX
Used for developing applications for embedded systems, mobile devices, and IoT devices.
Java SE
Java EE
Java ME
Java FX
Who is commonly referred to as the "father of Java"?
James Gosling
Mike Sheridan
Patrick Naughton
Bill Gates
A software development environment used for developing Java applications
Java Development Kit (JDK)
Java Runtime Environment (JRE)
Java Virtual Machine (JVM)
Java Execution Kit (JEK)
Is an installation package that provides an environment to only run(not develop) the java program(or application)onto your machine.
Java Development Kit (JDK)
Java Runtime Environment (JRE)
Java Virtual Machine (JVM)
Java Execution Kit (JEK)
Is responsible for executing the java program line by line, hence it is also known as an interpreter.
Java Development Kit (JDK)
Java Runtime Environment (JRE)
Java Virtual Machine (JVM)
Java Execution Kit (JEK)
What is a variable in Java?
A method used for performing calculations
A special type of loop in Java
A fixed value that cannot be changed
It is used to store the data temporarily in the computer's memory.
Which naming convention is typically used for class names in Java?
camelCase
PascalCase
snake_case
kebab-case
Which naming convention is commonly used for variable and method names in Java?
camelCase
PascalCase
snake_case
kebab-case
Which of the following naming conventions is typically used for constants (final variables) in Java?
camelCase
PascalCase
UPPER_CASE_SNAKE_CASE
kebab-case
What is the correct naming convention for a Java class name?
employeeDetails
employee_details
EmployeeDetails
employee-details
Which of the following correctly describes the two main categories of data types in Java?
Primitive Types and Object Types
Simple Types and Advanced Types
Primitive Types and Reference Types
Integer Types and Floating Types
Which type of data type is used to store simple values like numbers and characters in Java?
Primitive Types
Reference Types
Object Types
none
Which type of data type is used to store complex values like objects, arrays, and strings in Java?
Primitive Types
Reference Types
Object Types
Array Types
What is the default value of an int in Java?
0
null
undefined
1
Which of the following is NOT a primitive data type in Java?
int
boolean
String
char
What is the default value of a boolean in Java?
0
false
undefined
1
What is type casting in Java?
A method to store multiple values in a single variable
A process of converting the value of one data type to another data type
A way to define custom data types
A process of securing data in Java
Which of the following is an example of Widening Type Casting in Java?
int → short
short → byte
float → double
long → int
Which of the following is an example of Widening Type Casting in Java?
int → short
short → byte
double → float
none
Which of the following is an example of Narrowing Type Casting in Java?
long → int
byte → long
byte → short
none
Which of the following logical operators in Java returns true only if both operands are true?
||
&&
!
^
Which of the following relational operators checks if two values are NOT equal?
==
>=
!=
<
What is the purpose of the switch statement in Java?
It allows us to execute a block of code among many alternatives based on the value of an expression.
It allows us to execute a block of code based on whether a condition is true or false.
It repeats a block of code a certain number of times.
It lets us choose between multiple values without using if statements.
Which of the following is true about the condition in an if statement?
The condition in an if statement must always evaluate to an integer.
The condition in an if statement must evaluate to true or false (a boolean value).
The condition in an if statement must always evaluate to a non-zero value.
The condition in an if statement can be a string.
It handles 2 conditional expressions, it either does the first code block or the second code block.
If-Else Statement
If Statement
If-Else-If Statement
none
Statement hands 3 or more conditional expressions, the possibility of these statements are limitless.
If-Else Statement
If Statement
If-Else-If Statement
none
Repeats a block of code while a condition is true (condition is checked before execution).
While Loop
Do While Loop
For Loop
For each Loop
Used for a known number of iterations with initialization, condition, and increment/decrement.
While Loop
Do While Loop
For Loop
For each Loop
Repeats a block of code at least once and continues as long as the condition is true (condition is checked after execution).
While Loop
Do While Loop
For Loop
For each Loop
It is similar to a conditional statement but only checks for equality and only works with strings, char, int, and enums.
Switch Statements
Variable
Conditional Statements
For each Loop
What is the key difference between a while loop and a do-while loop in Java?
A while loop always executes at least once, while a do-while loop may not execute if the condition is false.
A while loop evaluates the condition before each iteration, while a do-while loop evaluates the condition after each iteration.
A while loop executes only when the condition is false, while a do-while loop executes only when the condition is true.
There is no difference; both loops work the same way.
Which data structure in Java is used to store similar elements and allows only a fixed set of elements?
Stack
Queue
Array
Loop
Which of the following is NOT a valid rule for declaring an array in Java?
An array must have a fixed size once declared.
An array can store multiple data types in a single declaration.
An array can be declared using int[] arr; or int arr[];
An array index starts from 0.
Which of the following is the correct way to declare an array in Java?
int[] numbers = {1, 2, 3, 4, 5};
int numbers(5) = {1, 2, 3, 4, 5};
int numbers = {1, 2, 3, 4, 5};
array numbers[] = {1, 2, 3, 4, 5};
What is the length of this array? String[] fruits = {"Apple", "Banana", "Orange", "Mango", "Grape"};
4
5
6
8
What is the index of "Grape" in the array?
4
3
2
0
If System.out.println(fruits[3]); is printed, what will be the output?
“Apple”
“Banana”
“Orange”
“Mango”
What is the correct way to get the length of this array?
fruits.length()
length(fruits)
fruits.length
Fruits.length()
If System.out.println(fruits[9]); is printed, what will be the output?
“Apple”
“Banana”
“Orange”
Index 5 out of bounds
Which of the following best describes memory allocation in Java?
Java manually manages memory allocation for variables and objects.
The Java Virtual Machine (JVM) automatically allocates memory for variables, objects, and methods.
Memory in Java is only allocated at compile time.
Java does not have a memory management system.
What does the isEmpty() method check?
None
(missing in source)
If the string has whitespace
If the string has a length of 0
What does the replaceAll() do?
Replaces all occurrences of a pattern in a string
Replaces only the first occurrence of a substring
Removes a specific word from a string
Converts a string into an array
This String method returns a unique integer (hash code) for an object, based on its contents.
hashCode()
replaceAll()
trim()
isEmpty()
This String method checks if a string contains a specific sequence of characters and returns true or false.
hashCode()
replaceAll()
contains()
isEmpty()
This String method removes leading and trailing spaces from a string and returns a new string.
hashCode()
replaceAll()
trim()
isEmpty()
This String method converts all characters in a string to uppercase and returns a new string.
toUpperCase()
replaceAll()
trim()
isEmpty()
It is a block of code that performs a specific task and can be called (invoked) from other parts of your program.
Method
String
Loop
Operators
Laboratory Exam (Coding) (100 points)
Instruction: Create a Java class named LastnameFirstnameInstitutionalExam.
In the main method:
Prompt the user for the student's name.
Prompt the user for scores (0–100) in three subjects: Math, English, and Science.
Calculate the average score by adding the three scores and dividing by 3.0.
Determine the final letter grade based on the average score using if-else conditions:
90–100 → A
80–89 → B
70–79 → C
60–69 → D
Below 60 → F
Display the student's name, the average score, and the final letter grade.
Sample Output:
Enter student name: John Doe
Enter Math score (0-100): 87
Enter English score (0-100): 92
Enter Science score (0-100): 85
--- Grading Report ---
Student: John Doe
Average score: 88.00
Final grade: B
Paste your code here:
