The .equals() method compares the Object's values by default.

 True or False?

 

 

Group of answer choices

True

False
 
Flag question: Question 2
Question 215 pts
What is Junit, and Why would we use Junit testing in our code? (Select All that apply)
Group of answer choices

The process of checking the functionality of an application to ensure it runs as per the speciﬁed requirements

A unit testing framework for Java programming language

A method used to ensure that another part of code works as expected

The Junit is only good for UI/UX/web designers
 
Flag question: Question 3
Question 315 pts
What are Parameterized Tests used for in JUnit?
Group of answer choices

To run a test once without any arguments.

To run a test multiple times with diﬀerent arguments.

To run a test once with a ﬁxed set of arguments.

To run a test multiple times without any arguments.
 
Flag question: Question 4
Question 415 pts
Monolithic structures do not support the testing of individual behaviors.

True or False?

Group of answer choices

True

False
 
Flag question: Question 5
Question 515 pts
How can we test a method declared as protected?
Group of answer choices

By using a Reﬂection of the class that contains the tested methods.

Methods declared as protected cannot be tested

By copying the method content into the test case methods

By placing tests in the same package as the class that contains the tested method
 
Flag question: Question 6
Question 615 pts
What is the most likely output/result of the following JUnit tests? (please assume that all necessary imports are correct)

class MyClass {

  public int add(int a, int b) {
    return a + b;
  }
}
 

public class MyTests {

    private final MyClass myClass = new MyClass();

