Hardest Java Test: Trivia Quiz!

18 Questions | Attempts: 213
Share

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]

  • 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

  • 3. 
    Which of the following is a collection that contains no duplicate elements?
    • A. 

      Deque

    • B. 

      ArrayList

    • C. 

      Set

    • D. 

      Map

  • 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 {}

  • 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

  • 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

  • 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

  • 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) {

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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 18. 
    ORM stands for________________
    • A. 

      Object Runtime Mapping

    • B. 

      Object Relational Mapping

    • C. 

      Oriented Runtime Matching

Back to Top Back to top
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.