Show Menu
Cheatography

Final Exam Java Cheat Sheet (DRAFT) by

cheat sheet for final exam java

This is a draft cheat sheet. It is a work in progress and is not finished yet.

123

What is the advantage of using try-wi­th-­res­ource over normal try-an­d-catch when creating AutoCl­osable resources?

a) Try-wi­th-­res­ource will automa­tically close the resources upon leaving the scope of try.
b) Multiple lines of resources separated by "­;" can be placed inside of one try-wi­th-­res­ource.
c) There is no need to create a finally block with null check and close statement for each resource.
d) All are advantages (correct)

1234

Match the servlet method to its operation?

__4__ doDelete
__2__ doPost
__3__ doPut
__1__ doGet
1. Read, provide data to user, for example, return a html page or a DB SELECT.
2. Create, process user provided data, for example, add row to a table.
3. Update, depending on the user data update inform­ation on the server, for example, DB UDPATE.
4. Delete, remove data from the server or DB.

123321

What is false about XHMTL?

a) Elements must always be properly nested in XHTML.
b) <!D­OCT­YPE> is mandatory in XHTML.
c) Attribute minimi­zation is forbidden in XHTML.
d) All others are false. (correct)
 

123312321

There are no differ­ences between the two blocks of code below. They will both produce the same result. (Note: Assume the code is correct, anything omitted is irrelevant to the question.)

// Code Block 1
Properties dbProps = new Proper­ties();
dbProp­s.p­ut(­"­use­r", username);
dbProp­s.p­ut(­"­pas­swo­rd", password);
Connection connection = Driver­Man­age­r.g­etC­onn­ect­ion­(jd­bcUrl, dbProps);

// Code Block 2
Connection connection = Driver­Man­age­r.g­etC­onn­ect­ion­(jd­bcUrl, username, password);

a) True (correct)
b) False

413

When a JSP page is called, it will be compiled (by the JSP engine intern­ally) into a Java servlet.

a) True (correct)
b) False

123

All JPQL queries can be written in HQL as Hibernate is 100% compliant with JPA. However, not all HQL queries can be written in JPQL as Hibernate has extra features that JPA does not support.

a) True (correct)
b) False

123

All JPQL queries can be written in HQL as Hibernate is 100% compliant with JPA. However, not all HQL queries can be written in JPQL as Hibernate has extra features that JPA does not support.

a) True (correct)
b) False
 

1233

Match the method to its descri­ption? If you are not sure, look up the docume­ntation online.

__2__ Can execute any query that does not return any ResultSet like INSERT and UPDATE. It returns the number of updated rows.

__1__ Can execute any type of query, like SELECT and INSERT. If return is true, the executed query has a ResultSet, otherwise, just a row count of updated rows or nothing.

__3__ Can execute any query which return a set of rows, like SELECT. It returns a ResultSet which contains the data and can never be null.

1. Prepar­edS­tat­eme­nt:­:ex­ecute
2. Prepar­edS­tat­eme­nt:­:ex­ecu­teU­pdate
3. Prepar­edS­tat­eme­nt:­:ex­ecu­teQuery

4531

Which scope is used on managed bean which is to be create­d/i­nst­ant­iated for every client session?

a) @Sessi­onS­coped (correct)
b) @ViewS­coped
c) @Appli­cat­ion­Scoped
d) @Reque­stS­coped

123312

Assume we have the code below, which annotation prevents "­foo­" from being null?

@Entit­y(name = "­A")
@Table­(name = "­TAB­LE_­A")
public class APojo {

@Id
@Gener­ate­dVa­lue­(st­rategy = Genera­tio­nTy­pe.I­DE­NTITY)
protected int id;

@Colum­n(name = "­COL­_1")
protected String foo;

//JPA likes default constr­uctor
public APojo() {
}
}

a) @Basic
b) @Basic­(op­tio­nal­=false) (CORRECT)
c) @Basic­(op­tio­nal­=true)
d) No need because by default nothing can be null.
 

132

In which of the following JSF phases has HTTP request parameters placed in a hash table and passed to all objects in the component tree.

a) Restore View
b) Update Model Values
c) Apply Request Values (correct)
d) Process Valida­tions

4314

What does the annotation @Transient on a field or property of an entity mean?

a) It specifies that the field or property is to be mapped to a column on a table in the database.
b) It specifies that the field or property is not persis­tent. (correct)
c) All answers are wrong.
d) It specifies that the field or property can be null.

123213

What is true about the @Table annota­tion?

a) All answers are true.(­cor­rect)
b) If no @Table annotation is used, then default values are used, that is, the entity class MyEntity will be mapped to the myentity table in the database if no @Table annotation is provided.
c) It allows you to define the name, schema, and catalog of the table for your entity mapping.