Limited-Time Offer: Enjoy 50% Savings! Coupon code: 50OFF Use it at checkout
Skip to content

Free Oracle Java SE 8 Programmer I 1Z0-808 Exam Questions

Last updated: · 13 practice questions with answers and explanations

Page: 1 / 15 Total 225 questions

Want more questions? Get Premium Access.

Question 1

New Single answer

Topic: Java Basics

Skill tested: Select a valid Java application entry point and identify its command-line execution form.

A deployment team packages a small Java SE 8 utility in the unnamed package. The source file is named ReportTool.java, and it contains a public class named ReportTool. The class has a method declared as `public static void main(String[] args)`. The team compiles the source from the directory containing the file and wants to launch the class using the standard Java launcher, without specifying a classpath or creating a JAR. Which command sequence is valid?

Correct Answer: D. `javac ReportTool.java` followed by `java ReportTool`
Explanation:

The Java compiler takes the source filename, including its `.java` extension, while the launcher takes the class name without an extension. Thus, compile with `javac ReportTool.java` and launch with `java ReportTool`. The source-file launch form shown in A or C is not the standard Java 8 launcher behavior. `javac` does not compile a bare class name as in A, and the launcher is given a binary class name rather than the generated `.class` filename, so D is invalid.

Question 2

New Single answer

Topic: Java Basics

Skill tested: Distinguish Java platform independence from the platform-specific runtime implementation.

A software company distributes one compiled Java application to customers using different operating systems. Its architecture team wants to explain why the same application can run on those systems, while acknowledging that platform-specific software is still required. Which explanation is most accurate?

Correct Answer: D. The compiler produces bytecode that can run on compatible JVM implementations for each platform.
Explanation:

Java compilation normally produces platform-independent bytecode, and a JVM implementation for a particular platform executes that bytecode. The JVM is therefore a required platform-specific component, even though the same compiled class files can be used across compatible systems. The compiler does not generate native code for all operating systems at once, so A is false. Java bytecode is not executed directly by the processor without a runtime, and Java APIs do not categorically prohibit operating-system-dependent functionality, eliminating B and D.

Question 3

New Single answer

Topic: Working With Java Data Types

Skill tested: Apply primitive widening and narrowing conversion rules when assigning numeric values.

A telemetry component receives an integer sensor reading and must store it as a `byte`. The developer declares `int reading = 130;` and then writes `byte sample = reading;`. Compilation fails. The design requires an explicit conversion in this assignment and does not require a range check or rejection of out-of-range readings. Which change compiles while retaining Java's defined narrowing-conversion behavior?

Correct Answer: C. Use `byte sample = (byte) reading;`.
Explanation:

An assignment from an `int` variable to a `byte` requires an explicit narrowing cast, so `(byte) reading` compiles. Narrowing may discard high-order bits; converting 130 to `byte` yields -126 under Java's two's-complement representation. That behavior is permitted by the stated requirement, which does not call for validation. A is still an illegal implicit narrowing conversion. C attempts an invalid wrapper conversion, and D converts the expression to `double`, which cannot be cast directly to `byte` without an additional conversion.

Question 4

New Single answer

Topic: Using Operators and Decision Constructs

Skill tested: Evaluate short-circuit logical operators and their effects on side-effecting expressions.

A monitoring program uses a counter to record checks. The counter starts at zero, and the code is: `int checks = 0; boolean ready = false; if (ready && ++checks > 0) { System.out.println("ready"); } System.out.println(checks);` The team wants to retain the `&&` condition and understand the value printed by the final statement. Which outcome occurs?

Correct Answer: C. The program prints `0` only.
Explanation:

Java's `&&` operator evaluates its right operand only when the left operand is true. Since `ready` is false, `++checks` is not evaluated, the body is skipped, and `checks` remains zero. Therefore, only `0` is printed. A and B incorrectly assume the increment occurs despite short-circuit evaluation. D incorrectly assumes the `if` body executes when its condition is false.

Question 5

New Multiple answers

Topic: Using Operators and Decision Constructs

Skill tested: Choose correct String comparison semantics for content equality and reference identity.

