1Z0-811 · domain
Java Basics and Syntax
Practise Oracle Java Foundations 1Z0-811 Java Basics and Syntax practice questions — original exam-style scenarios with answer choices, explanations, and analysis of common mistakes.
Focused practice
Practice Java Basics and Syntax questions
Scored sessions drawing only from this domain — pick a length below.
Start 20-question practice test →What this domain covers
What to know about Java Basics and Syntax
Java Basics and Syntax questions test whether you can apply the concept in context, not just recognise a definition.
How the topic appears in realistic exam-style scenarios.
Which detail in the question changes the correct answer.
How to eliminate plausible but wrong options.
How to connect the question back to the wider exam objective.
Watch out for
Common Java Basics and Syntax exam traps
- ▸Answering from memory before reading the full scenario.
- ▸Missing a constraint such as cost, availability, security, scope or command context.
- ▸Choosing a broad answer when the question asks for the most specific fix.
- ▸Ignoring why the wrong options are tempting.
Question index
All Java Basics and Syntax questions (96)
Click any question to see the full explanation, or start a practice session above.
A 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?
Medium2Which method overloading is valid?
Easy3A developer uses the following array initialization: int[] nums = new int[]{1, 2, 3}; Which of the following is true?
Hard4Arrange the steps to use the Scanner class to read user input in Java in the correct order.
Medium5Given the loop: for (int i=0; i<5; i++) { if (i==2) continue; System.out.print(i); } What is the output?
Hard6Given method: static void change(String s) { s = "new"; } What is output of: String name = "original"; change(name); System.out.println(name);
Hard7Which TWO of the following are valid Java identifiers?
Easy8Arrange the steps to declare and initialize a one-dimensional array in Java in the correct order.
Medium9What is the result of the expression 10 % 3?
Easy10Which statement about try-catch is true?
Hard11What is the output of this program?
Medium12Which TWO keywords are used for decision-making in Java? (Choose two.)
Easy13A subclass overrides a method from its superclass. Which annotation should be used to indicate the overriding intention?
Hard14A team decides to use a single Java source file for a small application. Which statement is true about the file structure?
Medium15Which TWO are valid Java identifiers? (Choose two.)
Easy16Which TWO statements about constructors are true? (Choose two.)
Medium17Which assignment requires an explicit cast to compile?
Medium18A 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?
Hard19What is the result of compiling and running this code?
Medium20Which TWO are valid ways to create a String object?
Easy21Refer to the exhibit. What is the output?
Easy22Which THREE are primitive data types in Java? (Choose three.)
Easy23A 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?
Easy24A method receives an int parameter and modifies its value inside the method. Does this change affect the caller's argument?
Medium25Which access modifier allows members to be accessed only by classes in the same package?
Medium26Which TWO of the following are valid Java identifiers? (Choose two.)
Easy27Refer to the exhibit. What is the likely cause of this error?
Easy28Which THREE are valid ways to declare and initialize an integer variable in Java? (Choose three.)
Hard29Given two String objects s1 = "Hello" and s2 = "Hello", what does the expression (s1 == s2) return?
Medium30Which is the correct way to declare an array of integers in Java?
Easy31Which THREE of the following are primitive data types in Java?
Hard32Which loop construct guarantees that the body executes at least once?
Medium33A method is declared as: public static void main(String[] args) { }. Which statement is true?
Medium34Which TWO of the following are legal ways to declare and initialize an array?
Medium35Which TWO statements are true about the main method?
Medium36A developer declares an integer variable inside a method but does not assign a value. What is the result of attempting to print the variable?
Easy37A 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?
Easy38Which access modifier makes a member visible only within its own class?
Medium39Given: String s = "Java"; s.concat(" Rocks"); System.out.println(s); What prints?
Easy40A 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?
Medium41The code does not compile. What is the error?
Medium42A method is expected to receive an integer and return its square. Which method signature is correct?
Easy43Given: 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?
Medium44You 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?
Hard45A 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?
Easy46A 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?
Medium47A class defines two methods with the same name but different parameter lists. This is known as:
Easy48A 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?
Hard49A 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?
Hard50A 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?
Medium51Given methods: void print(Integer i) { System.out.println("Integer"); } void print(int i) { System.out.println("int"); } What is output of print(10);?
Medium52Which THREE are valid Java identifiers?
Easy53Refer to the exhibit. What is the result of attempting to compile and run the code?
Medium54Consider: for(int i=0;i<10;i++) { int x = i; } System.out.println(x); What is the result?
Hard55A package named com.example.util is declared in a file. Where should the file be placed in the directory structure?
Easy56A parent class has a static method display() and an instance method show(). A child class attempts to override both. What is the outcome?
Hard57Given 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?
Hard58Which loop construct guarantees that the loop body executes at least once?
Easy59Given: int[] arr = {10,20,30}; System.out.println(arr[3]); What is the result?
Hard60A developer wants to iterate over an array of integers named 'numbers'. Which loop declaration will correctly access each element?
Easy61Which THREE statements about the final keyword in Java are true?
Hard62A developer writes the following code: int x = 5; int y = x++; What are the values of x and y after execution?
Easy63Refer to the exhibit. What is the output?
Easy64Which THREE are valid ways to declare and initialize a two-dimensional int array in Java?
Medium65Refer to the exhibit. What is the output?
Hard66What likely caused this compilation error?
Hard67Match each Java collection interface to its characteristics.
Medium68A company requires a method that accepts an integer and returns true if the integer is even, otherwise false. Which implementation best follows Java conventions?
Medium69Which THREE of the following are primitive data types in Java?
Hard70Refer to the exhibit. What happens when you compile this code?
Medium71What is the value printed?
Hard72Refer to the exhibit. What is the most likely cause?
Medium73A 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?
Hard74Which TWO are valid identifiers in Java? (Choose two.)
Medium75Match each access modifier to its visibility level.
Medium76Refer to the exhibit. What is the output?
Hard77Which primitive data type should be used to store a single character?
Easy78You 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?
Medium79Given 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?
Hard80What is the result of: Integer a = null; int b = (a != null) ? a : 0; System.out.println(b);
Hard81A developer writes: int x = 5; int y = x++ + ++x; What is the value of y after execution?
Hard82A developer writes: if (x = 5) { System.out.println("x is 5"); } What is the result?
Medium83Which TWO keywords are used to control access to class members? (Choose two.)
Medium84What is the result of: int[] arr = new int[5]; System.out.println(arr[5]);
Easy85Which data type should be used to store a single character like 'A'?
Easy86A 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.
Hard87Given the code: int[] arr = {1,2,3}; for(int x : arr) { if(x==2) continue; System.out.print(x); } What is the output?
Hard88Which THREE are primitive data types in Java? (Choose three.)
Hard89A developer writes the following code: int x = 5; System.out.println(x++); What is the output?
Easy90What is the result of the following code? String s1 = "Hello"; String s2 = " World"; String s3 = s1 + s2; System.out.println(s3);
Medium91Given int[] arr = {1,2,3}; which correctly creates a new array with length 5 and copies the contents of arr?
Hard92What is the scope of a variable declared inside a for loop?
Medium93What 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)); } } ```
Easy94What is the value of the expression (10 > 5) && (3 < 2)?
Easy95A developer writes: int x; System.out.println(x); What is the result?
Easy96A developer uses a switch statement with a String variable. Which is true about this usage?
HardOther domains
All 1Z0-811 exam domains
Frequently asked questions
- What does the Java Basics and Syntax domain cover on the 1Z0-811 exam?
- Java Basics and Syntax questions test whether you can apply the concept in context, not just recognise a definition.
- How many questions are in this domain?
- This page lists all 96 Java Basics and Syntax questions in the 1Z0-811 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
- What is the best way to practise this domain?
- Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
- Can I practise only Java Basics and Syntax questions?
- Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.