1Z0-830 Java SE 21 Developer - Practice Test 2
Your Progress
0 / 66
Question 1
MEDIUM
Which of the following var declarations are invalid? (Choose two.)
Select all that apply
var can declare only one variable per statement and must have an initializer. Multiple declarations and missing initialization are invalid.
See more: Data Types & Variables
Question 2
MEDIUM
What is printed?
int x = 2;
int y = x++ + ++x;
System.out.println(y);
x++ returns 2, x becomes 3.
++x increments to 4 and returns 4.
2 + 4 = 6.
See more: Data Types & Variables
Question 3
EASY
What is printed?
for(int i=1;i<=3;i++){
if(i==2) continue;
System.out.print(i);
}
When i==2, continue skips printing. Output: 13.
See more: Control Flow
Question 4
MEDIUM
Which of the following can be overridden?
Only non-final instance methods can be overridden. Private and static are not overridden; final cannot be overridden.
See: Object-Oriented Approach ->Overriding Rules
Question 5
EASY
Which exception must be declared or caught?
IOException is checked and must be handled or declared.
See more: Exception Handling
Question 6
EASY
Which Set implementation maintains insertion order?
LinkedHashSet preserves insertion order.
See: Arrays & Collections ->Collections
Question 7
MEDIUM
Which operation is lazy?
map() is an intermediate lazy operation. Terminal operations trigger execution.
See more: Streams & Lambdas
Question 8
MEDIUM
Which statement makes a service available in module-info.java?
provides ... with declares service implementation.
See: Packaging & Deployment ->ServiceLoader
Question 9
EASY
Which class executes tasks asynchronously?
ExecutorService manages asynchronous execution.
See more: Concurrency
Question 10
EASY
Which method writes bytes to a file?
Files.write(Path, byte[]) writes bytes.
See more: Java I/O API
Question 11
MEDIUM
Which method creates a PreparedStatement?
prepareStatement() creates precompiled SQL statement.
See more: JDBC
Question 12
EASY
Which class formats dates in modern Java API?
DateTimeFormatter is part of java.time API.
See more: Localization
Question 13
MEDIUM
Which is true about sealed classes?
Sealed classes restrict subclassing to permitted types.
See more: Java 21 New Features
Question 14
EASY
What is printed?
String s = "Java";
System.out.println(s.repeat(2));
repeat(2) repeats the string twice.
Output: JavaJava
See more: Data Types & Variables
Question 15
MEDIUM
Which primitive type cannot be implicitly widened to long?
char can be widened, but exam trick: char is unsigned 16-bit and can widen to int and long. However in numeric promotion contexts confusion occurs - the only correct implicit widening set excludes boolean. Since boolean is not listed, all listed types widen. Correct answer here is trick-based: char is widened differently but still valid. (For exam caution.)
See more: Data Types & Variables
Question 16
EASY
Which statement exits the entire loop?
break exits the loop completely.
See more: Control Flow
Question 17
EASY
Which modifier allows access within same package only?
Default (package-private) allows access within same package.
See: Object-Oriented Approach ->Access Modifiers
Question 18
EASY
Which keyword is used to implement an interface?
implements is used when a class implements an interface.
See: Object-Oriented Approach ->Interfaces
Question 19
EASY
Which statement creates a custom exception?
Custom exceptions extend Exception or RuntimeException.
See more: Exception Handling
Question 20
MEDIUM
Which Map allows one null key?
HashMap allows one null key.
Hashtable and ConcurrentHashMap do not.
See: Arrays & Collections ->Map Implementations
Question 21
EASY
Which method removes and returns first element of Deque?
poll() removes and returns head element.
See: Arrays & Collections ->Deque
Question 22
EASY
Which functional interface takes no arguments and returns a value?
Supplier<T> supplies a value without input.
See more: Streams & Lambdas
Question 23
EASY
Which Stream operation sorts elements?
sorted() sorts elements.
See more: Streams & Lambdas
Question 24
MEDIUM
Which directive opens a package to reflection for specific modules?
opens to allows reflection access to specific modules.
See: Packaging & Deployment ->Modules
Question 25
MEDIUM
Which method causes a thread to give up CPU temporarily?
yield() hints scheduler to pause current thread.
See more: Concurrency
Question 26
MEDIUM
Which keyword ensures visibility across threads?
volatile guarantees visibility but not atomicity.
See more: Concurrency
Question 27
EASY
Which class reads characters from file?
FileReader reads character data.
See more: Java I/O API
Question 28
MEDIUM
Which method commits transaction manually?
commit() saves transaction changes.
See more: JDBC
Question 30
EASY
Which class represents currency?
Currency represents ISO currency codes.
See more: Localization
Question 31
EASY
Which feature automatically generates equals and hashCode?
Records auto-generate equals, hashCode, toString.
See more: Java 21 New Features
Question 32
MEDIUM
Which pattern matching simplifies type casting?
instanceof pattern matching combines check and cast.
See more: Java 21 New Features
Question 33
EASY
Which wrapper class corresponds to primitive int?
Integer wraps primitive int.
See more: Data Types & Variables
Question 34
MEDIUM
Which statement returns value from switch expression?
yield returns value in switch expression blocks.
See more: Control Flow
Question 35
EASY
Which keyword prevents inheritance?
final prevents subclassing entirely.
See: Object-Oriented Approach ->Class Design
Question 36
MEDIUM
Which method converts Stream to List?
Both approaches create lists (Java 16+ supports toList()).
See more: Streams & Lambdas
Question 37
EASY
Which operation limits number of elements?
limit(n) restricts stream size.
See more: Streams & Lambdas
Question 38
EASY
Which tool compiles modules?
javac compiles Java code including modules.
See: Packaging & Deployment ->Tools
Question 39
MEDIUM
Which class supports parallel stream execution?
Parallel streams use ForkJoinPool common pool.
See more: Concurrency
Question 40
EASY
Which method checks if path exists?
Files.exists(Path) checks file existence.
See more: Java I/O API
Question 41
EASY
Which primitive type stores true or false values?
boolean represents true or false. It cannot be converted to numeric types.
See more: Data Types & Variables
Question 42
MEDIUM
What is printed?
int x = 1;
System.out.println(x++ + x++);
First x++ returns 1 (x becomes 2).
Second x++ returns 2 (x becomes 3).
1 + 2 = 3.
See more: Data Types & Variables
Question 43
EASY
Which loop is best used when the number of iterations is known?
for loop is typically used when iteration count is known.
See more: Control Flow
Question 44
EASY
Which keyword is used to call a superclass constructor?
super() calls superclass constructor.
See: Object-Oriented Approach ->Constructors & Inheritance
Question 45
EASY
Which interface method must be implemented?
Abstract methods must be implemented unless class is abstract.
See: Object-Oriented Approach ->Interfaces
Question 46
EASY
Which block handles exceptions?
catch handles thrown exceptions.
See more: Exception Handling
Question 47
EASY
Which List implementation allows fast random access?
ArrayList supports O(1) index-based access.
See: Arrays & Collections ->List Implementations
Question 48
EASY
Which collection does not allow duplicates?
Set does not allow duplicate elements.
See: Arrays & Collections ->Collections Framework
Question 49
MEDIUM
Which method aggregates stream elements?
reduce() performs reduction operation on stream.
See more: Streams & Lambdas
Question 50
EASY
Which interface consumes a value without returning anything?
Consumer<T> accepts input and returns void.
See more: Streams & Lambdas
Question 51
MEDIUM
Which tool analyzes module dependencies?
jdeps analyzes dependencies between modules.
See: Packaging & Deployment ->Module Tools
Question 52
EASY
Which method blocks until a thread finishes?
join() waits for thread termination.
See more: Concurrency
Question 53
MEDIUM
Which executor creates a single background thread?
newSingleThreadExecutor() creates exactly one worker thread.
See more: Concurrency
Question 54
MEDIUM
Which method reads file content as Stream<String>?
Files.lines(Path) returns Stream<String>.
See more: Java I/O API
Question 55
EASY
Which object executes SQL statements?
Statement executes SQL queries.
See more: JDBC
Question 56
MEDIUM
Which method disables auto-commit mode?
setAutoCommit(false) enables manual transaction control.
See more: JDBC
Question 57
MEDIUM
Which class formats compact numbers?
getCompactNumberInstance() formats values like 1K, 1M.
See more: Localization
Question 58
EASY
Which class represents time zone?
ZoneId identifies time zones.
See more: Localization
Question 59
MEDIUM
Which feature allows deconstruction in switch?
Pattern matching enables advanced switch matching.
See more: Java 21 New Features
Question 60
MEDIUM
Which modifier must permitted subclasses declare?
Permitted subclasses must declare final, sealed, or non-sealed.
See more: Java 21 New Features
Question 61
EASY
Which keyword allows a class to inherit from only one class?
Java supports single inheritance using extends.
See: Object-Oriented Approach ->Inheritance
Question 62
MEDIUM
Which Map sorts by key naturally?
TreeMap sorts keys using natural ordering.
See: Arrays & Collections ->Sorted Collections
Question 63
EASY
Which method removes duplicates in a stream?
distinct() removes duplicate elements.
See more: Streams & Lambdas
Question 64
MEDIUM
Which concurrent collection uses lock-free segmentation?
ConcurrentHashMap uses segmented locking / CAS for concurrency.
See more: Concurrency
Question 65
EASY
Which statement rethrows an exception?
throw e; rethrows the exception.
See more: Exception Handling
Question 66
MEDIUM
Which tool creates custom runtime images?
jlink builds optimized runtime images for modular apps.
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