Practice 1Z0-811 Java Basics and Syntax questions with full explanations on every answer.
Start practicing
Java Basics and Syntax — choose a session length
Free · No account required
Click any question to see the full explanation and answer options, or start a focused practice session above.
A developer writes the following code: int x = 5; System.out.println(x++); What is the output?
2A team decides to use a single Java source file for a small application. Which statement is true about the file structure?
3Given 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?
4Which primitive data type should be used to store a single character?
5A method is declared as: public static void main(String[] args) { }. Which statement is true?
6What is the value of the expression (10 > 5) && (3 < 2)?
7Which loop construct guarantees that the body executes at least once?
8Given the code: int[] arr = {1,2,3}; for(int x : arr) { if(x==2) continue; System.out.print(x); } What is the output?
9Which access modifier makes a member visible only within its own class?
10What is the result of the expression 10 % 3?
11Which TWO are valid identifiers in Java? (Choose two.)
12Which THREE are valid ways to declare and initialize an integer variable in Java? (Choose three.)
13Which TWO keywords are used for decision-making in Java? (Choose two.)
14What is the output of this program?
15What is the value printed?
16What is the output? ```java public class Test { public static void main(String[] args) { String s1 = "hello"; String s2 = "hello"; System.out.println(s1.equals(s2)); } } ```
17You are developing a Java application for a library management system. The system must track the number of books in each genre. You need to store genre names (String) and their counts (int). The data will be accessed frequently and modified rarely. Which Java data structure should you use to store this mapping efficiently, while ensuring that genre names are unique?
18You are writing a program that processes a list of transactions. Each transaction has a timestamp (long), amount (double), and type (String). The program needs to iterate through the transactions in the order they were added. Which collection should you use to maintain insertion order and allow fast iteration?
19Arrange the steps to declare and initialize a one-dimensional array in Java in the correct order.
20Arrange the steps to use the Scanner class to read user input in Java in the correct order.
21Match each access modifier to its visibility level.
22Match each Java collection interface to its characteristics.
23A developer writes code to calculate the average of two integers: int a = 5; int b = 10; int avg = a / b;. Which change ensures the average is correctly calculated as a double?
24A class defines a static variable initialized at declaration: static int count = 10;. A static method attempts to modify it: count = 20;. Which statement is true?
25A developer uses a switch statement with a String variable. Which is true about this usage?
26Which loop construct guarantees that the loop body executes at least once?
27A method receives an int parameter and modifies its value inside the method. Does this change affect the caller's argument?
28Given int[] arr = {1,2,3}; which correctly creates a new array with length 5 and copies the contents of arr?
29A class defines two methods with the same name but different parameter lists. This is known as:
30Which access modifier allows members to be accessed only by classes in the same package?
31A subclass overrides a method from its superclass. Which annotation should be used to indicate the overriding intention?
32Which TWO are valid Java identifiers? (Choose two.)
33Which TWO statements about constructors are true? (Choose two.)
34Which THREE are primitive data types in Java? (Choose three.)
35Refer to the exhibit. What is the output?
36Refer to the exhibit. What is the result of attempting to compile and run the code?
37Refer to the exhibit. What is the output?
38A developer writes: int x; System.out.println(x); What is the result?
39Given: String s = "Java"; s.concat(" Rocks"); System.out.println(s); What prints?
40What is the result of: int[] arr = new int[5]; System.out.println(arr[5]);
41Given: int day = 3; switch(day) { case 1: System.out.print("A"); case 2: System.out.print("B"); case 3: System.out.print("C"); case 4: System.out.print("D"); } What prints?
42Given methods: void print(Integer i) { System.out.println("Integer"); } void print(int i) { System.out.println("int"); } What is output of print(10);?
43Which assignment requires an explicit cast to compile?
44Consider: for(int i=0;i<10;i++) { int x = i; } System.out.println(x); What is the result?
45Given method: static void change(String s) { s = "new"; } What is output of: String name = "original"; change(name); System.out.println(name);
46What is the result of: Integer a = null; int b = (a != null) ? a : 0; System.out.println(b);
47Which TWO of the following are valid Java identifiers?
48Which TWO of the following are legal ways to declare and initialize an array?
49Which THREE of the following are primitive data types in Java?
50Refer to the exhibit. What is the likely cause of this error?
51Refer to the exhibit. What happens when you compile this code?
52Refer to the exhibit. What is the output?
53A method is expected to receive an integer and return its square. Which method signature is correct?
54A class has a static variable counter initialized to 0. Two threads increment counter 1000 times each using counter++. What is a possible final value of counter?
55Which is the correct way to declare an array of integers in Java?
56A developer writes: if (x = 5) { System.out.println("x is 5"); } What is the result?
57Which TWO statements are true about the main method?
58Which THREE of the following are primitive data types in Java?
59Which TWO are valid ways to create a String object?
60Refer to the exhibit. What is the output?
61Refer to the exhibit. What is the most likely cause?
62Given the following code: class A { A() { System.out.print("A "); } } class B extends A { B() { System.out.print("B "); } } class C extends B { C() { System.out.print("C"); } public static void main(String[] args) { new C(); } } What is the output when running the main method?
63A developer writes the following code to compare two strings: String s1 = "Java"; String s2 = new String("Java"); if (s1 == s2) { System.out.println("Equal"); } else { System.out.println("Not equal"); } What is the output?
64A package named com.example.util is declared in a file. Where should the file be placed in the directory structure?
65A developer uses the following array initialization: int[] nums = new int[]{1, 2, 3}; Which of the following is true?
66A method is declared as: public void setAge(int age) { this.age = age; } Which statement is correct about this code assuming the class has an instance variable age?
67A developer writes the following code: int x = 5; int y = x++; What are the values of x and y after execution?
68A company requires a method that accepts an integer and returns true if the integer is even, otherwise false. Which implementation best follows Java conventions?
69Given the loop: for (int i=0; i<5; i++) { if (i==2) continue; System.out.print(i); } What is the output?
70Which data type should be used to store a single character like 'A'?
71What is the result of the following code? String s1 = "Hello"; String s2 = " World"; String s3 = s1 + s2; System.out.println(s3);
72Given: int[] arr = {10,20,30}; System.out.println(arr[3]); What is the result?
73Which method overloading is valid?
74What is the scope of a variable declared inside a for loop?
75Which statement about try-catch is true?
76Which TWO keywords are used to control access to class members? (Choose two.)
77Which THREE are primitive data types in Java? (Choose three.)
78The code does not compile. What is the error?
79What likely caused this compilation error?
80A developer is working on a Java application that processes user input. The application reads an integer from the command line using args[0], converts it to an int, and uses it in a loop. When testing, the application throws a NumberFormatException when the user provides an alphabetic string. The developer needs to handle this exception gracefully by prompting the user to enter a valid number and retrying. However, the developer must avoid infinite loops. The current code uses a while loop with a flag. Which approach ensures the code handles the exception, provides feedback, and terminates if the user enters 'quit'? The environment is a standard Java SE 11 application. The developer wants a robust solution without using external libraries.
81A developer declares an integer variable inside a method but does not assign a value. What is the result of attempting to print the variable?
82Given two String objects s1 = "Hello" and s2 = "Hello", what does the expression (s1 == s2) return?
83A developer writes: int x = 5; int y = x++ + ++x; What is the value of y after execution?
84A developer wants to iterate over an array of integers named 'numbers'. Which loop declaration will correctly access each element?
85A parent class has a static method display() and an instance method show(). A child class attempts to override both. What is the outcome?
86Which THREE are valid ways to declare and initialize a two-dimensional int array in Java?
87Which THREE are valid Java identifiers?
88Which THREE statements about the final keyword in Java are true?
89A financial trading application processes high-volume transactions. The system uses a multithreaded architecture where multiple threads update a shared Account object's balance field. Recently, intermittently incorrect balance calculations have been reported. Developers suspect a race condition on the balance field. The Account class is defined as follows: public class Account { private double balance = 0.0; public void deposit(double amount) { balance += amount; } public void withdraw(double amount) { balance -= amount; } public double getBalance() { return balance; } } Threads are created using ExecutorService with a fixed thread pool. The issue occurs only under heavy load. Which course of action should the development team take to resolve the issue while maintaining performance?
90A junior developer wrote the following code to calculate the sum of an array: int[] numbers = {1, 2, 3, 4, 5}; int sum = 0; for (int i = 1; i <= numbers.length; i++) { sum += numbers[i]; } System.out.println("Sum: " + sum); The developer expects the output to be 15, but the program throws an exception. What is the root cause and the correct fix?
91A team is developing a library management system. They have a base class 'Item' with a method 'getTitle()' that returns the title. They also have a subclass 'Book' that overrides 'getTitle()'. In some places, they have a method that accepts an Item reference but actually receives a Book object. They want to call a method specific to Book, such as 'getISBN()', that is not in Item. They attempt to cast the parameter: ((Book) item).getISBN(). However, occasionally the program crashes with ClassCastException. What is the best practice to avoid this exception?
92A web application uses a HashMap to cache user session data. The keys are String objects representing session IDs, and values are Session objects. After some time, the cache memory usage grows excessively, causing OutOfMemoryError. The cache is never cleared. The team decides to implement a cache eviction policy. Which approach is best suited for this scenario in terms of Java standard library?
93A mobile app backend uses Java streams to process user data. The code snippet filters users who are active and older than 18, then collects them into a list: List<User> result = users.stream() .filter(u -> u.isActive()) .filter(u -> u.getAge() > 18) .collect(Collectors.toList()); Performance metrics show that this stream operation is slow when the user list has millions of entries. The team wants to improve performance without changing the business logic. Which change would most likely improve performance?
94A developer is writing a program to find the maximum value in an array of integers. The code is: int[] nums = {10, 20, 5, 30, 15}; int max = 0; for (int i = 0; i < nums.length; i++) { if (nums[i] > max) { max = nums[i]; } } System.out.println(max); The output is 30, which is correct for this array. However, the developer is concerned that if all numbers are negative, the output would be 0 instead of the highest negative number. Which modification ensures the algorithm works correctly for all integer arrays?
95Which TWO of the following are valid Java identifiers? (Choose two.)
96What is the result of compiling and running this code?
Deep-dive questions
The most-searched questions in this domain — detailed explanations, worked examples, full answer breakdowns.
The Java Basics and Syntax domain covers the key concepts tested in this area of the 1Z0-811 exam blueprint published by Oracle. Courseiva provides free domain-focused practice, mock exams, missed-question review, and readiness tracking across all 1Z0-811 domains — no account required.
The Courseiva 1Z0-811 question bank contains 96 questions in the Java Basics and Syntax domain, covering the 15% of the exam attributed to this domain in the official Oracle blueprint. Click any question to see the full explanation and answer breakdown.
Start with a 10-question focused session to identify your baseline accuracy in this domain. Read every explanation — even for questions you answer correctly — to understand the reasoning. Once you score consistently above 80%, move to a 20–30 question session to confirm depth before moving to the next domain.
Yes — the session launcher on this page draws questions exclusively from the Java Basics and Syntax domain. Choose 10, 20, 30, or 50 questions for a focused session, or click individual questions to review them one by one.
Save your results, see per-domain analytics, and get readiness scores — free, for every certification.
Sign Up FreeFree forever · Every certification included