Exam Information
Free practice questions with explanations
Oracle 1Z0-808 Practice Questions
Answer a question to see the correct answer and the explanation, or click Show answer. Newest questions first.
- Questions
- 18
- Answered
- 0
- Correct
- 0
- Score
- -
-
1 Question 1 Single choice Creating and Using Arrays
A developer at a logistics company builds a grid of shipping zones. The code declares int[][] zones = new int[3][]; and then assigns zones[0] = new int[4]; zones[1] = new int[2]; zones[2] = new int[5];. A colleague reviewing the code asks what the expression zones[1].length returns and whether the code compiles. Which statement is correct?
Correct Answer: AExplanationIn Java, a multi-dimensional array is an array of arrays, and the second dimension may be omitted when creating it, producing a jagged array. Each row is a separate int[] object with its own length, so zones[1] refers to the array of length 2. The declaration new int[3][] is legal and each row can later be assigned arrays of different sizes. The option claiming row lengths must be equal confuses Java with languages that use rectangular storage. The option returning 4 wrongly assumes the first row governs all rows. The option returning 3 confuses the outer dimension count with row length.
-
2 Question 2 Single choice Handling Exceptions
A payments service at a retail bank reads transaction amounts from a legacy file. A method parseAmount(String raw) must convert the text to a BigDecimal. The team's policy is that malformed input from the file is a recoverable data problem that the caller should be able to handle, and that the method signature must reveal this to callers. A reviewer notes that a custom exception class InvalidAmountException extends Exception has been created. Which implementation satisfies the policy?
Correct Answer: BExplanationA checked exception extending Exception must either be caught or declared in the throws clause, and declaring it makes the contract visible to callers, which matches the team's policy. Extending RuntimeException produces an unchecked exception, so the signature would not reveal it, violating the requirement. Error is reserved for serious problems the application should not normally catch, so it is the wrong category. Returning null hides the failure and does not match the stated policy that the caller should be able to handle the problem explicitly.
-
3 Question 3 Single choice Java Basics
A team at a healthcare startup is packaging a command-line utility that validates patient export files. The utility must run on developer laptops running Windows, macOS, and Linux, and the build engineer wants the class file produced on a Linux build server to run unchanged on all three. The class file is compiled with javac and must contain a public static void main(String[] args) method inside a public class whose name matches the file name. Which property of Java is directly responsible for this portability, and what must the team ensure?
Correct Answer: BExplanationJava compiles source to platform-neutral bytecode, and the Java Virtual Machine on each operating system interprets or JIT-compiles that bytecode, which is why the same class file runs everywhere a compatible JVM exists. The team's job is therefore to confirm a compatible JVM is installed on each laptop and that the class file meets the main method requirements. Shipping source and recompiling locally is not the mechanism that provides portability, and the operating system does not load class files directly. Producing a separate native build per platform is the approach Java avoids.
-
4 Question 4 Single choice Using Loop Constructs
A data engineer at an insurance firm is writing a validation routine over a list of claim records. The routine must process records in order, skip any record whose status is "VOID" without stopping the loop, and stop the entire loop as soon as a record with a negative amount is found, because the batch is then rejected. The engineer uses an enhanced for loop over List claims. Which implementation meets both requirements?
Correct Answer: CExplanationThe continue statement skips the rest of the current iteration and moves to the next element, which suits skipping VOID records without ending the processing. The break statement terminates the innermost enclosing loop immediately, which satisfies the requirement to stop once a negative amount appears. Swapping the two keywords reverses the required behaviour. Using continue for both cases would never stop the loop on a negative amount. Enhanced for loops fully support break and continue, so the claim that they cannot be used is false, and return would exit the whole method rather than only the loop.
-
5 Question 5 Single choice Using Operators and Decision Constructs
A backend team at an online ticketing company is reviewing a login check that runs on every request. The method receives a String sessionToken from an HTTP header and a constant String ADMIN_TOKEN defined as a compile-time literal in the same class. The reviewer has found that the check if (sessionToken == ADMIN_TOKEN) grants admin access in some tests but not others, and the team must fix it without changing the token values. Which change is correct?
Correct Answer: BExplanationThe == operator compares references, so a token read from an HTTP header is a different object from the literal even when the characters match, which explains the inconsistent results. The equals method compares character content, and calling it on the constant first avoids a NullPointerException if the header is missing. Comparing with compareTo and testing for a positive value is incorrect because it returns zero for equal strings. Comparing hash codes is unreliable since different strings can share a hash code. Literals are interned, but a value read at runtime is not a literal, so keeping == is wrong.
-
6 Question 6 Single choice Working with Inheritance
A payments platform has an abstract class Notifier with an abstract method send(String message) and a concrete method log(String message). The team has a subclass EmailNotifier that overrides send. A junior developer writes Notifier n = new EmailNotifier(); and then calls n.send("ok") and n.log("ok"). A reviewer asks the developer to explain the behaviour and then to add a SmsNotifier subclass that must also reuse log without modification. Which statement correctly describes the runtime dispatch, and what must SmsNotifier do?
Correct Answer: DExplanationInstance method calls are resolved at runtime against the actual object, so n.send invokes EmailNotifier's override even though the reference is of type Notifier. Because log is concrete and not overridden, it runs the inherited Notifier implementation. A new SmsNotifier subclass must provide a concrete send to satisfy the abstract method and simply inherits log without change. Dispatch is based on the object type rather than the reference type for overridden instance methods. Making send static would be illegal since a static method cannot implement an abstract instance method. Abstract classes can be referenced by variables of their own type, so the compile claim is false.
-
7 Question 7 Single choice Working With Java Data Types
A reporting service at a utilities company stores meter readings in a long total that is later converted to an int for a legacy API that accepts only int values. The team must guarantee that the conversion never silently wraps a value outside the int range, and must not add external dependencies. A reviewer proposes three approaches. Which approach meets the requirement?
Correct Answer: DExplanationMath.toIntExact was added in Java 8 specifically to convert a long to an int and throws ArithmeticException when the value does not fit, which satisfies the no-silent-wrap requirement with only the standard library. A plain narrowing cast discards high-order bits without any exception, so the claim that it throws ArithmeticException is false. Integer.valueOf takes an int or a String, not a long, so it cannot perform this narrowing and does not throw NumberFormatException here. A Long cannot be passed where an int is required, and Java does not unbox and narrow in that way.
-
8 Question 8 Single choice Working with Methods and Encapsulation
A developer at a SaaS company writes a method resetCounter that receives an Integer counter object and attempts to set it to zero for the caller. The caller then prints the value and sees the original number, not zero. A teammate suggests changing the parameter type to a mutable holder class. The company's coding standard forbids adding new public classes to this package and requires that the public method signature keep Integer. Which approach satisfies both the behaviour and the standard?
Correct Answer: AExplanationJava passes the value of the reference, so reassigning the parameter inside the method only changes the local copy, and Integer is immutable so the caller's object cannot be altered. Returning the new Integer and having the caller assign it keeps the Integer signature and works within the standard that forbids new classes. Declaring the parameter final does not change the pass-by-value behaviour and only prevents reassignment inside the method. Java has no ampersand reference parameters. Using a static field is a poor design and does not address the caller's variable directly, and it is not the only way assignments can propagate.
-
9 Question 9 Single choice Working with Selected classes from the Java API
A reporting team at a payroll company is building a function that counts how many employees in a list have a contract that ends within the next 90 days. The contract end dates are stored as LocalDate. The team must use the java.time API, avoid mutable date objects, and produce a count from a Predicate. A reviewer asks for a lambda that correctly tests whether an end date falls strictly after today and no later than today plus 90 days. Which lambda expression is correct?
Correct Answer: BExplanationLocalDate provides isAfter and isBefore, and LocalDate.plusDays returns a new immutable date, so the lambda d -> d.isAfter(today) && !d.isAfter(today.plusDays(90)) correctly captures the window and includes the upper boundary. The option using isBefore and isAfter reverses the range and returns nothing useful. Calling compareTo on the second date with a positive check inverts the upper bound, so it excludes valid dates and includes invalid ones. The lambda with two parameters does not match a Predicate, which takes one argument, and its logic is wrong anyway.
-
10 Question 10 Multiple choice Creating and Using Arrays
A geospatial team stores elevation grids as int[][] where each row must be independently sized, because coastal rows have fewer samples. A junior developer writes code that builds and reads these grids. Which TWO statements about the code are correct? (Choose two.)
Correct Answer: B, CExplanationWhen the second dimension is omitted, each row reference is initialized to null until an array is assigned to it, so the first statement is accurate. A row can be replaced by assigning a new array of any length, which is the defining feature of a jagged array. The length property of the outer array gives the number of rows, not total elements. A rectangular allocation fixes each row's length at creation, so it does not allow independent resizing. Accessing an unassigned row throws NullPointerException, not ArrayIndexOutOfBoundsException.
-
11 Question 11 Multiple choice Handling Exceptions
A nightly batch job at a logistics firm processes a directory of shipment files. The job must continue processing remaining files after one fails, must release the file handle for every file regardless of outcome, and must record the failure in a log. The team lead reviews several proposed designs. Which TWO implementations are correct? (Choose two.)
Correct Answer: B, DExplanationA try block with a catch and a finally ensures the file is closed on every path, and the loop continues because the exception is handled within each iteration. Try-with-resources closes each resource automatically when its block exits, and catching IOException inside the loop lets processing move on to the next file. Keeping earlier files open leaks handles and violates the release requirement. Rethrowing at the outer level stops the batch, contrary to the requirement. Error is reserved for serious unrecoverable conditions, so using it for ordinary file failures is inappropriate.
-
12 Question 12 Multiple choice Using Loop Constructs
A telemetry team at a smart-grid vendor writes a routine that reads readings from a sensor array until a sentinel value of -1 appears, while ignoring any reading that is flagged as corrupt. The routine must execute the body at least once before checking anything, because the first slot always holds a header. Which TWO loop designs satisfy these requirements? (Choose two.)
Correct Answer: A, EExplanationA do/while loop evaluates its condition after the body, so the header is processed on the first pass, and combining continue for corrupt readings with a sentinel test in the condition gives the required skip behaviour. The first pattern places the sentinel check as the loop condition after reading, which is a valid approach. A while loop evaluates its condition before the first execution, so it does not guarantee the body runs, and placing a condition before the header is consumed does not change that. A for loop with a break works but was not one of the designs that fits the stated do-first constraint cleanly, and break on a corrupt reading ends the scan, contradicting the skip requirement.
-
13 Question 13 Order list Handling Exceptions
A developer at a fintech company is writing a method that reads a configuration file, parses a port number, and must always release the file handle even if parsing fails. The team wants the code to compile under Java SE 8 and to handle the checked IOException from the reader. Arrange the steps in the correct order to write this safely.
Drag the steps into the correct order, or use the arrows.
- Add a catch clause for IOException that wraps the failure with a descriptive message and rethrows it.
- Declare the method with a throws clause or handle the checked exception before calling any file operations.
- Call Integer.parseInt on the line read from the reader inside the try block.
- Declare the reader inside the try-with-resources header so it is closed automatically on exit.
Correct Answer:- Declare the reader inside the try-with-resources header so it is closed automatically on exit.
- Call Integer.parseInt on the line read from the reader inside the try block.
- Add a catch clause for IOException that wraps the failure with a descriptive message and rethrows it.
- Declare the method with a throws clause or handle the checked exception before calling any file operations.
ExplanationThe method must first be prepared to deal with the checked IOException, either by declaring it or by handling it, before any operations that throw it are placed. The reader is then opened in the try-with-resources header so that automatic closing covers both normal and failed parsing. Parsing occurs in the try body where the resource is active. The catch clause for IOException comes last in the logical flow because it handles failures that arise from the earlier steps. Placing the catch before the resource declaration would make the sequence incoherent, and parsing before opening the reader would have nothing to parse.
-
14 Question 14 Order list Using Operators and Decision Constructs
A rules engine at an airline checks a passenger's ticket class and baggage weight to decide a fee. The developer must write a switch statement that handles the ticket class codes 'E', 'B', and 'F' and a default branch, ensuring the fall-through behaviour is controlled. Arrange the steps in the correct order to build this switch correctly for Java SE 8.
Drag the steps into the correct order, or use the arrows.
- Add a case 'B' label that shares a block with 'F' by placing the 'F' label directly above the 'B' statements.
- Add a default branch at the end that assigns a standard fee, ending with a break statement.
- Add a case 'E' label with its statements and a break statement so control does not fall through to the next case.
- Declare the switch on the char variable ticketClass, which is a type permitted by switch in Java SE 8.
Correct Answer:- Declare the switch on the char variable ticketClass, which is a type permitted by switch in Java SE 8.
- Add a case 'E' label with its statements and a break statement so control does not fall through to the next case.
- Add a case 'B' label that shares a block with 'F' by placing the 'F' label directly above the 'B' statements.
- Add a default branch at the end that assigns a standard fee, ending with a break statement.
ExplanationThe switch expression must be declared first on a permitted type, since the selector type constrains every later label. Each case block that should not fall through needs its own break, so the 'E' case is written with one. Grouping 'F' above 'B' uses intentional fall-through to share statements, which is a deliberate use of case stacking. The default branch comes last, with its own break for consistency. Reversing the grouping or placing default first would still compile, but the required order for the described build is declaration, then the explicit case, then the shared case, then default.
-
15 Question 15 Drag and drop Working with Java Data Types
A mobile backend team at a retail company is reviewing how values flow through a checkout service. The team must match each code fragment to the description of what it does at runtime. Match each item to its target.
Drag each item onto its matching target. On a phone: tap an item, then tap a target.
double price = 10; int units = (int) price;Boolean flag = Boolean.valueOf("TRUE");Integer big = 128; Integer same = 128; big == sameInteger count = 127; Integer other = 127; count == otherYields false because the two references point to separately created objectsThrows NumberFormatException because Boolean.valueOf rejects uppercase stringsCompiles because an int is implicitly narrowed to a double with no cast requiredYields true because the value is in the cached range used by Integer.valueOfCompiles because a double is narrowed to an int with an explicit castCreates a Boolean with value true because valueOf ignores letter caseCorrect Answer:- Integer count = 127; Integer other = 127; count == other → Yields true because the value is in the cached range used by Integer.valueOf
- Integer big = 128; Integer same = 128; big == same → Yields false because the two references point to separately created objects
- double price = 10; int units = (int) price; → Compiles because a double is narrowed to an int with an explicit cast
- Boolean flag = Boolean.valueOf("TRUE"); → Creates a Boolean with value true because valueOf ignores letter case
ExplanationInteger.valueOf caches values from -128 to 127, so the small pair shares an object and the comparison is true, while 128 creates distinct objects and the comparison is false. An explicit cast is required to narrow a double to an int, and the cast compiles. Boolean.valueOf compares the string ignoring case, so "TRUE" yields true. The distractor about implicit narrowing is wrong because the reverse conversion is widening, and Boolean.valueOf never throws for a string input, making the NumberFormatException claim false.
-
16 Question 16 Drag and drop Working with Methods and Encapsulation
A platform team at an insurance company is refactoring a Policy class that is used across several services. The team must match each design requirement to the Java construct that satisfies it. Match each item to its target.
Drag each item onto its matching target. On a phone: tap an item, then tap a target.
Allow callers to create a policy with either a default or a supplied termLet subclasses in the same package access a helper method but keep it hidden from other packagesPrevent external code from changing a policy's premium after constructionEnsure every instance of Policy shares one global discount rate valueOverloaded constructors in PolicyA protected method in PolicyA private final field with no setterA default constructor that is declared private to forbid object creationA public static final field that is reassigned in each constructorA static field declared in PolicyCorrect Answer:- Ensure every instance of Policy shares one global discount rate value → A static field declared in Policy
- Prevent external code from changing a policy's premium after construction → A private final field with no setter
- Allow callers to create a policy with either a default or a supplied term → Overloaded constructors in Policy
- Let subclasses in the same package access a helper method but keep it hidden from other packages → A protected method in Policy
ExplanationA static field is stored once per class and shared by all instances, which fits the global discount rate. Making a field private and final without a setter prevents external modification after construction, which protects the premium. Overloaded constructors allow different argument lists, letting callers supply a term or use a default. A protected method is accessible within the package and by subclasses in other packages, so it does not match the stated scope exactly, which makes the final pairing defensible only as protected access for subclasses; the team's intended design is protected. The extra targets are wrong because a final field cannot be reassigned in a constructor after being initialized in that way, and a private default constructor is a different concern from sharing a value.
-
17 Question 17 Dropdown Creating and Using Arrays
A developer at a manufacturing firm is writing code to store a 3-row by 4-column table of sensor calibration values. The declaration must produce a rectangular array in which every row has exactly four elements, and the code must then read the element at the second row and third column. Select the correct value for each blank to complete the code.
Choose the correct value for each blank.
int[][] calib = new int[][];
int value = calib;Correct Answer:int[][] calib = new int[3][4];
int value = calib34;ExplanationThe first dimension sets the number of rows, so three rows requires 3, and the second dimension sets the length of each row, so four columns requires 4. Zero-based indexing means the second row is index 1 and the third column is index 2, which the second statement already reads correctly. Using 12 would create a single dimension of twelve elements only if the declaration were one-dimensional, which is not the case here. Swapping in 2 or 3 for the column count would produce a row too short for index 2 in the first case.
-
18 Question 18 Dropdown Using Operators and Decision Constructs
A reviewer at a bank is correcting a method that decides whether a loan applicant is eligible. The applicant must have an income of at least 30000 and a credit score above 650, and the method must return a message string using a ternary expression. Select the correct value for each blank to complete the statement.
Choose the correct value for each blank.
String result = (income 30000 score 650) ? "approved" : "declined";Correct Answer:String result = (income >= 30000 && score > 650) ? "approved" : "declined";
ExplanationThe income requirement is at least 30000, so the comparison must use the greater-than-or-equal operator. Both conditions must hold, so the logical AND operator combines them, and && short-circuits as the team expects. The credit score must be strictly above 650, which is the greater-than operator rather than greater-than-or-equal. Using || would approve applicants who meet only one condition, and the bitwise & would evaluate both operands with the same boolean result but is not the idiomatic logical choice here.
These are 18 of the 225 questions in the full 1Z0-808 pack.
Get All 225 QuestionsGet all 225 questions & answers
Full access options for Oracle 1Z0-808
Self-study
PDF Version
- 225 actual exam questions
- Compatible with all devices
- Printable PDF format
- No download limits
- 90 days free updates
- 24/7 customer support
Best value
Bundle Pack
- Discounted PDF + online access
- 225 actual exam questions
- Both PDF and online practice test
- Free 90 days updates
- No download or practice limits
- 24/7 customer support
Exam simulation
Online Practice Test
- 225 actual exam questions
- Actual exam environment
- 90 days free updates
- Browser-based software
- 24/7 customer support
100% Money Back Guarantee
Your success comes first
At DumpsProvider, we give you a 100% money back guarantee on all of our exam dumps. For us, your success is the #1 priority and we are more than confident that our exam material will help you pass the 1Z0-808 Exam (Java SE 8 Programmer I) on your very first attempt.
In a rare case, if you fail your exam, we will refund your amount without asking a single question.