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

Free Oracle Java Foundations 1Z0-811 Exam Questions

Last updated: · 15 practice questions with answers and explanations

Page: 1 / 8 Total 75 questions

Want more questions? Get Premium Access.

Question 1

New Single answer

Topic: What Is Java?

Skill tested: Relates Java platform characteristics to cross-platform application deployment.

A company needs to distribute a small inventory application to offices that use different operating systems. The team wants to compile the application once and avoid maintaining a separate native executable for each operating system. Each office can install compatible Java runtime software, but users should not need the development tools. Which approach best meets these requirements?

Correct Answer: C. Compile the source into Java bytecode and run it on each office's compatible Java runtime.
Explanation:

Java source is compiled into bytecode, which a compatible Java runtime executes on its platform. This allows the same compiled application to run across supported operating systems without shipping the JDK to users. Native executables in A are generally platform-specific. C unnecessarily requires users to compile source, and D incorrectly claims that bytecode runs directly on the processor without a runtime.

Question 2

New Single answer

Topic: Java Basics

Skill tested: Distinguishes JDK development tools from the runtime needed to execute Java programs.

A development team builds a Java application on its workstations, but the deployment policy requires production servers to contain only software needed to run the application. A server administrator proposes installing the JDK everywhere to ensure the application can execute. The application does not need to compile Java source code on the servers. Which recommendation is most appropriate?

Correct Answer: D. Install a JRE-compatible runtime environment; the JDK is needed on systems that compile or develop Java code.
Explanation:

The JDK provides development tools, including the Java compiler, along with the components needed to run Java programs. A production system that only executes an already compiled application needs an appropriate Java runtime, not the compiler. A wrongly makes compilation part of program startup, while C omits the runtime environment. Java source is not executed directly by the operating system as D suggests.

Question 3

New Single answer

Topic: Basic Java Elements

Skill tested: Applies package imports and java.lang automatic availability in a Java source file.

A developer writes a class in a named package. Its code uses `String`, `System`, and `ArrayList`, but does not compile because the compiler cannot resolve `ArrayList`. The team wants to keep the file's package declaration and avoid using fully qualified names throughout the code. Which change should the developer make?

Correct Answer: A. Add `import java.util.ArrayList;` after the package declaration; `String` and `System` are available from `java.lang` automatically.
Explanation:

Types in `java.lang`, including `String` and `System`, are implicitly available in every compilation unit. `ArrayList` is in `java.util`, so it must be imported or referred to by its fully qualified name. A package declaration, when present, precedes import declarations. Thus B misstates the `java.lang` rule, C uses an invalid declaration order and import, and D places the import before the package declaration.

Question 4

New Single answer

Topic: Working with Java Data Types

Skill tested: Uses assignment conversion and explicit casting between primitive numeric types.

A telemetry program stores a count as an `int` and a calibration factor as a `double`. It must calculate a fractional result, then store that result in an `int` field because the receiving system accepts only whole numbers. The team accepts truncation of the fractional part but wants the code to compile without changing the field type. Which expression correctly performs the conversion?

Correct Answer: C. `int result = (int) (count * factor);`
Explanation:

Multiplying an `int` by a `double` promotes the result to `double`. Assigning that value to an `int` requires an explicit narrowing cast; `(int)` truncates the fractional portion toward zero. A and D attempt an implicit narrowing conversion and do not compile. C casts only the count, then multiplication still produces a `double`, so its declared result type does not meet the requirement.

Question 5

New Multiple answers

Topic: Working with Java Operator

Skill tested: Evaluates operator precedence, short-circuit logic, and increment side effects.

A service processes a batch using `int attempts = 2; int limit = 3; boolean retry = false;`. It evaluates `boolean send = attempts++ < limit && retry || attempts == 3;`. The team must determine both the final value of `attempts` and the value of `send` before deciding whether a retry request is transmitted. Select two statements that correctly describe Java's evaluation. (Select TWO.)

Correct Answer: A. The expression assigns `true` to `send`.; C. `attempts` is 3 after the expression is evaluated.
Explanation:

Post-increment compares the original value 2 with 3, then changes `attempts` to 3. The comparison is true, so `&&` must evaluate `retry`, which is false; the left side of `||` is therefore false. Java then evaluates `attempts == 3`, yielding true, so `send` becomes true. D is false because the left operand of `&&` is true, and E is false because the left side of `||` is false, requiring evaluation of its right operand.

