image
Exam Part 2
Exam Part 2
Difficulty
Intermediate
Duration
57m
Students
11
Description

In this course, we will cover a Mock Exam with answers and explanations for Java EE 7.

Learning Objectives

  • Prepare for the Java EE 7 exam

Intended Audience

  • Anyone looking to get Oracle Java Certification
  • Those who want to improve Java 7 EE knowledge
  • Java developers

Prerequisites

  • Have at least 2 years of Java development experience 
Transcript

The next question is about use batch API in Java EE 7 applications. It asks, which interface should we implement if we want to be alerted to the lifecycle events surrounding our task being executed by a ManagedExecutorService? For this question, the right option is C. Tasks can optionally provide a ManagedTaskListener to receive notifications of lifecycle events through the use of ManagedTaskInterface. The next question is about use Java message service API. The question says, a developer wants to send a message to a queue in a transaction. Which of the following calls would he use to create a session with default acknowledgement mode? Before moving on to options, note that there is only one method in QueueConnectionsInterface to create QueueSession, and it takes two parameters. The first parameter is named as TRANSACTED, and its type is Boolean. 

If that parameter is True, then the session is transacted. The second parameter is named as ACKNOWLEDGE-MODE, and its type is integer. That parameter indicates whether the consumer or the client will acknowledge any messages it receives. Legal values are Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, and Session.DUPS_OK_ACKNOWLEDGE. In this question, since the message needs to be sent in a transaction, the first parameter must be True and the second parameter may have any value. So, the right option is B. The next question is about secure Java EE 7 applications. The question asks, which annotation allows a request to be executed with another Principal's identity? For this question, the right option is C. The RunAs annotation defines the identity of the application during execution in a J2EE container. This allows developers to execute under a particular role. The role must map to the user or group information in the container security realm. Its value is the name of a security role. The next question is about implement REST services using Jax-RS API. There is a code fragment. 

And the question asks, which URL triggers the invocation of the getStudent() method. Here, the path statement for id implies that id must match the regular expression starting at least a capital string, and continuing with at least a digit. By the way, /id is not required, let it not distract you. According to these given, the right option is C. The next question is about create Java web applications using Servlets. The question says, a developer created two filters for her web application by using the web filter annotation, one for narrowing results by the provided search criteria, and the other for authorization. The authorization filter must be invoked first. How can she specify this? Let's talk a bit about filters. As per section 6.2.4 of Servlet 3.0, if there are filters matched by Servlet name, and the web resource has a Servlet name, the container builds the chain of filters matching in the order declared in the deployment descriptor. The last filter in this chain corresponds to the last Servlet name matching filter, and is the filter that invokes the target web resource. If there are any filters using URL pattern matching, and the URL pattern matches the request URI, according to the rules of section 12.2, specification of mappings, the container builds the chain of URL pattern matched filters in the same order as declared in the deployment descriptor. 

The last filter in this chain is the last URL pattern matching filter in the deployment descriptor for this request URI. The last filter in this chain is the filter that invokes the first filter in the Servlet name matching chain or invokes the target web resource if there are none. Now, when we combine what we know, we understand that the correct answer is B. The next question is about implementing business logic by using EJBs. The question says, select True options regarding setRollbackOnly method of EJBContext. The right option is D. The next question is about managed persistence using JPA entities and validation. There is a code fragment, and the question asks, what code should be added to the body of the updatedStudent method in order to save pending changes to the database? The state of persistent entities is synchronized to the database at transaction commit. This synchronization involves writing to the database any updates to persistent entities and their relationships. An update to the state of an entity includes both the assignment of a new value to a persistent property or field of the entity, as well as, the modification of immutable value of a persistent property or field. Therefore, for a managed entity, no code is necessary to save changes to the database. However, if you want to save a detached entity, then you need to call merge. 

Further, if you want to persist the changes immediately, then you should either call flush on the entityManager, or commit the transaction. So, the right option here is D. The next question is about use Batch API in Java EE 7 applications. There is a job definition code given. And the question asks, how can be sent an email to a payroll manager at the conclusion of this batch job? For such jobs, that's needed to add another step element. So, the right option is D. The next question is about secure Java EE 7 applications. The question asks, which type of security credentials are included by Java EE Support for WS security? Some of security credentials included by Java EE support for WS security are, Kerberos, SAML tokens and X.509 certificates. So, there are two right options, D and E. The next question is about implement REST services using Jax-RS API. The question says, select valid description of REST. For this question, the right option is A. The specification defines a set of Java APIs for the development of web services built according to the representational state transfer architectural style. The next question is about implement business logic by using EJBs. 

