1Z0-819 Sample Questions & Answers
Tests your grasp of the Java Platform Module System, concurrency, JDBC, localization and annotations, plus handling primitives and text values, program flow, the object lifecycle, exceptions, arrays, lambda expressions and streams, and generics with collections.
Launch the full 1Z0-819 simulator →Showing 10 of 20 free samples.
- Question 1Beginner
Localization · Parse and format messages, dates, and numbers
A developer is writing a utility method to format currency values for different regions. The method should take a
doubleand ajava.util.Localeand return a formatted string. The application will be used in the US, Germany, and Japan. Which is the correct way to instantiate and use aNumberFormatobject for this purpose?Show answer & explanation
Correct answer: B
NumberFormatis an abstract class and cannot be instantiated directly withnew. The correct way to obtain a locale-specific formatter, especially for currency, is by using the static factory methodNumberFormat.getCurrencyInstance(locale). This ensures that the correct currency symbol, grouping separators, and decimal separators are used according to the rules of the specifiedLocale. - Question 2Intermediate
Java Object-Oriented Approach · Utilize polymorphism and casting to call methods
Given the following code:
public class Device { private String type = "electronic"; public String getType() { return type; } } public class Phone extends Device { private String type = "mobile"; @Override public String getType() { return type; } } public class Tester { public static void main(String[] args) { Device device = new Phone(); System.out.println(device.type + ":" + device.getType()); } }What is the result?
Show answer & explanation
Correct answer: B
This question tests the difference between method overriding (dynamic dispatch) and field hiding (static dispatch). When
device.getType()is called, polymorphism ensures the overridden method in thePhoneclass is executed, returning "mobile". However, whendevice.typeis accessed, the reference type (Device) determines which field is used, not the object type (Phone). Therefore, thetypefield from theDeviceclass is accessed, which is "electronic". - Question 3Intermediate
Working with Streams and Lambda expressions · Perform decomposition and reduction
A developer needs to process a list of
Orderobjects. The goal is to create aMapwhere keys are theCustomerassociated with the order, and values are aListof allOrderobjects for that customer. Which stream operation correctly achieves this?graph TD A[List ] --> B{Stream Pipeline} B --> C[Map >]Show answer & explanation
Correct answer: C
The
Collectors.groupingBy()collector is specifically designed for this purpose. It takes a classification function (in this case,Order::getCustomer) and groups the elements of the stream into aMap. The keys of the map are the results of applying the classification function, and the values areLists of the stream elements that produced each key. - Question 4IntermediateSelect 2
Annotations · Create, apply, and process annotations
A developer has created a custom annotation
@Versionto track the version of a class. The annotation must be available at runtime via reflection and should be included in the generated Javadoc.// line n1 public @interface Version { String value(); }Which meta-annotations should be placed at
line n1to meet these requirements? (Select TWO)Show answer & explanation
Correct answers: A, D
To make an annotation available at runtime through reflection, its retention policy must be set to
RetentionPolicy.RUNTIME. To ensure the annotation is included in the output of documentation tools like Javadoc, the@Documentedmeta-annotation must be applied. - Question 5Beginner
Controlling Program Flow · Create and use loops
A developer is implementing a custom collection class that must be usable in a
for-eachloop. Which interface must the custom class implement to support this functionality?Show answer & explanation
Correct answer: C
The
for-eachloop (or enhanced for loop) in Java works with any object whose class implements thejava.lang.Iterableinterface. This interface has a single abstract method,iterator(), which must return an instance ofjava.util.Iterator. The loop then uses this iterator to traverse the elements. - Question 6Intermediate
Working with Arrays and Collections · Use List, Set, Map and Deque collections
What is the output of the following code snippet?
var list = new java.util.ArrayList (); list.add("A"); list.add("B"); list.add("C"); for (var s : list) { System.out.print(s); list.remove(s); }Show answer & explanation
Correct answer: B
It is illegal to modify a collection (e.g., by calling
list.remove(s)) while iterating over it using an enhanced for-loop or a standard iterator, except through theIterator's ownremovemethod. The code will print "A", then attempt to remove it. On the next iteration, the iterator'shasNext()ornext()method will detect that the underlying collection has been structurally modified and will throw aConcurrentModificationExceptionto prevent unpredictable behavior. - Question 7Beginner
Database Applications with JDBC · Connect to and perform database SQL operations
A database administrator needs a Java application to connect to an Oracle database. The connection details are: driver
oracle.jdbc.driver.OracleDriver, URLjdbc:oracle:thin:@host:1521:sid, userscott, and passwordtiger. Which code fragment correctly establishes a connection to the database?Show answer & explanation
Correct answer: A
Since JDBC 4.0, it is no longer necessary to explicitly load the driver class using
Class.forName(). TheDriverManagercan discover and load drivers automatically from the classpath. The most direct and modern way to establish a connection is to callDriverManager.getConnection(url, user, password). - Question 8IntermediateSelect 3
Java Object-Oriented Approach · Make objects immutable
A developer is creating an immutable
Userclass. Which of the following principles must be followed to ensure true immutability? (Select THREE)Show answer & explanation
Correct answers: A, B, C
- Question 9Advanced
Concurrency · Develop thread-safe code
Case Study
Company Background:
GlobalTrade Inc. is a logistics company that provides real-time tracking for international shipments. They are developing a new backend service,TrackingService, using Java 11. This service receives location updates from various carriers, validates them, and stores them in a database. Performance and reliability are critical, as the service must handle thousands of updates per second.Current Situation:
The development team has created aLocationUpdateProcessorclass that runs in its own thread. This processor fetches batches of raw location data from a shared queue, processes them, and writes them to the database. During initial load testing, the team observed that under heavy load, the application sometimes throws aNullPointerExceptionwithin therun()method of the processor. The code for the processor is as follows:class LocationUpdateProcessor implements Runnable { private volatile boolean isRunning = true; private final Queue dataQueue; public LocationUpdateProcessor(Queue queue) { this.dataQueue = queue; } public void stopProcessing() { isRunning = false; } @Override public void run() { while (isRunning) { String rawData = dataQueue.poll(); // NPE occurs on the next line if (rawData.contains("URGENT")) { // process urgent data } } } }Requirements:
TheLocationUpdateProcessormust be fixed to prevent theNullPointerException. It should process data as long as theisRunningflag is true and there is data in the queue. The solution must be efficient and avoid busy-waiting (i.e., continuously looping and checking the queue when it's empty).Question:
Which modification to therun()method is the most appropriate and robust solution to fix the bug and meet the requirements?Show answer & explanation
Correct answer: D
The
NullPointerExceptionoccurs becausedataQueue.poll()returnsnullwhen the queue is empty. The original code does not check fornullbefore calling a method onrawData. While adding a null check fixes the NPE, it leads to busy-waiting, violating a requirement. The most robust and idiomatic solution for producer-consumer scenarios is to use ajava.util.concurrent.BlockingQueue. Thetake()method blocks until an element is available, which efficiently waits without consuming CPU cycles. This fixes the NPE and avoids busy-waiting, fully satisfying the requirements. - Question 10Beginner
Working with Java data types · Use local variable type inference
What is the purpose of the
varkeyword introduced in Java 10 and available in Java 11?Show answer & explanation
Correct answer: B
The
varkeyword is used for local variable type inference. It is purely a compile-time feature that allows the developer to omit the explicit type declaration for a local variable when it can be inferred from the right-hand side of the assignment. The variable is still statically typed; its type is fixed at compile time and cannot change.
Ready for the real thing?
The full 1Z0-819 simulator has every exam-style question, timed mode, and instant scoring.