NEW
Font size
WorksheetsJava Programming Quiz
Total questions: 17
Worksheet time: 9mins
What is the role of the JVM in the Java program execution process?
It compiles Java source code directly into machine code.
It interprets and executes Java bytecode on any platform.
It only optimizes the code for better performance but doesn’t execute it.
It is responsible for managing the file system on the host machine.
Which of the following statements about Java variables is TRUE?
Java variable names can start with a digit.
Java variable names are not case-sensitive.
Java variable names can start with an underscore or a letter.
Java variable names can include spaces.
Given the expression: int result = 5 + 2.5 * 4; What is the value of result?
15
13
21
25
What is the main difference between a while loop and a do-while loop?
A while loop always runs at least once, while a do-while loop may never run.
A while loop does not require a condition, while a do-while loop does.
A do-while loop always runs at least once, while a while loop may never run.
They are identical in their runtime behavior.
Which method is used to read integer input from the console in Java using a Scanner object?
scanner.nextLine()
scanner.nextFloat()
scanner.next()
scanner.nextInt()
Which statement about methods in Java is FALSE?
A method can return a value or be declared void if it returns nothing.
A method can be overloaded by changing its parameter list.
All method parameters in Java are passed by reference.
The public static void main(String[] args) method is the entry point to a Java application.
Which of the following best describes the proper way to declare an array of integers in Java?
int array = new int[10];
int[] array = new int(10);
int array[] = new int[10];
array int = [10] new;
What does the final keyword do in Java variable declarations?
It prevents the variable from being used inside a loop.
It allows the variable to be changed only within a certain scope.
It makes the variable constant and prevents reassignment.
It makes the variable only accessible within the current class.
Which of the following best describes method overloading in Java?
Having methods in multiple classes with the same name.
Having a method with the same name but different return types only.
Having multiple methods with the same name but different parameter lists.
Having methods with different names but identical parameter lists.
Which statement is TRUE about selection sort compared to bubble sort?
Selection sort always has better time complexity than bubble sort.
Selection sort swaps elements in each pass only once.
Selection sort depends on the array being sorted beforehand.
Selection sort is a built-in Java method.
Which of the following correctly demonstrates formatted output using System.out.printf()?
System.out.println(“Result: %d”, 10);
System.out.printf(“Result: %d”, 10);
System.out.print(“Result: “ + %d, 10);
System.out.printf(“Result “ + 10, “%d”);
Which statement about local variable scope is correct?
Local variables can be accessed by all methods in the same class.
Local variables exist only within the code block where they are declared.
Local variables are automatically assigned default values.
Local variables have the same scope as class fields.
Which statement about the bubble sort algorithm is accurate?
It is much quicker than selection sort
It compares adjacent elements and swaps them if they are out of order.
It requires a sorted list to start with.
It typically outperforms selection sort in the worst case.
Which statement about explicit type casting is TRUE?
It is only necessary when assigning from a smaller to a larger data type.
It can never lead to data loss.
It is required when assigning from a larger type to a smaller type.
It is forbidden for primitive data types.
What is the value of the following expression in Java? boolean result = true || false && false;
true
false
This expression will not compile
None of the above
What is the result of the expression int result = 7 / 2; in Java?
3.5
4
3
2
Which statement about Strings in Java is correct?
Strings in Java can be changed in place.
Strings in Java are mutable by default.
Strings in Java are immutable, and any modification creates a new String.
String immutability is determined at compile time, not runtime.
