Java Certified Foundations Associate (1Z0-811) Free Practice Tests

 

The answers to the questions below are waiting for you at the end of this blog. Keep reading to discover them!

1. Which of the following is true about Java bytecode?

  • A. It can only be executed on the machine where it was compiled.
  • B. It can be executed on any platform that has a compatible Java Virtual Machine (JVM).
  • C. It can be executed on any operating system but only on specific hardware architectures.
  • D. It needs to be compiled separately for each operating system and hardware architecture to run properly.

2. Given the following code:

//1
//2
public class ExampleClass {
    public static void main(String[] args) {
        String message = "Hello, World!";
        System.out.println(message);
    }
}

Which two lines can be inserted at locations marked //1 and //2?

  • A. import java.util.*; at //1
  • B. import java.lang.*; at //1
  • C. package example; at //1
  • D. package com.example; at //2
  • E. import java.lang.*; at //2
  • F. import java.util.*; at //2

3. Which of the following can be valid declarations of a string variable?

  • A. string message = "Hello";
  • B. public String message = "Hello";
  • C. final String message = "Hello";
  • D. String message = "Hello";
  • E. static string message = "Hello";

4. What will be printed when the following code snippet is executed?

String str = "abcdefgh";
str.substring(1, 4);
System.out.println(str.charAt(3));
  • A. d
  • B. e
  • C. f
  • D. This will not compile

5. Given:

int x = 10, y = 3, z = 20;
System.out.println(x++ * z / y);

What is the result?

  • A. 30
  • B. 33
  • C. 40
  • D. 66
  • E. Compilation failure
  • F. Exception at run time

6. Which of the following four constructs are valid?

1. if (a > b) if (c < d);
2. int y = 5;
   if (x > 0) if (y == 5) { }
3. if (x == 10) if (y == 20);
4. int z = 0;
   if (z == 0) { }
  • A. 1, 3
  • B. 1, 2, 3
  • C. All are valid.
  • D. 3, 4
  • E. 1, 2, 4

7. What will be the result of attempting to compile and run the following program? Given:

class Product {
    int productId;
    String productName;
    public Product(int productId, String productName) {
        this.productId = productId;
        this.productName = productName;
    }
    public void setProductId(int productId) {
        this.productId = productId;
    }
    public void setProductName(String productName) {
        this.productName = productName;
    }
}

public class Store {
    public static void main(String[] args) {
        //INSERT CODE HERE
        System.out.println(product.productId + " " + product.productName);
    }
}

What can be inserted in the above code so that it will print 123 Laptop?

  • A. Product product = new Product(); product.productId = 123; product.productName = "Laptop";
  • B. Product product = new Product(123, "Laptop");
  • C. Product product = new Product(); product.setProductId(123); product.setProductName("Laptop");
  • D. Product product = null; product.productId = 123; product.productName = "Laptop";
  • E. Product product; product.productId = 123; product.productName = "Laptop";

8. Given the following code:

class ControlFlowTest {
    public static void main(String args[]) {
        int i = 0;
        while (i < 5) { 
            i++; 
            if (i == 3) continue; //1
        }
        while (i > 0) { 
            i--; 
            if (i == 2) break; //2
        }
        do { 
            i--; 
        } while (i > 0); //3
    }
}

What will be the result?

  • A. The code will compile without error and will terminate without problems when run.
  • B. The code will fail to compile, since the 'continue' can't be used this way.
  • C. The code will fail to compile, since the 'break' can't be used this way.
  • D. The code will fail to compile, since the do-while loop in line 3 is invalid.
  • E. The code will compile without error but will never terminate.

9. Which of the following statements are true?

  • A. A non-static method can directly access static variables and methods in the same class.
  • B. A static method can call non-static methods directly in the same class using the 'this' keyword.
  • C. Every object of a class shares a single copy of static variables.
  • D. Instance methods can access local variables of static methods.
  • E. Static methods are implicitly passed a 'this' parameter when called.

10. Identify valid for constructs:

  • A. for(int i = 0; i < 10; i++) { System.out.println("valid"); }
  • B. for(int i = 0; ; i++) { if(i == 5) break; }
  • C. for(; i < 5; i++) { System.out.println(i); }
  • D. for(int i = 0; i < 5; ) { System.out.println(i); i++; }

11. A try statement must always have a ............. associated with it.

  • A. catch
  • B. throws
  • C. finally
  • D. catch, finally or both
  • E. throw

12. Which of the following statements about lists are correct?

  • A. A list can dynamically grow or shrink in size.
  • B. Lists can only store elements of primitive types.
  • C. Every list has a built-in property named 'length' which tells you the number of elements in the list.
  • D. Every list has an implicit method named 'size' which tells you the number of elements in the list.
  • E. Element indexing for lists as well as for arrays starts at 1.

Looking to ace your Java exam? 🚀

Boost your preparation for the Java Certified Foundations Associate (1Z0-811) exam with tons of practice questions and answers! 📚

✅ Test your knowledge with multiple-choice questions ✅ Dive deeper into core Java concepts ✅ Improve your chances of passing with expert-level questions!

Click Here to Level Up Your Java Skills! 🚀 ✨ unlock a whole new level of practice and strengthen your skills! 💡

Popular posts from this blog

Learn Java 8 streams with an example - print odd/even numbers from Array and List

Java Stream API - How to convert List of objects to another List of objects using Java streams?

Registration and Login with Spring Boot + Spring Security + Thymeleaf

Java, Spring Boot Mini Project - Library Management System - Download

ReactJS, Spring Boot JWT Authentication Example

Top 5 Java ORM tools - 2024

Java - Blowfish Encryption and decryption Example

Spring boot video streaming example-HTML5

Google Cloud Storage + Spring Boot - File Upload, Download, and Delete