Oracle Java Foundations (1Z0-811) — Questions and Answers
Question 1: What is the correct way to declare a singleton class in Java?
- Make the constructor private and provide a static factory method (Correct answer)
- Make the class abstract with a single subclass
- Use the `singleton` keyword in the class declaration
- Declare the class as final with all public constructors
Correct answer: Make the constructor private and provide a static factory method
A singleton restricts instantiation by using a private constructor and a static method that returns the single instance.
Question 2: Which option passed to `javac` enables preview features in Java 11?
- --enable-preview combined with --release 11 (Correct answer)
- --enable-preview alone
- --experimental
- --preview-features
Correct answer: --enable-preview combined with --release 11
Preview features require both `--enable-preview` and `--release <N>` (or `-source` / `-target`) so the compiler knows the exact release context.
Question 3: What does the following code print? String s = "Hello"; s.concat(" World"); System.out.println(s);
- World
- Hello World
- Compilation error
- Hello (Correct answer)
Correct answer: Hello
Strings are immutable in Java; concat() returns a new String but the original reference 's' is unchanged.
Question 4: How should ethical dilemmas be handled in Arrays and Collections?
- Always choose the cheapest option
- Make decisions based solely on personal preference
- Ignore ethical concerns
- Follow established ethical guidelines, consult with supervisors, and prioritize stakeholder welfare (Correct answer)
Correct answer: Follow established ethical guidelines, consult with supervisors, and prioritize stakeholder welfare
Ethical decision-making requires following professional guidelines and prioritizing the welfare of all stakeholders.
Question 5: Which approach is most effective for problem-solving in Exception Handling?
- Random trial and error
- Systematic analysis followed by evidence-based decision making (Correct answer)
- Ignoring the problem until it resolves itself
- Always asking someone else
Correct answer: Systematic analysis followed by evidence-based decision making
Systematic, evidence-based approaches lead to more reliable solutions than ad hoc methods.
Question 6: What is a JAR file in Java?
- A file used to define Java classes in a specific module
- A documentation file generated by JavaDoc
- A configuration file used to set JVM parameters
- A compressed file format used to bundle multiple Java class files and associated metadata into a single archive (Correct answer)
Correct answer: A compressed file format used to bundle multiple Java class files and associated metadata into a single archive
A JAR (Java Archive) file is a compressed file format, based on the ZIP format, used to bundle multiple Java class files, associated metadata, and resources (like images or configuration files) into a single archive. This makes it convenient for distributing and deploying Java applications and libraries as a single unit.
Question 7: What is the scope of a variable declared inside a method body?
- Local scope (Correct answer)
- Package scope
- Global scope
- Class scope
Correct answer: Local scope
A variable declared inside a method has local scope and is accessible only within that method.
Question 8: Which `Map` method returns the value associated with a key, or a default if the key is absent?
- merge()
- getOrDefault() (Correct answer)
- computeIfAbsent()
- putIfAbsent()
Correct answer: getOrDefault()
`Map.getOrDefault(key, defaultValue)` returns the mapped value or the specified default without modifying the map.
Question 9: Which module directive is used to allow reflective access to all packages in a module by a specific other module?
- opens <package> to <module> (Correct answer)
- exports <package> to <module>
- requires transitive <module>
- provides <service> with <impl>
Correct answer: opens <package> to <module>
The `opens` directive grants reflective access (e.g., for frameworks) while `exports` only grants compile/run-time API access.
Question 10: Which statement about `ArrayList` vs `LinkedList` is accurate?
- ArrayList has O(1) random get by index (Correct answer)
- LinkedList uses less memory per element
- LinkedList has O(1) random access
- ArrayList has O(1) add at middle
Correct answer: ArrayList has O(1) random get by index
ArrayList backed by an array supports O(1) index-based access, while LinkedList requires O(n) traversal to reach an element.
Question 11: What is the most important foundational concept in Arrays and Collections?
- Only following instructions from supervisors
- Ignoring established guidelines
- Memorizing all rules without understanding
- Understanding core principles and their practical application in Arrays and Collections (Correct answer)
Correct answer: Understanding core principles and their practical application in Arrays and Collections
Core principles provide the foundation for all decision-making and practice in Arrays and Collections.
Question 12: Which loop is guaranteed to execute its body at least once?
- do-while loop (Correct answer)
- while loop
- for loop
- enhanced for loop
Correct answer: do-while loop
The `do-while` loop evaluates its condition after executing the body, so it always runs at least once regardless of the condition.
Question 13: How does technology impact modern practices in Arrays and Collections?
- Technology has no impact on this field
- Technology replaces all human judgment
- Technology improves efficiency, accuracy, and access to information while requiring new skills (Correct answer)
- Technology is only useful for record keeping
Correct answer: Technology improves efficiency, accuracy, and access to information while requiring new skills
Technology enhances capabilities while also requiring practitioners to develop new competencies.
Question 14: What is the purpose of the `this` keyword inside an instance method?
- It refers to the current object instance (Correct answer)
- It refers to the parent class
- It calls a superclass constructor
- It refers to a static field
Correct answer: It refers to the current object instance
The `this` keyword refers to the current instance of the class and is used to access its fields and methods.
Question 15: What does the following evaluate to? 10 == 10.0
- Compilation error
- false, int and double are incompatible
- true, after numeric promotion (Correct answer)
- false, types don't match
Correct answer: true, after numeric promotion
Java promotes the int 10 to double 10.0 before comparison, so 10 == 10.0 evaluates to true.
Question 16: What is the output of the following? int a = 10; int b = 3; System.out.println(a % b);
- 1 (Correct answer)
- 0
- 3.33
- 3
Correct answer: 1
The % operator returns the remainder; 10 divided by 3 is 3 with a remainder of 1.
Question 17: How should risk be managed in Arrays and Collections?
- By avoiding all risk entirely
- Through identification, assessment, mitigation strategies, and ongoing monitoring of potential risks (Correct answer)
- Risk management is not necessary
- By ignoring potential problems
Correct answer: Through identification, assessment, mitigation strategies, and ongoing monitoring of potential risks
Effective risk management involves a systematic process of identifying, evaluating, and addressing potential threats.
Question 18: What is the effect of calling `Collections.sort(list, Comparator.reverseOrder())`?
- Sorts list in natural ascending order
- Randomly shuffles the list
- Sorts list in descending order (Correct answer)
- Throws UnsupportedOperationException
Correct answer: Sorts list in descending order
`Comparator.reverseOrder()` produces a comparator that imposes the reverse of the natural ordering, sorting the list in descending order.
Question 19: What does the "javac" command do?
- It compiles Java source code into bytecode (Correct answer)
- It packages Java bytecode into a JAR file
- It starts the Java Virtual Machine (JVM)
- It executes a Java application
Correct answer: It compiles Java source code into bytecode
The `javac` command is the Java compiler. Its primary function is to translate Java source code files (with a `.java` extension) into Java bytecode files (with a `.class` extension). These bytecode files are then executed by the Java Virtual Machine (JVM).
Question 20: What are the key regulatory requirements affecting Object-Oriented Programming?
- Regulations are optional guidelines
- Only federal regulations apply
- There are no regulations
- Compliance with applicable laws, industry standards, and licensing requirements specific to the field (Correct answer)
Correct answer: Compliance with applicable laws, industry standards, and licensing requirements specific to the field
Practitioners must comply with all applicable regulations, which may include federal, state, and industry-specific requirements.
Question 21: What is the primary purpose of standardized procedures in Java Fundamentals?
- To ensure consistency, safety, and quality across all practitioners (Correct answer)
- To slow down work processes
- To benefit only management
- To create unnecessary bureaucracy
Correct answer: To ensure consistency, safety, and quality across all practitioners
Standardized procedures ensure that all practitioners deliver consistent, safe, and high-quality outcomes.
Question 22: In Java, a static nested class differs from an inner class because it:
- Can only be instantiated inside the outer class
- Must be declared public
- Cannot have any methods
- Does not hold an implicit reference to the outer class instance (Correct answer)
Correct answer: Does not hold an implicit reference to the outer class instance
A static nested class has no implicit reference to the enclosing instance, unlike a non-static inner class.
Question 23: Which operator is used for short-circuit logical AND in Java?
- |
- AND
- && (Correct answer)
- &
Correct answer: &&
The `&&` operator performs a short-circuit logical AND, meaning the second operand is not evaluated if the first is false.
Question 24: What happens if a class implements two interfaces that declare the same default method without overriding it?
- Runtime exception on first call
- The method is silently ignored
- The first interface's method is used
- Compilation error due to ambiguity (Correct answer)
Correct answer: Compilation error due to ambiguity
If a class inherits two conflicting default methods and does not override the method, a compile-time error occurs.
Question 25: What is the output of `int i = 0; while(i < 3) { System.out.print(i + " "); i++; }`?
- 0 1 2 (Correct answer)
- 1 2
- 0 1 2 3
- 1 2 3
Correct answer: 0 1 2
The loop prints i (starting at 0) and increments it after each print, running while i < 3, so it outputs 0, 1, and 2.
Question 26: When using `jlink` to create a custom runtime image, which option specifies the modules to include?
- --output
- --module-path
- --add-modules (Correct answer)
- --compress
Correct answer: --add-modules
`--add-modules` tells `jlink` which root modules to include; it then resolves and adds all transitive dependencies automatically.
Question 27: What is the difference between `==` and `.equals()` when comparing String objects in Java?
- Both compare references
- Both compare content
- `==` compares content; `.equals()` compares references
- `==` compares references; `.equals()` compares content (Correct answer)
Correct answer: `==` compares references; `.equals()` compares content
`==` compares object references (memory addresses), while `.equals()` on String compares the actual character content.
Question 28: What is the output of `int x = 5; System.out.println(x++);`?
- 4
- 5 (Correct answer)
- Compilation error
- 6
Correct answer: 5
The post-increment operator `x++` returns the current value of x (5) before incrementing it to 6.
Question 29: Which of the following is true about variable shadowing in Java?
- It only applies to primitive types
- It only occurs with static variables
- It causes a compilation error
- It occurs when a local variable has the same name as an instance variable (Correct answer)
Correct answer: It occurs when a local variable has the same name as an instance variable
Variable shadowing occurs when a local variable or parameter has the same name as an instance variable, hiding the instance variable within that scope.
Question 30: Which of the following is a valid enhanced for loop (for-each) in Java SE 11?
- for(int i : 10) { }
- for(String s : stringArray) { } (Correct answer)
- foreach(String s : list) { }
- for each(String s in list) { }
Correct answer: for(String s : stringArray) { }
The enhanced for loop syntax uses `for(Type variable : iterable)` and works with arrays and any Iterable collection.
Question 31: What is the result of `!true && false` in Java?
- Compilation error
- true
- false (Correct answer)
- null
Correct answer: false
`!true` evaluates to `false`, and `false && false` evaluates to `false` due to short-circuit evaluation.
Question 32: How should risk be managed in Exception Handling?
- By ignoring potential problems
- By avoiding all risk entirely
- Risk management is not necessary
- Through identification, assessment, mitigation strategies, and ongoing monitoring of potential risks (Correct answer)
Correct answer: Through identification, assessment, mitigation strategies, and ongoing monitoring of potential risks
Effective risk management involves a systematic process of identifying, evaluating, and addressing potential threats.
Question 33: What is the return type of `Map.entrySet()`?
- List<Map.Entry<K,V>>
- Set<K, V>
- Collection<Map.Entry<K,V>>
- Set<Map.Entry<K,V>> (Correct answer)
Correct answer: Set<Map.Entry<K,V>>
`Map.entrySet()` returns a `Set<Map.Entry<K,V>>` containing all key-value pair entries in the map.
Question 34: Which of the following correctly declares a varargs parameter in a method?
- public void print(*String args)
- public void print(String... args) (Correct answer)
- public void print(varargs String args)
- public void print(String[] ...args)
Correct answer: public void print(String... args)
Varargs is declared using an ellipsis (`...`) after the type, allowing a method to accept zero or more arguments of that type.
Question 35: Which approach is most effective for problem-solving in Object-Oriented Programming?
- Always asking someone else
- Ignoring the problem until it resolves itself
- Random trial and error
- Systematic analysis followed by evidence-based decision making (Correct answer)
Correct answer: Systematic analysis followed by evidence-based decision making
Systematic, evidence-based approaches lead to more reliable solutions than ad hoc methods.
Question 36: What is the difference between pass-by-value and pass-by-reference in the context of Java method arguments?
- Java uses pass-by-value; for objects, the reference value (address) is passed (Correct answer)
- Java uses pass-by-reference for all types
- Java uses pass-by-reference for objects and pass-by-value for primitives
- Java uses pass-by-value only for String types
Correct answer: Java uses pass-by-value; for objects, the reference value (address) is passed
Java always passes arguments by value; for object types, the value passed is the reference (memory address) of the object, not the object itself.
Question 37: What is the correct syntax for a `switch` statement's default case in Java?
- default: { } (Correct answer)
- otherwise: { }
- else: { }
- case default: { }
Correct answer: default: { }
The `default` keyword in a switch statement defines the block that executes when no other case matches.
Question 38: What does `--patch-module <module>=<path>` allow you to do at runtime?
- Add exports to a module dynamically
- Replace the entire module with a new JAR
- Inject additional classes into a module without recompiling it (Correct answer)
- Increase the memory allocated to a module
Correct answer: Inject additional classes into a module without recompiling it
`--patch-module` overlays classes from a path into a named module, commonly used for testing or hot-patching.
Question 39: Which statement correctly describes labeled `break` in Java?
- It is not supported in Java SE 11
- It breaks out of a method and returns to the caller
- It breaks out of the innermost loop only
- It breaks out of the loop or block associated with the specified label (Correct answer)
Correct answer: It breaks out of the loop or block associated with the specified label
A labeled `break` exits the loop or block that is marked with the corresponding label, allowing breakout from nested loops.
Question 40: What is method chaining in Java?
- Overloading a method more than three times
- Defining methods in a chain of inheritance
- Calling a method from within another method of a different class
- Calling multiple methods sequentially on the same object by returning `this` (Correct answer)
Correct answer: Calling multiple methods sequentially on the same object by returning `this`
Method chaining allows multiple method calls to be linked on the same object when each method returns `this` or another object.
Question 41: What is the result of the expression `10 % 3` in Java?
- 0
- 1 (Correct answer)
- 3.33
- 3
Correct answer: 1
The `%` operator returns the remainder of integer division, so 10 divided by 3 leaves a remainder of 1.
Question 42: Which of these correctly declares a `Set` that preserves insertion order?
- new ArrayDeque<>()
- new TreeSet<>()
- new HashSet<>()
- new LinkedHashSet<>() (Correct answer)
Correct answer: new LinkedHashSet<>()
`LinkedHashSet` maintains insertion order using a doubly-linked list alongside the hash table.
Question 43: What is the result of `"hello".substring(2, 4)`?
- "lo"
- "ll" (Correct answer)
- "llo"
- "ell"
Correct answer: "ll"
`substring(beginIndex, endIndex)` returns characters from index 2 (inclusive) to 4 (exclusive): 'l' and 'l'.
Question 44: What does the compound assignment operator `+=` do?
- Adds two values and stores the result in a new variable
- Concatenates two strings only
- Checks if the left value is greater than the right
- Adds the right operand to the left operand and assigns the result to the left operand (Correct answer)
Correct answer: Adds the right operand to the left operand and assigns the result to the left operand
The `+=` operator adds the right operand to the left operand and stores the result back in the left operand (e.g., `x += 3` is equivalent to `x = x + 3`).
Question 45: What is the value of `x` after executing `int x = 10; x -= 3; x *= 2;`?
- 14 (Correct answer)
- 17
- 13
- 20
Correct answer: 14
After `x -= 3`, x becomes 7; after `x *= 2`, x becomes 14.
Question 46: What is the primary purpose of standardized procedures in Arrays and Collections?
- To slow down work processes
- To create unnecessary bureaucracy
- To benefit only management
- To ensure consistency, safety, and quality across all practitioners (Correct answer)
Correct answer: To ensure consistency, safety, and quality across all practitioners
Standardized procedures ensure that all practitioners deliver consistent, safe, and high-quality outcomes.
Question 47: What is the primary purpose of standardized procedures in Object-Oriented Programming?
- To ensure consistency, safety, and quality across all practitioners (Correct answer)
- To benefit only management
- To slow down work processes
- To create unnecessary bureaucracy
Correct answer: To ensure consistency, safety, and quality across all practitioners
Standardized procedures ensure that all practitioners deliver consistent, safe, and high-quality outcomes.
Question 48: Which statement correctly describes constructor chaining using `this()`?
- `this()` can be used in static methods
- `this()` must be the first statement in the constructor (Correct answer)
- `this()` calls the parent class constructor
- `this()` may appear anywhere in the constructor body
Correct answer: `this()` must be the first statement in the constructor
A `this()` constructor call must appear as the very first statement in the constructor body.
Question 49: What is the importance of communication skills in Exception Handling?
- Communication is only important for managers
- Clear communication prevents errors, builds relationships, and ensures understanding among all parties (Correct answer)
- Technical skills are sufficient without communication
- Communication skills cannot be learned
Correct answer: Clear communication prevents errors, builds relationships, and ensures understanding among all parties
Effective communication is essential for coordination, error prevention, and stakeholder relationships.
Question 50: What is the output of the following? System.out.println("Value: " + 1 + 2);
- Value: 1 2
- Value: 12 (Correct answer)
- Compilation error
- Value: 3
Correct answer: Value: 12
String concatenation is left-to-right: "Value: "+1 gives "Value: 1", then +2 gives "Value: 12".
Question 51: Which control flow statement is used to exit the current iteration of a loop and proceed to the next?
- exit
- break
- return
- continue (Correct answer)
Correct answer: continue
The `continue` statement skips the rest of the current loop iteration and jumps to the loop condition check for the next iteration.
Question 52: What is the rule regarding access modifiers when overriding a method?
- The overriding method can have a more restrictive access modifier
- The overriding method can freely change the access modifier
- The overriding method must have the exact same access modifier
- The overriding method must have the same or broader (less restrictive) access modifier (Correct answer)
Correct answer: The overriding method must have the same or broader (less restrictive) access modifier
An overriding method must have the same or broader (less restrictive) access modifier than the method it overrides.
Question 53: What is the correct way to call a static method `calculate` from the same class `MathUtil`?
- MathUtil.calculate() or just calculate() within the class (Correct answer)
- super.calculate()
- this.calculate()
- new MathUtil().calculate()
Correct answer: MathUtil.calculate() or just calculate() within the class
Static methods are called on the class name (e.g., `MathUtil.calculate()`) or simply by method name within the same class without an object reference.
Question 54: How many classes can a Java class directly extend?
- Unlimited
- Up to two
- Only one (Correct answer)
- Up to three
Correct answer: Only one
Java supports single inheritance for classes, meaning a class can only directly extend one other class.
Question 55: In Java, where can a local variable be declared?
- Only as the first statement in a class
- Only outside of all control flow structures
- Anywhere inside a block where it is needed (Correct answer)
- Only at the beginning of a method body
Correct answer: Anywhere inside a block where it is needed
Local variables in Java can be declared anywhere inside a block, but they must be initialized before use.
Question 56: Which keyword is used to define a method that belongs to the class rather than an instance?
- abstract
- void
- static (Correct answer)
- final
Correct answer: static
The `static` keyword declares a method that belongs to the class itself and can be called without creating an instance.
Question 57: What is the result of `true || false && false` in Java?
- null
- Compilation error
- true (Correct answer)
- false
Correct answer: true
Due to operator precedence, `&&` is evaluated before `||`, so the expression becomes `true || (false && false)` = `true || false` = `true`.
Question 58: When module-info.java contains `uses com.example.Printer;`, what does this indicate?
- The module is a consumer of the Printer service via ServiceLoader (Correct answer)
- The module requires the com.example module
- The module provides an implementation of Printer
- The module exports the Printer interface
Correct answer: The module is a consumer of the Printer service via ServiceLoader
The `uses` directive registers the module as a consumer of a service type, allowing `ServiceLoader` to discover implementations at runtime.
Question 59: What is the significance of documentation in Exception Handling?
- Only required during audits
- Only management needs to document
- It provides a record for accountability, quality assurance, and legal compliance (Correct answer)
- Documentation is unnecessary busy work
Correct answer: It provides a record for accountability, quality assurance, and legal compliance
Proper documentation supports accountability, enables quality review, and satisfies legal requirements.
Question 60: Which of the following method signatures would cause a compilation error due to ambiguity in overloading?
- void test(int a) and void test(int a, int b)
- void test(int a) and int test(int a) (Correct answer)
- void test(int a) and void test(String a)
- void test(int a) and void test(double a)
Correct answer: void test(int a) and int test(int a)
Two methods with the same name and parameter list but different return types are not valid overloads and cause a compilation error.
Oracle Java Foundations (1Z0-811)
The Oracle Java Foundations exam (1Z0-811) validates foundational knowledge of Java programming including core syntax, data types, operators, control flow, object-oriented concepts, arrays, and exception handling. It is the entry-level Oracle Java certification designed for students and beginners new to Java development.
Exam Rules
- You can skip questions and return to them later
- Flag questions for review before submitting
- No feedback shown until you submit the entire exam
- Unanswered questions count as wrong — answer everything
- 10 pretest questions are mixed in and don't affect your score
- Timer auto-submits when time runs out
- Your progress is auto-saved every 30 seconds