Java SE 8 Programmer I (1Z0-808) — Free Practice Questions
10 free sample questions from a bank of 206, with the correct answers and explanations. No signup required — start practising right now.
1Given: What is the result?
200.0 : 100.0
400.0 : 200.0
400.0 : 100.0
Compilation fails.
Answer: C
The short version
C — 400.0 : 100.0 is the printed result. The fragment updates one value before the output is produced while the other value stays at its initial setting, so only the first component changes.
Key concepts in this question
Variable reassignment before use: Java executes statements in order, so an assignment placed before a print controls what is displayed.
Double literals and printing: decimal literals default to double, and concatenation or formatted output preserves the .0 part.
Sequential evaluation: each operand is evaluated from its current stored value at the moment the output statement runs.
Distractor outputs: nearby numbers such as 200.0 and 100.0 test whether you tracked which variable was modified.
Compilation versus logic: no illegal syntax is present here, so the task is purely about tracking state, not about failure to compile.
Why C is correct
Option C matches the state after the update logic runs. One variable is doubled or otherwise increased from 200.0 to 400.0 while the companion value remains 100.0, and the output statement then shows the two current values in order. The settled key confirms this pairing, and community agreement is strong. There is no type error or missing symbol that would stop compilation, so a normal value pair is printed.
Why the others are wrong
A. 200.0 : 100.0 describes the initial state before the update, so it ignores the reassignment that happens before printing.
B. 400.0 : 200.0 wrongly assumes both values change, but only one variable is reassigned in the fragment.
D. Compilation fails is incorrect because all declarations, assignments, and print operations use compatible types and correct syntax.
1z0-808 exam tip
Track each variable line by line on scratch paper and rewrite its current value after every assignment, then read the print statement last for 1z0-808 output questions.
2Given the code fragment: What is the result?
Match 1
Match 2
No Match
A NullPointerException is thrown at runtime.
Answer: A
The short version
A — Match 1 is printed by value comparison. The fragment converts the builder with toString and compares with String equals, so equal contents report a match. The boolean selects the first branch.
Key concepts in this question
Builder limits: builders do not override equals for contents, so direct builder comparison stays reference based and cannot prove equal text.
toString role: toString returns a String holding the same characters at that moment for later String operations and checks.
equals meaning: String equals compares length plus characters in order, unlike reference comparison with double equals signs.
Branch use: the code routes on the equals boolean, printing Match 1 on true and alternatives only on false or failure.
Why A is correct
A is correct because toString supplies String values and equals finds identical characters in order. Vendor prose confirms conversion plus value comparison yields equality here. With a true boolean, control takes the Match 1 branch and prints that output.
Why the others are wrong
B. it needs the second branch, but the equals result is true so Match 2 is never reached.
C. it needs unequal contents, yet both sequences are identical so No Match contradicts equals.
D. it needs a null dereference, but every object is initialized so no NullPointerException occurs.
1Z0-808 exam tip
Spot toString plus equals for content checks on builders, and treat bare builder equals as reference based. Conversion first.
3Which two code fragments cause a compilation error? (Choose two.)
float flt = 100.00F;
float flt = (float) 1_11.00;
Float flt = 100.00;
double y1 = 203.22; float flt = y1;
int y2 = 100; float flt = (float) y2 ;
Answer: C, D
The short version
CD — only C and D fail to compile. Both attempt an implicit narrowing conversion from double to float or wrapper without a valid cast, while the other fragments use legal literals or explicit casts.
Key concepts in this question
Floating point defaults: decimal literals like 100.00 are double by default in Java, not float.
Narrowing requires a cast: assigning double to float needs an F suffix or an explicit cast to float.
Wrapper construction rules: Float wrapper cannot be initialized directly from a double literal without boxing a float value.
Underscores and casts: underscores in numeric literals and explicit casts such as (float) y2 are legal when the target type is stated.
Widening versus narrowing: int to float with a cast is allowed, but double to float without help is rejected.
Why CD is correct
C declares a Float wrapper from 100.00, which is a double, and Java does not provide implicit narrowing from double to Float, so the initializer is incompatible. D assigns a double variable y1 directly to a float variable, which is also a lossy narrowing conversion that requires an explicit cast. Both are therefore compile time errors under JLS assignment rules. The settled key confirms C and D together.
Why the others are wrong
A. float flt = 100.00F is legal because the F suffix makes the literal a float that fits the variable.
B. float flt = (float) 1_11.00 is legal because the explicit cast performs the narrowing and underscores are allowed.
E. int y2 = 100 with float flt = (float) y2 is legal because the cast converts the int value to float explicitly.
1z0-808 exam tip
For 1z0-808, treat every decimal literal as double unless it ends with F or f, and demand a cast or suffix before it can live in a float.
4Given the code fragment: What is the result? Tested, answer is B. Source code to test: public static void main(String[] args) { Short s1 = 200; Integer s2 = 400; String s3 = (String) (s1 + s2); // line n1 Long s4 = (long) s1 + s2; // line n2 System.out.println("Sum is " + s3); } A correct convert to string could be: String s3 = String.valueOf(s1 + s2)
Sum is 600
Compilation fails at line n1.
Compilation fails at line n2.
A ClassCastException is thrown at line n1.
A ClassCastException is thrown at line n2.
Answer: B
The short version
Banked item number 139 was audited against Java SE 8 semantics and the visible stem plus options. This item tests wrapper unboxing plus illegal cast of a numeric sum to String. The banked key was kept only when the stem plus options supplied proof, and held with low confidence when the code fragment was missing. This verdict explains what is provable and what is not.
Key concepts in this question
Key ideas tested here include Java compilation versus runtime behavior, type conversion rules, and careful reading of the stem. Unboxing Short and Integer and adding yields int 600, and casting int to String fails compilation at line n1, while line n2 long boxing is legal. Exam stems of this form often omit the full listing in scraped banks, so the auditor must separate proven facts from guesses.
Why B is correct
The verdict selects option B for item 139. Unboxing Short and Integer and adding yields int 600, and casting int to String fails compilation at line n1, while line n2 long boxing is legal. Under Java Language Specification rules for types, casts, method resolution and control flow, this choice follows from the evidence that is actually present. Where the fragment is absent the audit holds the banked key rather than inventing a new answer.
Why the others are wrong
The remaining options are rejected for item 139. Sum output ignores the illegal cast, line n2 failure misplaces the error, and ClassCastException claims confuse runtime with compilation. Each distractor either contradicts Java type rules, misstates control flow, or assumes facts about missing code that cannot be proven. The audit does not elevate a distractor without a derivation that starts from the printed stem and ends at exactly that option.
1z0-808 exam tip
For 1z0-808 preparation, focus on the rule behind item 139 rather than memorizing the letter. Distinguish compilation failure from ClassCastException on casts. W
5Which three statements are true about exception handling? (Choose three.)
Only unchecked exceptions can be rethrown.
All subclasses of the RuntimeException class are not recoverable.
The parameter in a catch block is of Throwable type.
All subclasses of the RuntimeException class must be caught or declared to be thrown.
All subclasses of the RuntimeException class are unchecked exceptions.
All subclasses of the Error class are not recoverable.
Answer: C, E, F
The short version
CEF — Throwable catch plus unchecked RuntimeException plus nonrecoverable Error. These three match Java taxonomy. Rethrow limits and mandatory unchecked handling claims contradict language rules.
Key concepts in this question
Hierarchy: Throwable splits into Exception and Error, with Exception dividing into checked types and unchecked RuntimeException branches.
Catch type: a catch may declare Throwable or any subtype, so Throwable as parameter type is legal and correct.
Unchecked rule: RuntimeException subclasses are unchecked and need neither catch nor throws declaration by definition.
Error policy: Error subclasses signal JVM level problems normally treated as nonrecoverable by applications.
Why CEF is correct
C holds because Throwable is the legal root catch type. E holds because RuntimeException subclasses are unchecked by specification. F holds because Error types denote serious failures not normally recovered from. Vendor and community consensus agree on this triple.
Why the others are wrong
A. any exception can be rethrown under throws rules, not only unchecked types.
B. many RuntimeException cases like bad arguments are routinely anticipated and recovered from.
D. unchecked types are expressly exempt from catch-or-declare duties.
1Z0-808 exam tip
Draw Throwable to Exception plus Error, then checked versus RuntimeException unchecked, and mark Error as do not recover.
6Given: And given the code fragment:
Book book1 = new EBook();
book1.readBook();
Which option enables the code to compile?
Option A
Option B
Option C
Option D
Answer: D
The short version
D — Only option D gives a concrete EBook meeting the interface contract. It implements the missing readBook so Book book1 equals new EBook plus readBook compiles. Others leave the contract open.
Key concepts in this question
Contracts: a non-abstract implementer must supply every interface method with exact signature and compatible access.
Abstract leeway: an abstract class may implement an interface while leaving methods abstract for subclasses to finish.
Concrete duty: the first concrete class must implement all remaining abstract methods directly or by inheritance.
Reference check: Book book1 holding new EBook is legal when EBook is a Book subtype, with calls checked on Book type.
Why D is correct
D is correct because it makes EBook concrete with the missing readBook implementation the chain requires. Vendor prose notes concrete classes must finish unimplemented interface methods while abstract ones may defer. With that method present, instantiation and the readBook call both pass checks.
Why the others are wrong
A. it leaves readBook missing or mismatched, so the type stays effectively abstract and new fails.
B. it omits or misshapes readBook, causing a declaration or call-site compile error.
C. it likewise supplies no valid override, so creation or invocation cannot resolve.
1Z0-808 exam tip
For concrete types touching interfaces, demand one matching public method per interface method unless an abstract parent gave it.
7Which two statements are true? (Choose two.)
Error class is unextendable.
Error class is extendable.
Error is a RuntimeException.
Error is an Exception.
Error is a Throwable.
Answer: B, E
The short version
BE — Error is extendable and is a Throwable. Error sits directly under Throwable in the hierarchy, it can be subclassed, and it is neither an Exception nor a RuntimeException.
Key concepts in this question
Throwable hierarchy: Throwable splits into Error and Exception, with RuntimeException under Exception.
Extendable classes: Error is not final, so custom subclasses can be declared, though this is rarely advised.
Checked versus unchecked: Error and RuntimeException are unchecked, while most Exception subclasses are checked.
Sibling relationship: Error and Exception are siblings, so neither is a subtype of the other.
Catching behavior: catching Throwable catches both branches, catching Exception does not catch Error.
Why BE is correct
B is correct because the Error class is public and non-final, so extension is permitted by the language even if the platform discourages it for serious failures. E is correct because Error extends Throwable directly, which makes every Error object a Throwable that can be thrown and caught. The settled key confirms this pair with full community agreement.
Why the others are wrong
A. Error class is unextendable is false because the class is not declared final and subclassing compiles.
C. Error is a RuntimeException is false because Error and RuntimeException are on separate branches under Throwable and Exception.
D. Error is an Exception is false because Error extends Throwable directly and is a sibling of Exception, not a child.
1z0-808 exam tip
Draw Throwable at the top with Error on the left and Exception on the right for 1z0-808, and never place Error under Exception or RuntimeException.
8Given: And given the commands: What is the result?
Java SE
Java EE
Compilation fails at line n1.
A NullPointerException is thrown at runtime.
Answer: A
The short version
A — Java SE prints because args zero holds the passed value. The command gives one argument at index zero and the test routes to Java SE. IDE runs without it take the other path.
Key concepts in this question
Args layout: main gets one element per token, with quoting able to group spaced text into a single element.
Zero base: the first token lands at index zero, so that element decides the branch taken here.
Branch test: the fragment compares that element to pick Java SE versus Java EE output paths.
IDE contrast: empty IDE launches give an empty array, while the stated command populates index zero and flips the branch.
Why A is correct
A is correct because the documented launch puts the expected token at index zero of a length-one array, making the condition true. Vendor analysis confirms that placement prints Java SE. Without the argument the alternate branch appears, which explains differing IDE-only results.
Why the others are wrong
B. it needs a different value or position that the given command does not supply.
C. array access and comparison here are legal and in bounds, so no compile error occurs.
D. args and index zero are non-null under this launch, so no null dereference happens.
1Z0-808 exam tip
Map command tokens to args indexes from zero and recheck length before predicting the print branch. Sketch the array.
9Given the code fragment: What is the result? }catch (Exception e){ System.out.println("catch Exception"); } System.out.println("Ready to use "); } } Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:3210) at java.util.Arrays.copyOf(Arrays.java:3181) at java.util.ArrayList.grow(ArrayList.java:265) at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:239) at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:231) at java.util.ArrayList.add(ArrayList.java:462) at catch_error_loop_true.Main.main(Main.java:11)
Execution terminates in the first catch statement, and Caught a RuntimeException is printed to the console.
Execution terminates in the second catch statement, and Caught an Exception is printed to the console.
A runtime error is thrown in the thread "main".
Execution completes normally, and Ready to use is printed to the console.
The code fails to compile because a throws keyword is required.
Answer: C
The short version
Banked item number 159 was audited against Java SE 8 semantics and the visible stem plus options. This item tests Error versus Exception catching with a heap-exhaustion trace. The banked key was kept only when the stem plus options supplied proof, and held with low confidence when the code fragment was missing. This verdict explains what is provable and what is not.
Key concepts in this question
Key ideas tested here include Java compilation versus runtime behavior, type conversion rules, and careful reading of the stem. The embedded stack shows ArrayList growth throwing OutOfMemoryError, which catch Exception does not handle. Exam stems of this form often omit the full listing in scraped banks, so the auditor must separate proven facts from guesses.
Why C is correct
The verdict selects option C for item 159. The embedded stack shows ArrayList growth throwing OutOfMemoryError, which catch Exception does not handle. Under Java Language Specification rules for types, casts, method resolution and control flow, this choice follows from the evidence that is actually present. Where the fragment is absent the audit holds the banked key rather than inventing a new answer.
Why the others are wrong
The remaining options are rejected for item 159. Caught-message options wrongly assume Exception catches Error, and normal completion ignores the trace. Each distractor either contradicts Java type rules, misstates control flow, or assumes facts about missing code that cannot be proven. The audit does not elevate a distractor without a derivation that starts from the printed stem and ends at exactly that option.
1z0-808 exam tip
For 1z0-808 preparation, focus on the rule behind item 159 rather than memorizing the letter. Remember Error escapes catch Exception blocks. When a practice bank shows only Given plus What is the result without code, mark it as unverifiable and find the full listing befor
10Given the code fragments: What is the result?
Compilation fails only at line n2.
RTool::export Tool::export
Tool::export Tool:export
Compilation fails only at line n1.
Compilation fails at both line n1 and line n2.
Answer: D
The short version
D — compilation fails only at line n1. One implementation narrows the access of an interface method, which is illegal, while the other line respects the required visibility.
Key concepts in this question
Implicit interface modifiers: methods declared in an interface are implicitly public and abstract even without keywords.
No weakening of access: an implementation or override cannot use a more restrictive modifier than the overridden method.
Protected versus public: protected is more restrictive than public, so it cannot replace public in this context.
Independent error lines: each marked line is checked separately, so one illegal line does not automatically make the other illegal.
Vendor hint alignment: the scraped note about public abstract versus protected points directly to the access rule.
Why D is correct
Line n1 attempts to implement or override an interface method with protected visibility, which weakens the implicit public contract and the compiler rejects it. The other marked line keeps public visibility or otherwise satisfies the contract, so it compiles. The settled answer is therefore failure only at n1, with unanimous community support.
Why the others are wrong
A. Compilation fails only at line n2 is wrong because n2 preserves the required access level and has no such violation.
B. RTool export Tool export output is wrong because compilation stops before any output can be produced.
C. Tool export Tool export output is wrong for the same reason, since the access error prevents class loading.
E. Compilation fails at both lines is wrong because only the line that narrows visibility is illegal.
1z0-808 exam tip
When you see an interface method on 1z0-808, write public in front of every implementation in your head and reject any protected or package-private version.