    @BeforeAll
    public void beforeAll() {
        System.out.println("beforeAll/beforeClass
        Finished ");
    }

    @Test
    public void additionTest() {
        assertEquals(2, myClass.add(1, 1));
        System.out.println("additionTest
          Finished ");
    }
}
Group of answer choices

beforeAll/beforeClass Finished

org.junit.platform.commons.JUnitException: @BeforeAll method 'public void example.MyTests.beforeAll()' must be static

beforeAll/beforeClass Finished additionTest Finished

additionTest Finished
 
Flag question: Question 7
Question 715 pts
What is the most likely output/result of the following JUnit test? (please assume that all necessary imports are correct)

class MyClass {

  public int add(int a, int b) {
    return a + b;
  }
}
 

public class CalculatorTests {

  private final MyClass calculator = new MyClass();

  @Test
  void additionTest() {
    System.out.println("Test started");
    assertEquals(57, calculator.add(1, 1));
    System.out.println("Test Finished");
  }
}
Group of answer choices

Test started but the test will FAIL. (With an AssertionFailedError in the Failure Trace)

This code would not compile

Test started Test Finished
 
Flag question: Question 8
Question 815 pts
In the following code, the query.setParameter("empId", id) statement substitutes the "id" argument into the query (HQL).  (True / False)  

public Employee findByEmployeeId(Integer id) {
SessionFactory factory = new Configuration().configure().buildSessionFactory();
Session session = factory.openSession();
Transaction t = session.beginTransaction();

String hql = "FROM Employee e where e.employeeNumber = :empId";

TypedQuery<Employee> query = session.createQuery(hql, Employee.class);
query.setParameter("empId", id);

Employee result = query.getSingleResult();

t.commit();
factory.close();
session.close();

return result;
}

Group of answer choices

False

True
 
Flag question: Question 9
Question 915 pts
What is the most likely output of the following program? 

"Note: Assuming there is a record with the specified id."

public Customer findByCustomerId( Integer id ) {
     SessionFactory factory = new Configuration().configure().buildSessionFactory();
    Session session = factory.openSession();
    Transaction t = session.beginTransaction();

    String hql = "FROM Customer c where c.id = :custId";
    TypedQuery<Customer> query = session.createQuery(hql, Customer.class);
    query.setParameter("custId", id);
    Customer result = query.getSingleResult();

    t.commit();
   factory.close();
   session.close();
    return result;
}

Group of answer choices

Return single record from the CUSTOMER Table

Throw Error

None of the mentioned

Return all record from CUSTOMER table
 
Flag question: Question 10
Question 1015 pts
What is the most likely output of the following program? Please assumes all imports are correct and you have a valid hibernate.cfg.xml or persistance.xml file.

 

MainClass.java

public class MainClass {
  public static void main(String[] args) {
    SessionFactory factory = new Configuration().configure().buildSessionFactory();
    Session session = factory.openSession();
    Transaction t = session.beginTransaction();

    Person p1 = new Person();
    p1.setName("Elbert");
    session.save(p1);

    Person p2 = new Person();
    p2.setName("fink");
     session.save(p2);
    t.commit();

    TypedQuery q = session.createQuery("select P from Person P");
    List < Person > data = q.getResultList();
    for (Person e: data) {
      System.out.println(e.getPersonId() + ":" + e.getName());
    }
  }
}


Person.java

@Entity
@Table
public class Person {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int PersonId;
  private String name;

  // Declare Address class for relationship
  @OneToOne(cascade = CascadeType.ALL)
  private Address myaddress;

  public Person(int personId, String name) {
    PersonId = personId;
    this.name = name;
  }

  public Person() {}
  public int getPersonId() {
    return PersonId;
  }

  public void setPersonId(int personId) {
    PersonId = personId;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }
}
Group of answer choices

The Person objects will not be saved into the database but the code will execute without Runtime error

Output --> 1:Elbert 2:fink

1:Elbert

Throw runtime error
 
Flag question: Question 11
Question 1115 pts
Which of the following steps are required to properly use JDBC to issue SQL commands in your application? (Select All that apply)
Group of answer choices

Predeﬁned any SQL commands to be issued to the database as static ﬁnal Strings

Use a Connection to create Statement or Prepared Statement

Create a connection to the database

Establish and maintain a stable internet connection

Be already logged into the database through the Graphical user interface

Be already logged into the database through the command-line interface

Include the JDBC driver in the application's classpath

Provide a URL to the existing database schema to be accessed by your application
 
Flag question: Question 12
Question 1215 pts
What would happen if the connections used in JDBC applications were never closed? (Select All that apply)

 

Group of answer choices

It would lead to memory leaks

The database server would not be able to provide connections for new requests after it reaches its maximum number of simultaneous connections.

The data in the database will be corrupted

The connection may remain active even after the application exits

None of the mentioned - connections will be closed automatically by the JVM
 
Flag question: Question 13
Question 1315 pts
Which of the following methods is used to update the entity in the database?

 

Group of answer choices

insert()

merge()

put()

add()
 
Flag question: Question 14
Question 1415 pts
What is a SessionFactory() in hibernate?

 

 

 

Group of answer choices

Hibernate is a  Java object that represents data that can be persisted to the database, where its class represents a table stored in a database, and every instance of that class represents a row in the table.

SessionFactory is an interface. It is usually created during application start-up and kept for later use. It uses the hibernate config file to connect with the database and create hibernate sessions.

SessionFactory is a logical grouping of user-deﬁned persistable classes with related settings, that are deﬁned in a .xml ﬁle, which has to be located in the META- INF directory in the classpath.

SessionFactory object can be created without configuration information in the hibernate.cfg.xml file
 
Flag question: Question 15
Question 1515 pts
The following statement is True or False?

A Session object is used to perform Create, Read, Update, Delete (CRUD) operations for instances of mapped entity classes.

Group of answer choices

False

True
 
Flag question: Question 16
Question 1615 pts
What are some benefits of using hibernate over JDBC?  (Select All that apply)
Group of answer choices

Reduced boilerplate code

Automatic Object-Relational Mapping

Does not require database connection configuration for database query

Hibernate provides better migration to other databases
 
Flag question: Question 17
Question 1715 pts
In Hibernate, which annotation specifies the primary key on a variable?
Group of answer choices

@Table

@JoinColumn

@PrimaryId

@Id
 
Flag question: Question 18
Question 1815 pts
_________   annotation is used to map an instance field of the class to a column in the database table, and it is must be placed before the field or the getter method of the field. By default, Hibernate can implicitly infer the mapping based on the field name and field type of the class. But if the field name and the corresponding column name are different, we have to use this annotation explicitly.
Group of answer choices

@Id

@Column

@JoinColumn

@Table
 
Flag question: Question 19
Question 1915 pts
What is the difference between the executeQuery(String SQL) and the executeUpdate(String SQL) of the Statement interface?
Group of answer choices

The executeUpdate(String SQL) method is most often is used to execute DML statements (INSERT, UPDATE and DELETE) and it returns a ResultSet object containing data requested by executed SQL statement. The executeQuery(String SQL) method is used to retrieve data from the database by executing a DQL(SELECT ) statement and it returns an int value representing the count of the rows aﬀected by its execution.

The executeUpdate(String SQL) method is used to execute  (INSERT, UPDATE, and DELETE) statements, and it returns an int value representing the count of the rows aﬀected by its execution. The executeQuery(String SQL) method retrieves data from the database by executing a "SELECT" statement, and it returns a ResultSet object containing data requested by executed SQL statement.

The executeQuery(String SQL) method is most often is used to execute DML statements (INSERT, UPDATE and DELETE) and it returns an int value representing the count of the rows aﬀected by its execution. The executeUpdate(String SQL) method is used to retrieve data from the database by executing a DQL(SELECT ) statement and it returns a ResultSet object containing data requested by executed SQL statement.

The executeQuery(String SQL) and executeUpdate(String SQL) methods are equivalent and serve the same function on the Statement and the PreparedStatement interfaces respectively.
 
Flag question: Question 20
Question 2015 pts
The ________ annotation is used on the Entity classes (model classes) and tells that the classes are entity bean. The _________ annotation is used to define the name of the table used. (Select all that apply.)
Group of answer choices

@Table

@Entity

@Model

@Entities