Question 6

New Single answer

Topic: Working with the String Class

Skill tested: Formats String output using conversion specifiers and newline escape formatting.

A reporting utility needs to create one formatted line containing an integer record count and a String status. The format must place the count first, separate the values with a space, and end the line using the platform's line separator. The result should be produced with `String.format`, not printed directly. Which expression satisfies the requirement?

Correct Answer: C. `String.format("%d %s%n", count, status)`
Explanation:

`%d` formats an integral value, `%s` formats a String, and `%n` inserts the platform-specific line separator. The arguments in B match the conversion specifiers and appear in the requested order. A reverses the types in the format relative to the arguments. C also reverses the arguments and uses `\n` rather than the requested platform-independent `%n`. D omits the required line ending.

Question 7

New Single answer

Topic: Working with the Random and Math Classes

Skill tested: Generates a bounded random integer using Random's exclusive upper bound.

A game assigns each new player a uniformly distributed starting position from 10 through 19, inclusive. The implementation must use `java.util.Random` and should avoid manual scaling that can introduce an off-by-one error. Which expression correctly generates the required position?

Correct Answer: B. `10 + random.nextInt(10)`
Explanation:

`nextInt(bound)` returns an integer from zero inclusive to the bound exclusive. Adding 10 to `random.nextInt(10)` therefore produces 10 through 19, with each value equally likely. B can produce 20, while C produces values from 19 through 28. D produces only values from zero through eight and does not shift them to the required range.

Question 8

New Single answer

Topic: Using Decision Statements

Skill tested: Compares String contents with equals rather than object-reference equality.

An access-control routine receives a String role from a configuration parser. The parser may create a new String object even when its characters match a role literal in the program. The routine should grant access whenever the content is exactly `ADMIN`, regardless of whether both references point to the same object. Which condition is appropriate?

Correct Answer: C. `role.equals("ADMIN")`
Explanation:

`String.equals` compares character content, which is the required test even when the parser creates a distinct object. The `==` operator on references checks whether they refer to the same object, so A can reject equal text stored in another object. `compareTo` returns zero for equal content; B and D instead select strings that sort after or differ from `ADMIN`.

Question 9

New Single answer

Topic: Using Looping Statements

Skill tested: Selects a loop form that guarantees one execution before checking its condition.

A command-line tool must prompt for a valid menu choice. It should display the menu and read input at least once, then repeat only when the entered value is outside the accepted range. The input-reading operation must not be duplicated before the first validation. Which loop structure best expresses this behavior?

Correct Answer: A. A `do-while` loop that displays and reads the choice in the body, then checks validity.
Explanation:

A `do-while` loop executes its body before evaluating its condition, so the menu is displayed and input is read at least once. It then repeats when the choice is invalid. A `while` loop checks first and can skip the body, while an empty `for` loop does not clearly express the required validation behavior. An enhanced `for` loop is intended to traverse elements of an iterable or array, not repeat input until a condition is met.

Question 10

New Multiple answers

Topic: Debugging and Exception Handling

Skill tested: Uses targeted catch blocks to handle parsing and arithmetic failures separately.

A batch processor reads a text value, parses it as an integer, and divides 100 by that integer. Invalid text and a zero divisor are expected input failures; the process should report a useful message and continue with the next record. The code must not hide unrelated programming defects behind a broad catch. Which two approaches meet these requirements? (Select TWO.)

Correct Answer: A. Use a multi-catch clause for `NumberFormatException` and `ArithmeticException` and report the record failure.; B. Catch `NumberFormatException` and `ArithmeticException` in separate catch blocks after the `try`.
Explanation:

Parsing nonnumeric text can throw `NumberFormatException`, and integer division by zero can throw `ArithmeticException`. Separate catches or a multi-catch for these distinct exception types can report expected bad records without suppressing unrelated defects. Catching broad `Exception` or `RuntimeException` hides failures the program may not be prepared to handle, and returning zero misrepresents the calculation. In E, the broader `Exception` catch makes the later specific catch unreachable.

Question 11

New Single answer

Topic: Arrays and ArrayLists

Skill tested: Chooses safe ArrayList traversal when removing matching elements.

