You must read short Java snippets and state output, identify compile errors, choose correct primitive declarations, and place packaged classes correctly. The single most important thing: know that do-while executes its body before checking the condition, while for and while check first.
Start practicing
Java Basics and Syntax — choose a session length
Free · No account required
Domain overview
This domain covers the foundational syntax every Java program depends on: primitive types, variables, operators, expressions, String handling, control flow with if/else, switch, and the for, while, and do-while loops, plus package declarations and imports. Questions are short code-reading items where you predict output, spot compile errors, or choose correct declarations.
Exam objectives
Identifying Java's eight primitive types: boolean, byte, short, int, long, char, float, double
Reading String code and predicting results of equals, ==, concatenation, and length
Tracing control flow through if, switch, for, while, and do-while loops
Placing a class in the directory matching its package declaration, such as com/example/util
Confusing String == reference comparison with equals content comparison; == on two identical literals is true due to interning, but on new String objects is false
Assuming a while loop always runs at least once; only do-while guarantees one execution before testing its condition
Declaring a file in the wrong directory for its package, or forgetting that package names map directly to nested folders
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?
9What is the result of the expression 10 % 3?
10Which TWO are valid identifiers in Java? (Choose two.)
11Which THREE are valid ways to declare and initialize an integer variable in Java? (Choose three.)
12Which TWO keywords are used for decision-making in Java? (Choose two.)
13Which FOUR statements about the main method are correct? (Choose four.)
14What 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)); } } ```
15You 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?
16You 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?
17Arrange the steps to declare and initialize a one-dimensional array in Java in the correct order.
18Arrange the steps to use the Scanner class to read user input in Java in the correct order.
19Match each access modifier to its visibility level.
20Match each Java collection interface to its characteristics.
21A 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?
22A developer uses a switch statement with a String variable. Which is true about this usage?
23Which loop construct guarantees that the loop body executes at least once?
24A method receives an int parameter and modifies its value inside the method. Does this change affect the caller's argument?
25Given int[] arr = {1,2,3}; which correctly creates a new array with length 5 and copies the contents of arr?
26A class defines two methods with the same name but different parameter lists. This is known as:
27Which access modifier allows members to be accessed only by classes in the same package?
28A subclass overrides a method from its superclass. Which annotation should be used to indicate the overriding intention?
29Which TWO are valid Java identifiers? (Choose two.)
30Which TWO statements about constructors are true? (Choose two.)
31Which THREE are primitive data types in Java? (Choose three.)
32Refer to the exhibit. What is the output?
33A developer writes: int x; System.out.println(x); What is the result?
34Given: String s = "Java"; s.concat(" Rocks"); System.out.println(s); What prints?
35What is the result of: int[] arr = new int[5]; System.out.println(arr[5]);
36Given: 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?
37Given methods: void print(Integer i) { System.out.println("Integer"); } void print(int i) { System.out.println("int"); } What is output of print(10);?
38Consider: for(int i=0;i<10;i++) { int x = i; } System.out.println(x); What is the result?
39Given method: static void change(String s) { s = "new"; } What is output of: String name = "original"; change(name); System.out.println(name);
40What is the result of: Integer a = null; int b = (a != null) ? a : 0; System.out.println(b);
41Which TWO of the following are valid Java identifiers?
42Which THREE of the following are primitive data types in Java?
43Refer to the exhibit. What is the likely cause of this error?
44A method is expected to receive an integer and return its square. Which method signature is correct?
45A developer writes: if (x = 5) { System.out.println("x is 5"); } What is the result?
46Which TWO statements are true about the main method?
47Which TWO are valid ways to create a String object?
48Given 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?
49A 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?
50A package named com.example.util is declared in a file. Where should the file be placed in the directory structure?
51A developer uses the following array initialization: int[] nums = new int[]{1, 2, 3}; Which of the following is true?
52A 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?
53A developer writes the following code: int x = 5; int y = x++; What are the values of x and y after execution?
54Which data type should be used to store a single character like 'A'?
55Given: int[] arr = {10,20,30}; System.out.println(arr[3]); What is the result?
56Which method overloading is valid?
57What is the scope of a variable declared inside a for loop?
58Which TWO keywords are used to control access to class members? (Choose two.)
59Which THREE are valid Java identifiers? (Choose three.)
60What likely caused this compilation error?
61A 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.
62A developer declares an integer variable inside a method but does not assign a value. What is the result of attempting to print the variable?
63Given two String objects s1 = "Hello" and s2 = "Hello", what does the expression (s1 == s2) return?
64A developer writes: int x = 5; int y = x++ + ++x; What is the value of y after execution?
65A developer wants to iterate over an array of integers named 'numbers'. Which loop declaration will correctly access each element?
66A class has two methods: void setValue(int a) and void setValue(double a). Which call will result in a compilation error?
67A parent class has a static method display() and an instance method show(). A child class attempts to override both. What is the outcome?
68Which THREE are valid Java identifiers?
69Which THREE statements about the final keyword in Java are true?
70A 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?
71A 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?
72A 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?
73Which TWO of the following are valid Java identifiers? (Choose two.)
74A developer is writing a Java program that needs to store the number of items in a shopping cart. The value will never be negative and will never exceed 2 billion. Which primitive type is most appropriate for this variable?
75A junior developer is reviewing a Java source file and sees the following declaration at the top of the file: package com.acme.util; Which statement correctly describes the requirement for this declaration?
76A developer is writing a method that calculates the average of two integers and wants the result to include fractional values. The method signature is: public static double average(int a, int b) Which return statement produces the intended result?
77A junior developer is writing a Java class to model a bank account. The class needs a field that stores the current balance as a decimal value with high precision, and the field should be accessible only within that same class. Which declaration best meets these requirements?
78A developer is reviewing loop constructs in a Java utility class. Which TWO statements about Java loop behavior are correct? (Choose two.)
79A developer writes a loop that should print the integers 0 through 4 inclusive. The code is: for (int i = 0; i < 5; i++) { System.out.print(i + " "); } Which statement accurately describes the output and the loop's behavior?
80A junior developer writes the following code snippet: int x = 10; if (x = 5) { System.out.println("Equal"); } else { System.out.println("Not Equal"); } What happens when this code is compiled and run?
81A developer writes a class with a static field and an instance field: public class Counter { static int total = 0; int count = 0; void increment() { total++; count++; System.out.println(total + " " + count); } } In main, two Counter objects c1 and c2 are created. c1.increment() is called, then c2.increment(). What is printed?
82A developer needs to store whether a customer has opted in to marketing emails. The value will be either true or false, and the field will later be compared inside conditional statements. Which declaration is most appropriate for this field?
83A developer needs to store the number of active users in a web application. The value will be a whole number and will never exceed 2 billion. Which primitive data type is most appropriate for this purpose?
84A developer writes the following code: int x = 7; int y = 2; double result = x / y; System.out.println(result); What is printed, and why?
85A programmer writes the following code: public class Test { public static void main(String[] args) { int i = 0; for (; i < 3; i++) { System.out.print(i + " "); } } } What is the output?
86A developer is writing a Java class and needs to declare local variables that follow valid Java naming and declaration rules. Which two of the following declarations are valid and will compile without error? (Choose two.)
87A developer is reviewing Java code and encounters several statements involving operators. Which TWO statements about Java operators are correct? (Choose two.)
88A developer is reviewing a class that declares several variables at different scopes. The class has an instance field named count, and a method contains a local variable also named count. The developer needs to identify which statements about variable scope and shadowing in Java are correct. (Choose two.)
89A developer writes a method that prints a message and then returns early when a validation check fails. The method signature is public void process(int value). Inside the method, the developer writes: if (value < 0) { return; } System.out.println(value); The code compiles and runs. Which statement best explains why the bare return statement is valid here?
90A developer is converting a numeric string entered by a user into an int for arithmetic. The code reads: String input = "42"; int result = Integer.parseInt(input) + 8; System.out.println(result); The developer expects 50 to be printed. Which statement correctly describes what happens when this code executes?
Deep-dive questions
The most-searched questions in this domain — detailed explanations, worked examples, full answer breakdowns.
You must read short Java snippets and state output, identify compile errors, choose correct primitive declarations, and place packaged classes correctly. The single most important thing: know that do-while executes its body before checking the condition, while for and while check first.
The Courseiva 1Z0-811 question bank contains 90 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