Courseiva
Knowledge + Practice
CertificationsVendorsCareer RoadmapsLabs & ToolsStudy GuidesGlossaryPractice Questions
C
Courseiva

Free IT certification practice questions with explained answers for CCNA, CompTIA, AWS, Azure, Google Cloud, and more.

Certification Practice Questions

CCNA practice questionsSecurity+ SY0-701 practice questionsAWS SAA-C03 practice questionsAZ-104 practice questionsAZ-900 practice questionsCLF-C02 practice questionsA+ Core 1 practice questionsGoogle Cloud ACE practice questionsCySA+ CS0-003 practice questionsNetwork+ N10-009 practice questions
View all certifications →

Product

CertificationsCertification PathsExam TopicsPractice TestsExam Dumps vs Practice TestsStudy HubComparisons

Company

AboutContactEditorial PolicyQuestion Writing PolicyTrust Center

Legal

Privacy PolicyTerms of Service

Courseiva is a free IT certification practice platform offering original exam-style practice questions, detailed explanations, topic-based practice, mock exams, readiness tracking, and study analytics for Cisco, CompTIA, Microsoft, AWS, and other technology certifications.

© 2026 Courseiva. Courseiva is operated by JTNetSolutions Ltd. All rights reserved.

Courseiva is an independent certification practice platform and is not affiliated with, endorsed by, or sponsored by Cisco, Microsoft, AWS, CompTIA, Google, ISC2, ISACA, or any other certification vendor. Vendor names and certification marks are used only to identify the exams learners are preparing for.

HomeCertifications1Z0-811DomainsJava Basics and Syntax
1Z0-811Free — No Signup

Java Basics and Syntax

Practice 1Z0-811 Java Basics and Syntax questions with full explanations on every answer.

103questions

Start practicing

Java Basics and Syntax — choose a session length

10 questions~10 min20 questions~20 min30 questions~30 min50 questions~50 min

Free · No account required

1Z0-811 Domains

What is JavaJava Basics and SyntaxPrimitives, Strings and OperatorsControl Flow and LoopsArrays and MethodsObject-Oriented ProgrammingException Handling and Development Tools

Practice Java Basics and Syntax questions

10Q20Q30Q50Q

All 1Z0-811 Java Basics and Syntax questions (103)

Start session

Click any question to see the full explanation and answer options, or start a focused practice session above.

1

A developer writes the following code: int x = 5; System.out.println(x++); What is the output?

2

A team decides to use a single Java source file for a small application. Which statement is true about the file structure?

3

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?

4

Which primitive data type should be used to store a single character?

5

A method is declared as: public static void main(String[] args) { }. Which statement is true?

6

Which code snippet correctly creates a two-dimensional array with 3 rows and 4 columns?

7

What is the value of the expression (10 > 5) && (3 < 2)?

8

Which loop construct guarantees that the body executes at least once?

9

Given the code: int[] arr = {1,2,3}; for(int x : arr) { if(x==2) continue; System.out.print(x); } What is the output?

10

Which access modifier makes a member visible only within its own class?

11

What is the result of the expression 10 % 3?

12

Which TWO are valid identifiers in Java? (Choose two.)

13

Which THREE are valid ways to declare and initialize an integer variable in Java? (Choose three.)

14

Which TWO keywords are used for decision-making in Java? (Choose two.)

15

Which THREE statements about the main method are correct? (Choose three.)

16

What is the output of this program?

17

What is the value printed?

18

What is the output?

19

You 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?

20

You 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?

21

Arrange the steps to declare and initialize a one-dimensional array in Java in the correct order.

22

Arrange the steps to use the Scanner class to read user input in Java in the correct order.

23

Match each access modifier to its visibility level.

24

Match each Java collection interface to its characteristics.

25

A 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?

26

A 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?

27

A developer uses a switch statement with a String variable. Which is true about this usage?

28

Which loop construct guarantees that the loop body executes at least once?

29

A method receives an int parameter and modifies its value inside the method. Does this change affect the caller's argument?

30

Given int[] arr = {1,2,3}; which correctly creates a new array with length 5 and copies the contents of arr?

31

A class defines two methods with the same name but different parameter lists. This is known as:

32

Which access modifier allows members to be accessed only by classes in the same package?

33

A subclass overrides a method from its superclass. Which annotation should be used to indicate the overriding intention?

34

Which TWO are valid Java identifiers? (Choose two.)

35

Which TWO statements about constructors are true? (Choose two.)

36

Which THREE are primitive data types in Java? (Choose three.)

37

Refer to the exhibit. What is the output?

38

Refer to the exhibit. What is the result of attempting to compile and run the code?

39

Refer to the exhibit. What is the output?

40

A developer writes: int x; System.out.println(x); What is the result?

41

Given: String s = "Java"; s.concat(" Rocks"); System.out.println(s); What prints?

42

What is the result of: int[] arr = new int[5]; System.out.println(arr[5]);

43

Given: 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?

44

Given methods: void print(Integer i) { System.out.println("Integer"); } void print(int i) { System.out.println("int"); } What is output of print(10);?

45

Which assignment requires an explicit cast to compile?

46

Consider: for(int i=0;i<10;i++) { int x = i; } System.out.println(x); What is the result?

47

Given method: static void change(String s) { s = "new"; } What is output of: String name = "original"; change(name); System.out.println(name);

48

What is the result of: Integer a = null; int b = (a != null) ? a : 0; System.out.println(b);

49

Which TWO of the following are valid Java identifiers?

50

Which TWO of the following are legal ways to declare and initialize an array?

51

Which THREE of the following are primitive data types in Java?