An import service receives a status value from a parser and compares it with the literal `READY`. During testing, the parser sometimes returns a distinct `String` object containing the same characters as the literal. The service must accept either the literal or an equivalent distinct object as a matching status. A separate diagnostic must determine whether two variables refer to the exact same object. Which two statements meet these requirements? Select two answers.

Correct Answer: C. Use `"READY".equals(status)` to test whether the contents match without risking a null dereference of `status`.; D. Use `status.equals("READY")` to test whether the contents match, provided `status` is non-null.
Explanation:

`String.equals` compares character content, so B works when `status` is known to be non-null. Calling `equals` on the non-null literal, as in C, also compares content and remains safe if `status` is null. The `==` operator compares reference identity for objects, not String contents, so A cannot reliably match a distinct equivalent String. D confuses content equality with identity, and assignment in E changes a reference rather than testing either property. To test identity, use `==` between the two references being compared.

Question 6

New Single answer

Topic: Creating and Using Arrays

Skill tested: Declare and initialize a rectangular two-dimensional array and access its elements.

A reporting component stores four rows of monthly measurements, with three measurements in each row. It must allocate a rectangular two-dimensional `int` array, put `17` in row index 2 and column index 1, and later retrieve that value. Which code performs these operations correctly?

Correct Answer: D. `int[][] values = new int[4][3]; values[2][1] = 17; int result = values[2][1];`
Explanation:

The first dimension represents four rows and the second represents three columns, so `new int[4][3]` creates a rectangular array with valid indices 0-3 and 0-2. The assignment and retrieval at `[2][1]` are valid. B reverses the requested dimensions, though its particular access happens to be in bounds. C is not valid Java declaration and allocation syntax. D creates the outer array but leaves each row reference null, so accessing `values[2][1]` causes a `NullPointerException` unless that row is allocated.

Question 7

New Single answer

Topic: Using Loop Constructs

Skill tested: Use loop control statements to skip selected iterations without terminating the loop.