A Java program stores pending job names in an `ArrayList`. It must remove every job whose name equals `obsolete`, while preserving the order of the remaining jobs. A developer proposes removing matching elements inside an enhanced `for` loop, but the collection may have multiple matches. Which implementation is the most appropriate?

Correct Answer: C. Use an `Iterator`, test each element, and call `iterator.remove()` for each match.
Explanation:

An iterator supports removal of the current element through `iterator.remove()`, allowing traversal to continue safely and preserving the order of retained elements. Removing directly from the list during an enhanced `for` traversal generally invalidates the iterator and can cause `ConcurrentModificationException`. A forward index loop that does not adjust after removal can skip the element shifted into the removed position. D discards the entries that should remain.

Question 12

New Single answer

Topic: Classes and Constructors

Skill tested: Distinguishes instance fields from local variables and initializes objects through constructors.

A `Sensor` class has a private instance field `id`. Each sensor must retain its own identifier, and callers should be able to create a sensor with a supplied identifier. In the current constructor, the developer writes `String id = id;`, then observes that the field remains `null`. Which change correctly initializes the object's field while keeping it private?

Correct Answer: C. Write `this.id = id;` in the constructor that accepts the identifier.
Explanation:

The constructor parameter named `id` shadows the instance field. `this.id` explicitly refers to the current object's field, so `this.id = id;` stores the supplied value for that particular sensor. In the original statement, both unqualified references resolve to the local variable. Making the field static would incorrectly share one identifier across all sensors; C copies the uninitialized field into the parameter, and D cannot initialize the object's field.

Question 13

New Single answer

Topic: Java Methods

Skill tested: Uses static methods through the class and distinguishes them from instance methods.

A utility class provides a method `static int clamp(int value, int minimum, int maximum)` that returns a value within the specified bounds. A caller needs to clamp a reading, but has no need to create or retain a utility object. The class has no constructor requirement or instance state. Which call follows the intended use of the method?

Correct Answer: A. `int safe = Utility.clamp(reading, 0, 100);`
Explanation:

A static method belongs to the class rather than a particular instance, so calling it with the class name is appropriate when there is no instance state. C may compile if the class can be instantiated, but needlessly creates an object and does not reflect the method's class-level use. B is not in scope merely because the method exists in another class. D is not valid Java invocation syntax; method references use a different syntax and are used in functional contexts.

Question 14

New Multiple answers

Topic: Working with Java Operator

Skill tested: Applies compound assignment and integer division rules to primitive arithmetic.

A billing routine uses `int units = 17; int packSize = 5;`. It must calculate the number of complete packs and then reduce `units` by the number of units assigned to those packs. The implementation must use integer arithmetic because partial packs are not billable. Select the two statements that produce the required results: three complete packs and two remaining units. (Select TWO.)

Correct Answer: A. `int packs = units / packSize;`; D. `units %= packSize;`
Explanation:

With integer operands, division truncates the fractional part: `17 / 5` is 3, so A calculates the complete packs. The remainder operator yields `17 % 5`, which is 2, so D leaves the required number of unassigned units. B computes the remainder rather than the pack count. C subtracts only three from 17, not the 15 units assigned to packs. E introduces floating-point division and truncation, which is unnecessary for the specified integer calculation.

Question 15

New Multiple answers

Topic: Using Decision Statements

Skill tested: Selects valid switch labels and prevents unintended fall-through between cases.

A command processor maps integer codes to actions: 1 starts a job, 2 pauses it, and 3 stops it. Each code must execute only its own action; unknown codes must produce an error message. The implementation uses a traditional `switch` statement, and the team wants to avoid accidental fall-through. Select two correct implementation practices. (Select TWO.)

Correct Answer: A. Add a `break` after each action so execution does not continue into the next case.; C. Use `case 1: start(); break;`, with equivalent terminating cases for 2 and 3.
Explanation:

In a traditional switch statement, matching a case transfers control to its statements, and execution continues into subsequent cases unless it encounters a control-transfer statement such as `break`. Terminating each action case prevents accidental execution of another action. A demonstrates a correctly terminated case, and C states the applicable practice. The location of `default` does not determine whether a case is recognized, and a `double` literal is not a valid constant label for an integer switch. Java does not automatically exit each case as E claims.