There is a code fragment, and the question asks, what code should we add to line 1 for MyMapperBean bean instances to be correctly passivated? For this question, the right choice is, option B. The next question is about understand Java EE architecture. There is a code fragment, and the question asks, which annotation should be used to group multiple resource declarations together for class based injection, replacing XYZ in the code above? The Resources annotation is used to group together multiple resource declarations for class based injection. So, the right option is B. The next question is about create Java web applications using JSPs. The question asks, select True statements about the relationship between JavaServer Pages and servlets. There are two right options for this question. They are, A and B. The next question is about create Java web applications using JSPs. The question says, select valid JSP directives from below statements. JSP directives start with <%@ symbol combination. There are three types of directives, page, taglib, and include. When we look at the options, we see that there are two correct answers. 

They are, A and D. The next question is about implement SOAP services by using Jax-Ws and Jax_B APIs. There is a code fragment. The question asks, which method do you use on line 3 to enable default validation mechanism? Here we need to call setEventHandler method of UM object to enable default validation mechanism. So, the right option is D. The next question is about create Java applications using WebSockets. There is given a code block. The question asks, which client-side Java method will send the teacher object to the WebSocketServer Endpoint? Here, we need to call sendObject method of remote object. So, the right option is D. The next question is about UCDI beans. Given a code fragment, the question asks, which code would you add to register both of these methods to receive aeronautical weather event notifications only if an instance of aeronautical weather service is already instanciated in the current context. For this question, the right option is B. Observer methods can also be conditional or transactional. A conditional observer method is notified of an event only if an instance of the bean that defines the observer method already exists in the current context. To declare a conditional Observer method, specify notifyObserver=IF_EXISTS as an argument to Observes. The next question is about implement business logic by using EJBs. 

The question says they are creating an alarm management system. When they create a new alarm, they want to create an alert that is triggered once at the specified time. Which method should they call on Line 9 to create the timer? We use create single action timer method to create a single action timer that expires at a given point in time. So, the right option is D. The next question is about create Java web applications using Servlets. The question says you have an HttpServletRequest request, and an EJBSessionContext context, select the valid way to retrieve the Principal invoking either behavior. I need to say that HttpServletRequest has a method returning Principal. It is getUserPrincipal(). It returns a java.security.principalobject containing the name of the current authenticated user. If the user has not been authenticated, the method returns null.

EJB context has a method returning principal, it is getCallerPrincipal(). It obtains the java.security.principal that identifies the caller, so the right option is B. The next question is about develop web applications using JSFs. It says, you have been assigned to the Product Quality Editor portion of an application. It contains a ProductQuality Editor Facelet page, the ProductQuality class, and a simple ProductQualityEditor backing bean, which contains a reference to the current ProductQuality instance and gives some code blocks and says, the page prints conversion error when a user fills out the form field and click the 'Save Button' and at the end asks which steps should be performed to fix this problem? Here, it is needed a DateTime conversion pattern to avoid the error. So, the appropriate option is A.

The next question is about, develop web applications using JSFs. There is a Facelet page code fragment. The question says, on Line 1, you are asked to insert a search box that displays the text 'Search Now' via a placeholder. Assuming that find MB is a valid managed bean, select convenient options that enable you to create a search box with a placeholder. There are two right options here. First right option is C. Since xmlns:=p=txmlns.jcp.org//jsf// pass through is included, pt: placeholder will work. The other right option is D. In this approach, we are using html placeholder attribute and enhancing the html input tag with jsf using jsp:id and jsf:value attributes.

The next question asks, which class would be used to handle an incoming JSON message as a stream? For this question, the right answer is D. JSON parser provides forward read only access to JSON data in a streaming way. This is the most efficient way for reading JSON data. The next question is about manage persistence using JPA entities and bean validation. The question says, select options that can be a JPA entity. I need to say that Interface type, Enum type, and Final class cannot be a JPA entity, so option A, B, and C are not correct. Abstract class and Concrete class can be a JPA entity. The right options are D and E.

The next question is about managing persistence using JPA entities and bean validation. There is a code block from persistence.xml file. The question asks, what does this configuration represent about transactions management in the application? For this question, the right option is A. A transaction type of Resource_Local assumes that a non JTA data source will be provided. This means, the container won't be managing transactions for this resource and that you the programmer, has to manage transactions for it programmatically. This is done using entity manager factory. To get an entity manager, and then using entity transaction API, to begin or commit around every call to your entity manager. The next question is about implement business logic by using EJBs. There is a code fragment. The question asks, what should be done on Line 14 to abort the transaction? For this question, the right option is D. You must complete any transactions associated with that thread before beginning a new transaction. Here, we need to call roll back to complete the transaction. So, that's it. Have a nice day.

 

About the Author
Students
3900
Courses
64
Learning Paths
5

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.

Covered Topics