Hardest Java Test: Trivia Quiz!

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Filipe Miranda
F
Filipe Miranda
Community Contributor
Quizzes Created: 1 | Total Attempts: 241
Questions: 18 | Attempts: 241

SettingsSettingsSettings
Hardest Java Test: Trivia Quiz! - Quiz

.


Questions and Answers
  • 1. 

    Consider the following program: class Point2D {      private int x, y;       public Point2D(int x, int y) {           this.x = x;       }       public String toString() {           return "[" + x + ", " + y + "]";       }       public static void main(String []args) {          Point2D point = new Point2D(10, 20);          System.out.println(point.toString());      } } Which one of the following options provides the output of this program when executed?

    • A.

      Point

    • B.

      Point

    • C.

      [0,0]

    • D.

      [10,0]

    • E.

      [10,20]

    Correct Answer
    D. [10,0]
    Explanation
    The correct answer is [10,0] because the Point2D object "point" is created with the coordinates (10, 20). However, the "toString()" method only returns the x coordinate and the y coordinate, separated by a comma and enclosed in square brackets. Therefore, the output will be "[10,0]".

    Rate this question:

  • 2. 

    Explain Runtime Exceptions.

    • A.

      It is an exception that occurs that probably could have been avoided by the programmer. As opposed to checked exceptions, runtime exceptions are ignored at the time of compliation.

    • B.

      Those are Exceptions thrown by JDBC API

    • C.

      Only the Exceptions thrown by IO operations are considered RuntimeExceptions

    • D.

      RuntimeExceptions are exceptions thrown by the compiler when it encounters an invalid statement

    Correct Answer
    A. It is an exception that occurs that probably could have been avoided by the programmer. As opposed to checked exceptions, runtime exceptions are ignored at the time of compliation.
    Explanation
    Runtime exceptions are exceptions that occur during the execution of a program and could have been avoided if the programmer had taken proper precautions. Unlike checked exceptions, which need to be explicitly handled or declared, runtime exceptions are not enforced by the compiler and are ignored at the time of compilation. This means that the programmer is not required to catch or declare these exceptions, but they can still occur during runtime if certain conditions are not met.

    Rate this question:

  • 3. 

    Which of the following is a collection that contains no duplicate elements?

    • A.

      Deque

    • B.

      ArrayList

    • C.

      Set

    • D.

      Map

    Correct Answer
    C. Set
    Explanation
    A Set is a collection that contains no duplicate elements. This means that each element in a Set is unique and cannot be repeated. Unlike other collections like Deque, ArrayList, and Map, which can contain duplicate elements, a Set ensures that every element is distinct. Therefore, a Set is the correct choice for a collection that contains no duplicate elements.

    Rate this question:

  • 4. 

    Given this three definitions: interface I1 {} interface I2 {} abstract class C {} which one of the following will compile without errors?

    • A.

      class CI12 extends C, I1, I2 {}

    • B.

      Class CI12 implements C extends I1, I2 {}

    • C.

      class CI12 implements C, I1, I2 {}

    • D.

      class CI12 extends C implements I1, I2 {}

    • E.

      Class CI12 extends C implements I1 implements I2 {}

    • F.

      Class CI12 implements C extends I1 extends I2 {}

    Correct Answer
    D. class CI12 extends C implements I1, I2 {}
    Explanation
    The correct answer is "class CI12 extends C implements I1, I2 {}". In Java, a class can only extend one superclass but can implement multiple interfaces. In this case, the class CI12 extends the superclass C and implements the interfaces I1 and I2, which is allowed and will compile without errors.

    Rate this question:

  • 5. 

    Which of the following statements are true regarding Statement and its derived types?

    • A.

      Objects of type Statement can handle IN, OUT, and INOUT parameters

    • B.

      PreparedStatement is used for executing servlets.

    • C.

      You can get an instance of PreparedStatement by calling preparedStatement() method in the Connection interface.

    • D.

      Statements are used hold Strings for longer periods

    Correct Answer
    C. You can get an instance of PreparedStatement by calling preparedStatement() method in the Connection interface.
    Explanation
    The correct answer is that you can get an instance of PreparedStatement by calling the preparedStatement() method in the Connection interface. This means that you can create a PreparedStatement object, which is a derived type of Statement, by using the preparedStatement() method provided by the Connection interface. This allows you to execute parameterized SQL queries and updates.

    Rate this question:

  • 6. 

    What's the difference between TreeSet and HashSet 

    • A.

      TreeSet is the Interface and HashSet implements it

    • B.

      Both are Set implementations, however TreeSet is a SortedSet, which means it is elements have a natural order, while HashMap has an unpredictable order

    • C.

      There is no TreeSet in the Java Platform, only HashSet

    Correct Answer
    B. Both are Set implementations, however TreeSet is a SortedSet, which means it is elements have a natural order, while HashMap has an unpredictable order
    Explanation
    The given answer correctly explains the difference between TreeSet and HashSet. It states that TreeSet is a SortedSet, meaning its elements have a natural order, while HashSet does not have a predictable order. This highlights the key distinction between the two implementations.

    Rate this question:

  • 7. 

    What do you mean by Object?

    • A.

      Object is a runtime entity and it’s state is stored in fields and behavior is shown via methods. Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication.

    • B.

      They are the processors in which a Java Application is executed

    • C.

      Objects are also known as packages in the Java language

    • D.

      Are all of the methods in the Collections Framework

    Correct Answer
    A. Object is a runtime entity and it’s state is stored in fields and behavior is shown via methods. Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication.
  • 8. 

    Consider the following code snippet:try (FileReader inputFile = new FileReader(file)) {     //#1     System.out.print( (char)ch );  }}Which one of the following statements can be replaced in the place of statement #1?

    • A.

      While( (ch = inputFile.read()) != null) {

    • B.

      While( (ch = inputFile.read()) != -1) {

    • C.

      While( (ch = inputFile.read()) != 0) {

    • D.

      While( (ch = inputFile.read()) != EOF) {

    Correct Answer
    B. While( (ch = inputFile.read()) != -1) {
    Explanation
    The correct replacement for statement #1 is "while( (ch = inputFile.read()) != -1) {". This is because the FileReader class's read() method returns -1 when it reaches the end of the file. Therefore, the while loop will continue executing as long as there are more characters to read from the file.

    Rate this question:

  • 9. 

    Consider the following program:import java.util.ArrayList;class RemoveTest {    public static void main(String []args){      ArrayList list = new ArrayList ();      list.add(new Integer(2));      list.add(1);      list.add(5);      list.remove(2); // REMOVE      System.out.println(list);    }}Which one of the following options correctly describes the behavior of this program?

    • A.

      When executed, this program prints the following: [2, , 5]

    • B.

      When executed, this program prints the following: [2, 1].

    • C.

      When executed, this program prints the following: [1, 5].

    • D.

      This program results in a compiler error in the line marked with the comment REMOVE.

    • E.

      This program results in a NoSuchElementException in the line marked with the comment REMOVE.

    Correct Answer
    B. When executed, this program prints the following: [2, 1].
    Explanation
    The program creates an ArrayList called "list" and adds three elements to it: an Integer object with a value of 2, the integer 1, and the integer 5. The program then removes the element at index 2, which is the integer 5. Finally, the program prints the contents of the ArrayList, which is [2, 1].

    Rate this question:

  • 10. 

    What's the porpouse of the DAO Pattern

    • A.

      Commit all alterations in the Database

    • B.

      Separate the business logic from the data access logic in the application

    • C.

      Make the programmer work less

    • D.

      Establish a connection to the database

    Correct Answer
    B. Separate the business logic from the data access logic in the application
    Explanation
    The purpose of the DAO (Data Access Object) pattern is to separate the business logic from the data access logic in the application. This pattern allows for a clear separation of concerns, making the code more modular and maintainable. By encapsulating the data access code in separate DAO classes, it becomes easier to make changes to the data access layer without affecting the rest of the application. This promotes code reusability and improves the overall design of the application.

    Rate this question:

  • 11. 

    When we declare a field as volatile, what do we intend to do?class ClassVotile{    volatile boolean field;}

    • A.

      Make the field compile faster

    • B.

      Establish a happens before relationship regarding the reads and writes to the field

    • C.

      Avoid exceptions related to this field

    • D.

      The field is static and final, which means it cannot be changed

    Correct Answer
    B. Establish a happens before relationship regarding the reads and writes to the field
    Explanation
    When we declare a field as volatile, we intend to establish a happens before relationship regarding the reads and writes to the field. This means that any write to the volatile field will be visible to all subsequent reads of the field. It ensures that the changes made by one thread are visible to other threads, preventing any data inconsistencies or race conditions.

    Rate this question:

  • 12. 

    Is the following statement true: A Servlet cannot respond to requests, it is meant to connect to the database and serves as a pool of connections

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    A Servlet is a Java class that is used to respond to client requests in a web application. It can handle requests and generate responses dynamically. While a Servlet can connect to a database and manage connections, it is not solely meant for that purpose. It can perform a wide range of tasks, such as processing form data, generating HTML content, and interacting with other components in the web application. Therefore, the statement that a Servlet cannot respond to requests and is only meant for connecting to the database is false.

    Rate this question:

  • 13. 

    Which of the following option describes a Map in Java?

    • A.

      An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.

    • B.

      The root interface in the Collections Framework, the programmer never uses it

    • C.

      A container to map objects to values allowing duplicated keys

    • D.

      A subclass of Set that maps values to memory adresses

    • E.

      An subclass of Collection Interface that maps keys to values

    Correct Answer
    A. An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
    Explanation
    A Map in Java is an object that maps keys to values. It does not allow duplicate keys, meaning each key can only map to one value. This data structure is commonly used to store and retrieve values based on a specific key.

    Rate this question:

  • 14. 

     What is the difference between static and non-static variables?

    • A.

      A static variable is also known as a constant, that cannot have values other than null

    • B.

      A Static variable is also known as a local variable, while a variable is global

    • C.

      A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.

    • D.

      A Static variable is also known as a variable of only one type, while a variable might be dynamically resolved to any type during the program's execution

    Correct Answer
    C. A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.
    Explanation
    The correct answer explains the difference between static and non-static variables. It states that a static variable is associated with the class as a whole, meaning it is shared among all instances of the class. On the other hand, non-static variables are unique to each object instance and have different values for each instance. This difference highlights the distinction between a variable that is shared among all instances and a variable that is specific to each individual instance.

    Rate this question:

  • 15. 

    Consider the diagram, is the following statement true: The Controller cannot be implemented by the developer, and it must not be!

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The statement "The Controller cannot be implemented by the developer, and it must not be!" is false. The Controller is a crucial component in the Model-View-Controller (MVC) architectural pattern, responsible for handling user inputs and updating the model and view accordingly. The developer is responsible for implementing the Controller, as it requires programming logic to interpret user actions and update the system accordingly. Therefore, the statement is incorrect, and the Controller can and should be implemented by the developer.

    Rate this question:

  • 16. 

    Which of these packages contain classes and interfaces used for input & output operations of a program?

    • A.

      Java.util

    • B.

      Java.lang

    • C.

      Java.io

    • D.

      All mentioned

    Correct Answer
    C. Java.io
    Explanation
    The package java.io contains classes and interfaces that are used for input and output operations in a program. This package provides classes for reading and writing data streams, handling files and directories, and performing other input and output related tasks. Therefore, the correct answer is java.io.

    Rate this question:

  • 17. 

    Is the following Statement true: InputStreams and OutputStreams are part of the java built-in mechanism for I/O operations

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    InputStreams and OutputStreams are indeed part of the Java built-in mechanism for I/O operations. They are used for reading and writing data, respectively, in a streaming fashion. InputStreams allow the program to read data from a source, such as a file or network connection, while OutputStreams enable the program to write data to a destination. These classes provide a convenient and standardized way to perform input and output operations in Java.

    Rate this question:

  • 18. 

    ORM stands for________________

    • A.

      Object Runtime Mapping

    • B.

      Object Relational Mapping

    • C.

      Oriented Runtime Matching

    Correct Answer
    B. Object Relational Mapping
    Explanation
    ORM stands for Object Relational Mapping. It is a programming technique that allows developers to map objects from a relational database to the objects in their application code. This helps in simplifying the data access layer and eliminates the need for writing complex SQL queries. With ORM, developers can work with objects and their relationships, rather than dealing with low-level database operations. This improves productivity, code maintainability, and reduces the chances of errors.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Feb 12, 2015
    Quiz Created by
    Filipe Miranda
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.