Oracle · Free Practice Questions · Last reviewed May 2026
42real exam-style questions organised by domain, each with the correct answer highlighted and a plain-English explanation of why it's right — and why the others are wrong.
A developer is writing a Java application that processes a large number of transactions. The application must ensure that each transaction is committed only if all steps complete successfully, otherwise the entire transaction should be rolled back. Which Java concept should the developer use to implement this requirement?
Exception handling
Exception handling can catch failures and trigger rollback.
Inheritance
Multithreading
Encapsulation
A team is designing a Java application that needs to run on different operating systems without modification. Which Java feature makes this possible?
The Java Virtual Machine
JVM interprets bytecode on any platform, providing portability.
Just-in-time compilation
Garbage collection
The Java compiler
Which TWO statements correctly describe the Java language? (Choose two.)
Java supports multiple inheritance of implementation.
Java supports operator overloading.
Java supports object-oriented programming.
Java is primarily object-oriented.
Java supports multiple inheritance of classes.
Java is a statically typed language.
Variables must be declared with a type before use.
A developer runs the command shown in the exhibit. The developer wants to ensure the application uses the latest available language features. Which action should the developer take?
Download and install a newer version of the JDK.
A newer JDK includes both compiler and runtime with latest features.
Enable lambda expressions by setting the -enable-lambdas flag.
Use the -source and -target flags to compile for a newer version.
Upgrade the JVM to the latest version.
A company is developing a Java-based inventory management system. The system runs on a single server and processes up to 1000 concurrent requests. The development team has implemented the code using multiple threads to handle requests. Recently, the system has been experiencing intermittent data corruption in the inventory counts. After reviewing the code, the team suspects that the issue is related to thread safety. The team is considering the following solutions: (A) Use the 'synchronized' keyword on all methods that update inventory counts. (B) Use 'volatile' keyword on the inventory count variables. (C) Use 'AtomicInteger' for inventory counts. (D) Increase the number of threads to handle requests faster. Which solution should the team implement to fix the data corruption issue with minimal performance impact?
Use 'AtomicInteger' for inventory counts.
AtomicInteger provides lock-free, thread-safe operations with good performance.
Increase the number of threads to handle requests faster.
Use 'volatile' keyword on the inventory count variables.
Use the 'synchronized' keyword on all methods that update inventory counts.
Arrange the steps to compile and run a Java program from the command line in the correct order.
Want more What is Java practice?
Practice this domainA developer writes the following code: int x = 5; System.out.println(x++); What is the output?
Compilation error
5
x++ returns 5, then x becomes 6.
6
Runtime exception
A team decides to use a single Java source file for a small application. Which statement is true about the file structure?
It must have a main method to compile.
It can contain multiple public classes.
It can contain exactly one public class with the same name as the file.
This is the standard rule.
The public class name can differ from the file name.
Given the code: String s1 = "Java"; String s2 = new String("Java"); if (s1 == s2) { System.out.print("Equal"); } else { System.out.print("Not Equal"); } What is the output?
Runtime error
Compilation error
Equal
Not Equal
s1 is interned, s2 is a new object.
Which primitive data type should be used to store a single character?
int
byte
char
char is a 16-bit Unicode character.
String
A method is declared as: public static void main(String[] args) { }. Which statement is true?
The method can be overridden in a subclass.
The method can return an int.
The method can be called without creating an instance of the class.
It is static, so it belongs to the class.
The method can be private.
Which code snippet correctly creates a two-dimensional array with 3 rows and 4 columns?
int[][] array = new int[3,4];
int[] array[] = new int[3][4];
int array[][] = new int[3,4];
int[][] array = new int[3][4];
Correct syntax.
Want more Java Basics and Syntax practice?
Practice this domainGiven the code snippet: int x = 5; int y = 2; double result = x / y; What is the value of result?
2.0
Correct because integer division yields 2, then cast to double.
Compilation fails
2.5
2
A developer writes: String s = "Hello"; s.concat(" World"); System.out.println(s); What is the output?
Compilation fails
Hello World
Hello
Correct because concat does not modify s.
Hello World
Given: String str = "Java"; str = str.concat(" SE"); str.replace('a', 'A'); System.out.println(str); What is the output?
Java
JAVA SE
Java SE
Correct because replace result is ignored.
JAvA SE
Which operator is used to compare two strings for value equality in Java?
compareTo()
=
==
equals()
Correct for value equality.
What is the result of: System.out.println(10 + 20 + "30");
102030
3030
Correct because addition then concatenation.
30
Compilation fails
Given: boolean a = false; boolean b = true; boolean c = true; System.out.println(a || b && c); What is the output?
false
Compilation fails
None of the above
true
Correct due to operator precedence.
Want more Primitives, Strings and Operators practice?
Practice this domainA developer writes a loop to iterate over an array of integers. The loop must sum all elements and stop early if the sum exceeds 100. Which control flow construct should be used?
while(true) { sum += arr[i]; i++; }
for(int i=0; i<arr.length; i++) { sum += arr[i]; if(sum > 100) break; }
Correctly uses for loop and break to exit early.
do { sum += arr[i]; i++; } while(i<arr.length && sum <= 100);
for(int val : arr) { sum += val; if(sum > 100) break; }
Which loop is guaranteed to execute its body at least once?
repeat-until loop
while loop
do-while loop
Executes body then checks condition.
for loop
A developer needs to implement a menu-driven program that repeatedly displays options, reads input, and processes the choice until the user selects 'Exit'. Which loop structure and control flow is most appropriate?
for loop with break condition and nested if-else
for(;;) loop with if-else chain
do-while loop with switch statement
Ensures menu displays once, switch is clear for multiple options.
while(true) loop with if-else chain
What is the output of the following code?
int i = 0;
while (i < 5) {
if (i == 3) {i++; continue;
}
System.out.print(i + " "); i++;
}
0 1 2 4
Correctly skips 3 due to continue.
0 1 2 3
0 1 2 4 5
0 1 2 3 4
Which statement about the for-each loop in Java is true?
It cannot remove elements from a collection during iteration without additional logic.
Correct: removal causes ConcurrentModificationException.
It can modify the array elements.
It can iterate in reverse order.
It cannot be used with arrays.
A developer writes: for(int i=0; i<10; i++) { if(i%2==0) continue; System.out.print(i); }. What is the output?
0123456789
13579
Correctly prints odd numbers.
02468
123456789
Want more Control Flow and Loops practice?
Practice this domainA developer writes a method that takes an int array and returns the sum of its elements. The method signature is: 'public static int sumArray(int[] arr)'. Which statement correctly calls this method?
int result = sumArray(new int[]{1,2,3});
Creates and passes an anonymous int array.
int result = sumArray(true);
int result = sumArray([1,2,3]);
int result = sumArray(5);
Given the code snippet: 'int[] nums = {10, 20, 30, 40}; int sum = 0; for (int i = 0; i < nums.length; i++) { sum += nums[i]; }'. What is the value of sum after execution?
100
Sums all four elements correctly.
30
60
140
A method 'public static void modifyArray(int[] arr) { arr[0] = 99; }' is called with 'int[] myArray = {1,2,3}; modifyArray(myArray); System.out.println(myArray[0]);'. What is the output?
99
The method modifies the array element.
1
0
Compilation error
Which of the following correctly declares and initializes an array of strings with the elements "A", "B", and "C"?
String[] arr = new String[] {"A", "B", "C"};
String[] arr = ("A", "B", "C");
String[] arr = ["A", "B", "C"];
String[] arr = {"A", "B", "C"};
Correct shorthand initialization.
A method 'public static int findMax(int[] numbers)' returns the maximum value in the array. Which implementation correctly handles an empty array by returning 0?
int max = 0; for(int n: numbers) if(n > max) max = n; return max;
int max = numbers[0]; for(int i=1; i<numbers.length; i++) if(numbers[i] > max) max = numbers[i]; return max;
if(numbers.length == 0) return 0; int max = 0; for(int n: numbers) if(n > max) max = n; return max;
if(numbers.length == 0) return 0; int max = numbers[0]; for(int i=1; i<numbers.length; i++) if(numbers[i] > max) max = numbers[i]; return max;
Correctly handles empty and non-empty arrays.
Given the method: 'public static void swapFirstTwo(int[] arr) { int temp = arr[0]; arr[0] = arr[1]; arr[1] = temp; }'. What is the effect of calling this method with an array of length 1?
An ArrayIndexOutOfBoundsException is thrown.
Index 1 is out of bounds for length 1.
The first element is swapped with itself.
A new array with length 2 is returned.
The array remains unchanged.
Want more Arrays and Methods practice?
Practice this domainA developer writes a class 'Vehicle' with a method 'move()' that prints 'Vehicle moves'. A subclass 'Car' overrides 'move()' to print 'Car moves'. Given: Vehicle v = new Car(); v.move(); What is the output?
Vehicle moves
Runtime exception
Compilation fails
Car moves
Correct due to polymorphism; the overridden method in Car is called.
In a banking application, a class 'Account' has a private field 'balance'. Which is the best way to allow subclasses to read but not directly modify 'balance'?
Make balance public
Provide a public getBalance() method
Getter provides read-only access; keep field private.
Use a static variable
Make balance protected
A class 'Base' has a method 'public void display() throws IOException'. Subclass 'Derived' overrides display(). Which exception specifications are allowed in the overriding method?
public void display() throws SQLException
public void display() throws FileNotFoundException
FileNotFoundException is a subclass of IOException, allowed.
public void display() throws Exception
public void display() throws Throwable
Which design principle is violated by making all fields public in a class?
Inheritance
Abstraction
Encapsulation
Encapsulation hides internal data; public fields expose it.
Polymorphism
Given: abstract class Shape { abstract void draw(); } class Circle extends Shape { void draw() {} } Which is true?
Shape cannot have a constructor
Circle must override draw()
Circle provides implementation; it compiles fine.
Shape s = new Shape(); is valid
draw() must be public in Circle
Which is the correct way to call a superclass constructor from a subclass constructor?
super(); anywhere
super(); as first statement
Correct syntax and position.
super(); at the end
this.super();
Want more Object-Oriented Programming practice?
Practice this domainA developer writes a method that reads a file and processes its contents. If the file does not exist, the method should notify the caller. Which exception should the method declare in its throws clause?
RuntimeException
FileNotFoundException
FileNotFoundException is a checked exception specifically for missing files.
Exception
IOException
A team is developing a Java application that uses many third-party libraries. One library throws a checked exception that is not declared in its method signature. Which approach best handles this situation?
Ignore the exception because it is not declared.
Declare the library's exception in the method signature.
Wrap the exception in a RuntimeException and throw it.
This satisfies the compiler and preserves the exception chain.
Catch the exception and log it, then continue execution.
Which of the following is the best practice for resource management in Java?
Close resources in a finally block without null checks.
Rely on garbage collection to close resources.
Use try-with-resources statement.
Try-with-resources automatically closes AutoCloseable resources.
Use a try-catch block and close resources in the catch block.
A developer encounters an ArrayIndexOutOfBoundsException while running a unit test. The stack trace shows the error occurs in a method that is called from many places. Which tool or technique would most efficiently identify the specific call path?
Review the code manually to trace all possible callers.
Set a breakpoint in the method and debug the test.
Debugging allows inspection of the call stack and variables.
Run a static analysis tool to detect the issue.
Add log statements at the beginning of the method.
Which statement about the Java compiler is true?
It translates Java source code into native machine code.
It produces executable files that run directly on the OS.
It executes Java programs.
It translates Java source code into bytecode.
javac produces .class files containing bytecode.
A method throws a checked exception. Which of the following is the correct way to handle it in the calling method?
Ignore the exception since it is checked.
Add a throws clause to the calling method.
Enclose the call in a try-catch block.
Catching the exception handles it.
Use a finally block without catch.
Want more Exception Handling and Development Tools practice?
Practice this domainThe 1Z0-811 exam has 75 questions and must be completed in 75 minutes. The passing score is 650/1000.
Scenario-based questions covering exam objectives with detailed answer explanations.
The exam covers 7 domains: What is Java, Java Basics and Syntax, Primitives, Strings and Operators, Control Flow and Loops, Arrays and Methods, Object-Oriented Programming, Exception Handling and Development Tools. Questions are weighted by domain — higher-weight domains appear more on your actual exam.
No. These are original exam-style practice questions written against the official Oracle 1Z0-811 exam objectives. They are not copied from the real exam. Courseiva focuses on genuine understanding, not memorisation of braindumps.
Courseiva tracks your accuracy per domain and routes you toward weak areas automatically. Free, no account required.