Java Programming Test 1

    Question 1JAVA - Variable Declaration Basics

    Which of the following is a valid variable declaration in Java?

    Question 2JAVA - Method Basics

    Which of the following is a valid method declaration in Java?

    Question 3JAVA - String Immutability

    Why are Strings immutable in Java?

    Question 4JAVA - Array Declaration

    Which of the following is a valid array declaration in Java?

    Question 5JAVA - Exception Types

    Which of the following is a checked exception in Java?

    Question 6JAVA - Collection Interface

    Which of the following is the root interface of the Java Collections Framework?

    Question 7JAVA - Generics Basics

    What is the main purpose of Generics in Java?

    Question 8JAVA - Lambda Basics

    What is the main purpose of lambda expressions in Java?

    Question 9JAVA - Streams Basics

    What is the main advantage of using Streams in Java?

    Question 10JAVA - Thread Creation

    Which of the following is a correct way to create a thread in Java?

    Question 11JAVA - Data Types

    Which of the following is a primitive data type in Java?

    Question 12JAVA - Return Type

    What will be the output?

    int add(int a, int b) { return a + b; } System.out.println(add(3, 4));

    Question 13JAVA - String Object Creation

    Which of the following creates a new String object in the heap?

    Question 14JAVA - Array Initialization

    What will be the default values of an int array in Java?

    Question 15JAVA - Try-Catch Execution

    What will be the output?

    try { int x = 5 / 0; System.out.println("Try Block"); } catch(ArithmeticException e) { System.out.println("Catch Block"); }

    Question 16JAVA - List Characteristics

    Which statement about `List` is correct?

    Question 17JAVA - Generic Class

    Which of the following correctly defines a generic class?

    Question 18JAVA - Lambda Syntax

    Which is the correct syntax for a lambda expression that takes two integers a and b and returns their sum?

    Question 19JAVA - Stream Creation

    Which of the following is a correct way to create a stream from a list?

    Question 20JAVA - Start vs Run

    What happens if you call the run() method directly instead of start() on a thread?