A batch processor scans integer records from 1 through 8. It must omit record 5, process every other record, and then continue with subsequent records. The existing loop is `for (int record = 1; record

Correct Answer: B. `if (record == 5) continue;`
Explanation:

Within this `for` loop, `continue` skips the remainder of the current iteration and proceeds to the loop's update expression, after which the next condition is checked. This omits record 5 while allowing records 6 through 8 to be processed. `break` exits the loop entirely at 5, and `return` exits the containing method. Assigning 8 to the loop variable causes the loop to end after that iteration rather than processing the remaining records.

Question 8

New Multiple answers

Topic: Working with Methods and Encapsulation

Skill tested: Apply Java pass-by-value semantics to primitive arguments and mutable object references.

A service method receives both an integer priority and a mutable `StringBuilder` label. The caller must retain its original priority, while the method should append `-checked` to the same label object so the caller sees the change. The method must not replace the caller's label reference. Which two implementation choices satisfy these requirements? Select two answers.

Correct Answer: A. Assign a new value to the method's `int` parameter; this does not change the caller's integer variable.; B. Call `label.append("-checked")`; the caller observes the mutation to the shared object.
Explanation:

Java passes arguments by value. The method receives a copy of the primitive value, so assigning to its `int` parameter cannot modify the caller's variable (A). For an object, the copied value is a reference to the same object; mutating that object with `append` is visible to the caller (B). Reassigning the local reference in C does not update the caller's reference. Primitive increments are not copied back, contrary to D, and `toString()` creates a String representation without mutating the builder, so E does not append anything.

Question 9

New Single answer

Topic: Working with Methods and Encapsulation

Skill tested: Use access modifiers to encapsulate fields and provide controlled object access.

A library team exposes a `Booking` class to client code. It must prevent callers from directly changing a booking's seat count while still allowing them to read the count and request a change through a method that enforces validation. Which design best supports this requirement?

Correct Answer: D. Declare `seats` as `private`, provide a public getter, and expose a public method that validates changes before updating the field.
Explanation:

A private field prevents ordinary client code from assigning to `seats` directly. A public getter permits reading, while a public validating method provides the controlled mutation path required by the design. A public field in A bypasses validation; merely offering a method does not force clients to use it. A protected field does not provide the required encapsulation and is not generally accessible to unrelated clients in other packages. Package-private access in D exposes the field within the package and makes the validation method unavailable to clients.

Question 10

New Single answer

Topic: Working with Inheritance

Skill tested: Resolve overridden instance methods using runtime object type and inherited behavior.

A reporting application defines `class Report { String label() { return "base"; } }` and `class AuditReport extends Report { @Override String label() { return "audit"; } }`. It then executes `Report report = new AuditReport(); System.out.println(report.label());`. The variable is intentionally declared using the base class so the reporting pipeline can handle multiple report types. What is printed?

Correct Answer: C. `audit`, because the runtime object overrides the instance method.
Explanation:

For an overridden instance method, Java uses dynamic dispatch: the implementation is selected according to the runtime class of the object. The reference type `Report` determines which members are available at compile time, but the object is an `AuditReport`, so its `label()` implementation runs and prints `audit`. A confuses reference type with runtime type. A superclass reference can call an accessible overridden method, so C is false, and the return type does not select the implementation, so D is false.

Question 11

New Single answer

Topic: Handling Exceptions

Skill tested: Order catch clauses from specific exceptions to their superclass types.

A file-processing method catches `IOException` to report an input failure and also attempts to catch `FileNotFoundException` separately for a more specific message. `FileNotFoundException` is a subclass of `IOException`. The compiler reports that one catch block is unreachable. The team wants to preserve both handlers and their distinct messages. Which change resolves the compilation error?

Correct Answer: C. Place the `FileNotFoundException` catch block before the `IOException` catch block.
Explanation:

A catch block for a superclass handles instances of its subclasses as well. If `IOException` appears first, it catches `FileNotFoundException`, making the later, more specific catch unreachable. Putting `FileNotFoundException` first allows its specific handler to run before the broader `IOException` handler. B preserves the unreachable-block problem. C loses the distinct catch structure and broadens handling unnecessarily, while `Throwable` in D is broader still and would also make subsequent related handlers problematic.

Question 12

New Single answer

Topic: Working with Selected classes from the Java API

Skill tested: Format Java 8 LocalDate values with DateTimeFormatter using the correct pattern.

A scheduling service stores an event date as a Java 8 `LocalDate`. An external report requires the date to be rendered as year-month-day, such as `2024-06-09`, with a four-digit year and two-digit month and day. The service must format the value without converting it to a legacy date class. Which approach is appropriate?

Correct Answer: D. Create a `DateTimeFormatter` with pattern `yyyy-MM-dd` and call `date.format(formatter)`.
Explanation:

`LocalDate` supports formatting with `DateTimeFormatter`; the pattern `yyyy-MM-dd` uses calendar year, month of year, and day of month, producing the requested representation. `LocalDate.toString()` takes no pattern argument, so A does not compile. Uppercase `Y` and `D` in C denote week-based year and day of year in pattern syntax, not the requested calendar year and day of month. `SimpleDateFormat` is a legacy formatter and is not accepted by `LocalDate.format`, so D is invalid.

Question 13

New Single answer

Topic: Working with Selected classes from the Java API

Skill tested: Use a typed ArrayList and remove an element by its value rather than its index.

A Java SE 8 application maintains an `ArrayList` of retry limits. It must remove the element whose value is 2, not the element at index 2. The list may contain several entries, but the first matching value is the only one to remove. Which statement expresses the required operation?

Correct Answer: D. `limits.remove(Integer.valueOf(2));`
Explanation:

`ArrayList` has overloaded `remove` methods: `remove(int index)` and `remove(Object value)`. The literal `2` selects the index overload, so A removes the element at index 2. Passing `Integer.valueOf(2)` selects `remove(Object)` and removes the first matching value, as required. A String is not an `Integer`, so C does not match the stored element. A `long` cannot be used as the `int` index argument without narrowing, and it is not an `Integer` object for value removal, so D does not express the operation.