1Z0-830 Java SE 21 Developer - Practice Test 5
Your Progress
0 / 66
Question 1
MEDIUM
Which of the following local variable declarations using var are invalid? (Choose two.)
Select all that apply
var requires an initializer because the compiler must infer the type at compile time.
var a = 10; -> Valid (int inferred)
var b; -> Invalid (no initializer)
var c = null; -> Invalid (null has no type information)
var d = new String("Java"); -> Valid (String inferred)
Exam Tip: var cannot be used without initialization and cannot infer from null.
See more: Data Types & Variables
Question 2
MEDIUM
What is printed?
int x = 5;
int y = ++x + x++;
System.out.println(y);
Evaluation is left-to-right.
++x -> x becomes 6, returns 6
x++ -> returns 6, then x becomes 7
6 + 6 = 12
Final x = 7.
See more: Data Types & Variables
Question 3
MEDIUM
What is printed?
int i = 0;
do {
System.out.print(i);
} while(++i < 3);
Iteration steps:
Print 0 -> i becomes 1
Print 1 -> i becomes 2
Print 2 -> i becomes 3 -> condition fails
Output: 012
See more: Control Flow
Question 4
MEDIUM
Which statement about method overriding is correct?
Overriding allows covariant return types (subclass return allowed).
Access cannot be more restrictive.
Static methods are hidden, not overridden.
See: Object-Oriented Approach -> Object-Oriented Approach (Overriding Rules)
Question 5
EASY
What is printed?
try {
throw new RuntimeException();
} catch(Exception e) {
System.out.print("A");
} finally {
System.out.print("B");
}
Exception is caught -> prints A.
finally always executes -> prints B.
Output: AB
See more: Exception Handling
Question 6
EASY
Which collection maintains natural sorted order?
TreeSet keeps elements sorted using natural ordering or Comparator.
See: Arrays & Collections -> Arrays & Collections (Sorted Collections)
Question 7
MEDIUM
What is printed?
Stream.of(1,2,3)
.filter(i -> i > 1)
.map(i -> i * 2)
.forEach(System.out::print);
Filter keeps 2 and 3.
Map multiplies -> 4 and 6.
Output: 46
See more: Streams & Lambdas
Question 8
EASY
Which directive exports a package in module-info.java?
exports makes a package accessible to other modules.
See: Packaging & Deployment -> Packaging & Deployment (Modules)
Question 9
EASY
Which keyword prevents a method from being accessed by multiple threads simultaneously?
synchronized enforces mutual exclusion on a monitor lock.
See more: Concurrency
Question 10
EASY
Which class is used to serialize objects?
ObjectOutputStream writes Serializable objects.
See more: Java I/O API
Question 11
EASY
Which JDBC interface represents a database connection?
Connection represents a session with the database.
See more: JDBC
Question 12
EASY
Which class is used for locale-specific formatting of numbers?
NumberFormat handles locale-aware number formatting.
See more: Localization
Question 13
EASY
Which feature allows pattern matching in switch statements?
Java 21 supports pattern matching for switch.
See more: Java 21 New Features
Question 14
EASY
What is printed?
String s = " Java ";
System.out.print("[" + s.strip() + "]");
strip() removes leading and trailing Unicode whitespace.
Original: " Java "
After strip(): "Java"
Output: [Java]
Exam Tip: strip() is Unicode-aware; trim() is not.
See more: Data Types & Variables
Question 15
EASY
What is printed?
int a = 10;
int b = 20;
System.out.println(a > b ? "A" : "B");
Ternary operator evaluates condition a > b.
10 > 20 is false -> returns "B".
See more: Data Types & Variables
Question 16
MEDIUM
Which statement about switch expressions is correct?
Switch expressions can return values. When using a block, yield returns the value.
break is not used in expression form.
See more: Control Flow
Question 17
EASY
Which keyword prevents a class from being extended?
final prevents subclassing completely.
sealed restricts but does not fully prevent extension.
See: Object-Oriented Approach -> Class Design
Question 18
MEDIUM
Which of the following compile? (Choose two.)
Select all that apply
Generics are invariant.
? extends allows subclasses (Integer extends Number).
? super allows supertypes.
Direct List<Number> = new ArrayList<Integer>() does NOT compile.
See: Object-Oriented Approach -> Generics & Wildcards
Question 19
EASY
Which exception is unchecked?
Unchecked exceptions extend RuntimeException.
NullPointerException is unchecked.
See more: Exception Handling
Question 20
EASY
Which method retrieves but does not remove the head of a Queue?
peek() retrieves without removing.
poll() removes.
See: Arrays & Collections -> Queue Interface
Question 21
EASY
Which intermediate operation returns a Stream?
map() is intermediate and returns a Stream.
forEach(), count(), reduce() are terminal operations.
See more: Streams & Lambdas
Question 22
EASY
What is printed?
Optional<String> o = Optional.of("Java");
System.out.println(o.orElse("Default"));
orElse returns contained value if present.
See more: Streams & Lambdas
Question 23
EASY
Which directive declares a dependency on another module?
requires declares dependency.
See: Packaging & Deployment -> Module Dependencies
Question 24
EASY
Which interface represents a task returning a value?
Callable returns a value and can throw checked exceptions.
See more: Concurrency
Question 25
MEDIUM
Which class allows thread-safe iteration without ConcurrentModificationException?
CopyOnWriteArrayList uses snapshot iteration.
See more: Concurrency
Question 26
EASY
Which class is part of NIO?
Path is part of java.nio.file package.
See more: Java I/O API
Question 27
EASY
Which method executes a SELECT statement?
executeQuery() returns a ResultSet.
See more: JDBC
Question 28
EASY
Which object holds the results of a query?
ResultSet stores query results row-by-row.
See more: JDBC
Question 29
EASY
Which class represents a specific geographical region for formatting?
Locale defines language and region.
See more: Localization
Question 30
MEDIUM
Which is true about records?
Records implicitly extend java.lang.Record.
They cannot extend other classes.
Components are final.
See more: Java 21 New Features
Question 31
MEDIUM
What is printed?
int a = 4;
int b = a++ * 2;
System.out.println(b + " " + a);
a++ uses 4, then increments to 5.
4 * 2 = 8.
Final a = 5.
Output: 8 5
See more: Data Types & Variables
Question 32
EASY
Which keyword skips the current loop iteration?
continue skips remaining code in the current iteration and moves to the next.
See more: Control Flow
Question 33
EASY
Which of the following about constructors is correct?
Constructors do NOT have return types (not even void).
They cannot be abstract.
They may have any access modifier.
See: Object-Oriented Approach -> Constructors
Question 34
EASY
Which block always executes?
finally executes regardless of exception handling (except JVM termination).
See more: Exception Handling
Question 35
MEDIUM
Which List implementation is synchronized?
Vector is legacy synchronized.
CopyOnWriteArrayList is concurrent but not fully synchronized.
See: Arrays & Collections -> Collections
Question 36
EASY
Which terminal operation returns an Optional?
findFirst() returns Optional<T>.
See more: Streams & Lambdas
Question 37
MEDIUM
Which keyword allows reflective access in modules?
opens allows reflection at runtime.
See: Packaging & Deployment -> Modules
Question 38
EASY
Which method waits for a thread to finish?
join() waits for thread completion.
See more: Concurrency
Question 39
EASY
Which method reads all lines from a file?
Files.readAllLines(Path) returns List<String>.
See more: Java I/O API
Question 40
EASY
Which JDBC method modifies database data?
executeUpdate() is used for INSERT, UPDATE, DELETE.
See more: JDBC
Question 41
EASY
Which class loads JDBC drivers?
DriverManager manages JDBC drivers and connections.
See more: JDBC
Question 42
MEDIUM
Which method formats currency based on locale?
getCurrencyInstance() formats according to locale.
See more: Localization
Question 43
MEDIUM
Which keyword restricts subclasses to specific types?
sealed restricts permitted subclasses.
See more: Java 21 New Features
Question 44
MEDIUM
Which modifier must permitted subclasses declare?
Subclasses must declare final, sealed, or non-sealed.
See more: Java 21 New Features
Question 45
MEDIUM
Which collector groups elements?
groupingBy groups stream elements by classifier.
See more: Streams & Lambdas
Question 46
EASY
Which functional interface takes two arguments and returns a result?
BiFunction<T,U,R> accepts two inputs and produces result.
See more: Streams & Lambdas
Question 47
EASY
Which access modifier is most restrictive?
private restricts access to the same class only.
See: Object-Oriented Approach -> Access Modifiers
Question 48
EASY
Which keyword allows inheritance?
extends is used for class inheritance.
See: Object-Oriented Approach -> Inheritance
Question 49
EASY
Which loop guarantees at least one execution?
do-while executes body before condition check.
See more: Control Flow
Question 50
MEDIUM
Which is a valid text block declaration?
Text blocks require line break after opening delimiter.
See more: Data Types & Variables
Question 51
MEDIUM
Which method sorts a List?
Both Collections.sort() and List.sort() can sort lists.
See: Arrays & Collections -> Collections Utility
Question 52
EASY
Which method pauses a thread?
Thread.sleep pauses execution for specified time.
See more: Concurrency
Question 53
EASY
Which is a terminal operation?
collect() triggers stream processing.
See more: Streams & Lambdas
Question 54
MEDIUM
Which class handles date formatting by locale?
DateFormat formats dates using locale settings.
See more: Localization
Question 55
EASY
Which interface represents file path abstraction?
Path represents file/directory path in NIO.
See more: Java I/O API
Question 56
EASY
Which keyword refers to superclass?
super references superclass members.
See: Object-Oriented Approach -> Inheritance
Question 57
EASY
Which feature reduces boilerplate for data carriers?
Records auto-generate constructor, getters, equals, hashCode.
See more: Java 21 New Features
Question 58
MEDIUM
Pattern matching for instanceof allows?
instanceof pattern matching combines type check and cast.
See more: Java 21 New Features
Question 59
EASY
Which concurrent map implementation exists?
ConcurrentHashMap is thread-safe without full synchronization.
See more: Concurrency
Question 60
MEDIUM
Which interface allows LIFO operations?
Deque supports stack (LIFO) and queue (FIFO) operations.
See: Arrays & Collections -> Deque
Question 61
EASY
Which statement throws an exception explicitly?
throw is used to explicitly throw an exception.
See more: Exception Handling
Question 62
EASY
Which keyword exits a method?
return exits a method and optionally returns value.
See more: Control Flow
Question 63
EASY
Which primitive type is 64-bit floating point?
double is 64-bit IEEE 754 floating point.
See more: Data Types & Variables
Question 64
EASY
Which keyword is used to define an interface?
interface defines a contract in Java.
See: Object-Oriented Approach -> Interfaces
Question 65
EASY
Which functional interface returns boolean?
Predicate<T> returns boolean.
See more: Streams & Lambdas
Question 66
MEDIUM
Which tool packages modules into runtime images?
jlink creates custom runtime images for modular applications.
See: Packaging & Deployment -> Deployment Tools
Popular Posts
1Z0-830 Java SE 21 Developer Certification
Azure AI Foundry Hello World
Azure AI Agent Hello World
Foundry vs Hub Projects
Build Agents with SDK
Bing Web Search Agent
Function Calling Agent
Spring Boot + Azure Key Vault Hello World Example
Spring Boot + Elasticsearch + Azure Key Vault Example
Spring Boot Azure AD (Entra ID) OAuth 2.0 Authentication
Deploy Spring Boot App to Azure App Service
Secure Azure App Service using Azure API Management
Deploy Spring Boot JAR to Azure App Service
Deploy Spring Boot + MySQL to Azure App Service
Spring Boot + Azure Managed Identity Example
Secure Spring Boot Azure Web App with Managed Identity + App Registration
Elasticsearch 8 Security - Integrate Azure AD OIDC