52

Refer to the exhibit. What is the likely cause of this error?

53

Refer to the exhibit. What happens when you compile this code?

54

Refer to the exhibit. What is the output?

55

A developer needs to declare a constant for the value of PI (3.14159) in a class. Which declaration follows Java best practices?

56

A method is expected to receive an integer and return its square. Which method signature is correct?

57

A 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?

58

Which is the correct way to declare an array of integers in Java?

59

A developer writes: if (x = 5) { System.out.println("x is 5"); } What is the result?

60

Which TWO statements are true about the main method?

61

Which THREE of the following are primitive data types in Java?

62

Which TWO are valid ways to create a String object?

63

Refer to the exhibit. What is the output?

64

Refer to the exhibit. What is the most likely cause?

65

Refer to the exhibit. What is the output when running the main method?

66

A 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?

67

A package named com.example.util is declared in a file. Where should the file be placed in the directory structure?

68

A developer uses the following array initialization: int[] nums = new int[]{1, 2, 3}; Which of the following is true?

69

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?

70

A developer writes the following code: int x = 5; int y = x++; What are the values of x and y after execution?

71

A company requires a method that accepts an integer and returns true if the integer is even, otherwise false. Which implementation best follows Java conventions?

72

Given the loop: for (int i=0; i<5; i++) { if (i==2) continue; System.out.print(i); } What is the output?

73

Which data type should be used to store a single character like 'A'?

74

What is the result of the following code? String s1 = "Hello"; String s2 = " World"; String s3 = s1 + s2; System.out.println(s3);

75

Given: int[] arr = {10,20,30}; System.out.println(arr[3]); What is the result?

76

Which method overloading is valid?

77

What is the scope of a variable declared inside a for loop?

78

Which statement about try-catch is true?

79

Which TWO keywords are used to control access to class members? (Choose two.)

80

Which THREE are primitive data types in Java? (Choose three.)

81

Which THREE are valid Java identifiers? (Choose three.)

82

The code does not compile. What is the error?

83

What likely caused this compilation error?

84

A 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.

85

A developer declares an integer variable inside a method but does not assign a value. What is the result of attempting to print the variable?

86

Given two String objects s1 = "Hello" and s2 = "Hello", what does the expression (s1 == s2) return?

87

A developer writes: int x = 5; int y = x++ + ++x; What is the value of y after execution?

88

A developer wants to iterate over an array of integers named 'numbers'. Which loop declaration will correctly access each element?

89

A class has two methods: void setValue(int a) and void setValue(double a). Which call will result in a compilation error?

90

A parent class has a static method display() and an instance method show(). A child class attempts to override both. What is the outcome?

91

Which TWO are valid ways to declare and initialize a two-dimensional int array in Java?

92

Which THREE are valid Java identifiers?

93

Which THREE statements about the final keyword in Java are true?

94

A 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?

95

A 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?

96

A 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?

97

A 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?

98

A 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?

99

A 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?

100

You are tasked with debugging a Java application that processes temperature sensor readings. The application reads an array of double values representing temperatures in Celsius, and should output the number of readings that exceed a threshold of 30.0°C. The current implementation is: public class TemperatureAnalyzer { public static void main(String[] args) { double[] readings = {25.5, 32.1, 30.0, 28.9, 35.7}; int count = 0; for (int i = 0; i < readings.length; i++) { if (readings[i] > 30.0) { count++; } } System.out.println("Count: " + count); } } However, the output is "Count: 3" instead of the expected 2 (since 30.0 is not above the threshold). The developer believes the issue is that the condition should be '>=' to include 30.0, but the specification says strictly above 30.0. After further investigation, you discover that the problem is due to floating-point imprecision when comparing with the literal 30.0. Which of the following changes would correctly fix the comparison to reliably count readings strictly greater than 30.0, considering floating-point representation?

101

Which TWO of the following are valid Java identifiers? (Choose two.)

102

What is the result of compiling and running this code?

103

A developer is building a Java application for a bank that processes account transactions. The application reads transaction amounts from a CSV file provided by a third party. The amounts are in string format, e.g., '1,234.56' or '$5,000.00'. The developer uses Integer.parseInt() to convert these strings to integers for processing. However, many transactions fail with NumberFormatException. The developer adds a try-catch block to catch the exception and log the error. But still, the application fails to process valid transactions because the parsing does not handle the formatting. The development team is considering several approaches to fix this issue. The goal is to parse the string into an integer representing the whole dollar amount (ignoring cents and formatting). Which course of action should the developer take?

Practice all 103 Java Basics and Syntax questions

Other 1Z0-811 exam domains

What is JavaPrimitives, Strings and OperatorsControl Flow and LoopsArrays and MethodsObject-Oriented ProgrammingException Handling and Development Tools

Frequently asked questions

What does the Java Basics and Syntax domain cover on the 1Z0-811 exam?

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.

How many Java Basics and Syntax questions are in the 1Z0-811 question bank?

The Courseiva 1Z0-811 question bank contains 103 questions in the Java Basics and Syntax domain. Click any question to see the full explanation and answer breakdown.

What is the best way to practice Java Basics and Syntax for 1Z0-811?

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.

Can I practice only Java Basics and Syntax questions for 1Z0-811?

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.

Free forever · No credit card required

Track your 1Z0-811 domain progress

Save your results, see per-domain analytics, and get readiness scores — free, for every certification.

Sign Up Free

Free forever · Every certification included

Practice Session

10 questions20 questions30 questions50 questions

Study Resources

All DomainsPractice TestMock ExamFlashcardsStudy Guide