14. Quiz Questions

If you would like to look up the answers for the following quiz questions, you can check our discussion forum. If you don't find an answer in the forum, you may create a post asking for an answer to a particular question.

14.1. Question 1: Casting types in Java

Which of the following are valid type casts in Java?

  1. int x = Integer.parseInt("123");

  2. int x = (int) Double.parseDouble("123.47");

  3. int x = (int) 123.47;

  4. int x = (int) "123";

14.2. Question 2: JPA standard identifier property

Complete the following code, so that the Book JPA entity class contains a property named isbn, with String type and playing the role of the standard identifier:

@Entity @Table( name="books")
public class Book {
  @_________________
   ___________ isbn;
}

14.3. Question 3: Valid Java Bean classes

Which of the following classes are valid JavaBean classes:

  1. public class Person {
      private String name;
      public String getName() {return this.name;}
      public void setName( String n) {this.name = n;}
    }
  2. public class Person {
      private String name;
      public Person() {}
      public Person( String n) {this.setName(n);}
      public String getName() {return this.name;}
      public void setName( String n) {this.name = n;}
    }
  3. public class Person {
      private String name;
      public Person( String n) {this.setName(n);}
      public String getName() {return this.name;}
      public void setName( String n) {this.name = n;}
    }
  4. public class Person {
      String name;
      public Person() {}
      public Person( String n) {this.setName(n);}
      public String getName() {return this.name;}
      public void setName( String n) {this.name = n;}
    }

14.4. Question 4: HTML5 attributes with JSF forms

Complete the following code with the JSF construct which results in using date as value of the @type attribute of the rendered input HTML5 element.:

<h:form id="createForm">
  ...
  <h:outputText value="Date of Birth: " />
  <h:inputText id="birthDate" 
     p:________________ value="#{person.birthDate}">
  </h:inputText>
  ...
</h:form>

14.5. Question 5: JPQL query

Consider a JPA entity class named Customer. Write down the JPQL query to extract all its instances managed by the EntityManager (e.g., stored in DB or memory storage):

SELECT c FROM _____________________________________