image
Mock Exams in Java EE 7

Contents

Mock Exams
1
Exam Part 1
PREVIEW39m 24s
2
Exam Part 2
PREVIEW17m 15s

The course is part of this learning path

Exam Part 1
Difficulty
Intermediate
Duration
57m
Students
9
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

This question is about understand Java EE architecture. Which of the following are true about .war files?

Let's look at the options. Option A says some Java EE containers don't support .war files. That's not true because all Java EE containers support .war files. Option B says JAR command is used to package a .war file. That's true. Jar command is used to package  .JAR files as well as .war files. Option C says EJB components can be placed into .war file. That's true too. Enterprise Beans may be packaged within a war module as Java programming language class files or within a JAR file that is bundled within the war module. To include Enterprise Bean class files in a war module, the class files should be in a web.inf/classes directory. To include a JAR file that contains Enterprise Beans in a war module, add the JAR to the web dash inf/lib directory of the war module. Option D says you can place JCA components into a .war file. That's not true. JCA resource adapters can exist in JEE application containers but are not managed by it. They are definitely not part of a war. The next question is about implement business logic by using EJBs.

In this question, a code fragment is given and asked when will the timer go off. Before moving on to answer options, I want to talk about expression formats used in schedule annotation. The forward slash constrains an attribute to a starting point and an interval and is used to specify n seconds, minutes, or hours within a minute, hour or day. For an expression of the form X/Y, X represents the starting point and Y represents the interval. The wildcard character may be used in the exposition of an interval and is equivalent to setting X to zero. Intervals may be set only for second, minute, and hour attributes. For example, that expression represents every 20 minutes within the hour. Minutes=*/ 20. It is equivalent to minute = 0, 20, 40. The following expression represents every three hours starting at noon. Hour=12/3. We can use a dash character to specify an inclusive range of values for an attribute. Members of a range cannot be wildcards, list,s or intervals. A range of the form X-X is equivalent to the single-valued expression X.

A range of the form X-Y, where X is greater than Y is equivalent to the expression X dash maximum value, minimum value dash Y, i.e, the expression begins at X, rolls over to the beginning of the allowable values, and continues up to Y. The following expression represents 8 AM to 4 PM. Hour equal 8-16. The following expression represents Thursday through Monday. Day of week = 4-1. The following expression represents the 25th day of the month to the end of the month and the beginning of the month to the 5th day of the month. Day of month = 25-5. It is equivalent to the following expression. Day of month = 25-last, 1-5. It's time to go into the options. It's time to go on to the options. Here the right option is A. The timer will go off every 10 minutes between the hours four and six, on the second day from the end of the month. The next question is about create Java web applications using servlets. Here is given the code fragment and the question asks what output will be returned when this servlet is called a GET request. As you know, if there is a service method in a servlet, it is called. If it wouldn't exist and exist only doGet then doGet method will be called.

So, the right answer is option A. The next question is about implement REST services using JAX-RS API. The question asks which statement is true about JAX-RS resource implementation? Here, the right option is C. Resource classes are POJOS that have at least one method annotated with at PATH or a request method designator. The next question is about understand Java EE architecture. It asks, which component type would you not be able to use in a Java EE 7 application intended to be hosted by a server that supports only web profile? Here, the right choice is A because web profile includes EJB lite, and message-driven beans are not included in EJB lite. EJB lite API is composed of the following subset of the EJB API. Stateless, stateful, and singleton session bean components only, local business interface and no interface view only, container-managed transactions and bean-managed transactions, declarative and programmatic security, interceptors, local asynchronous session bean invocations, non-persistent EJB timer service, deployment descriptor support. The next question is about UCDI beans.

Here is given a code fragment and the query asks which type would be injected at runtime and referenced by the message holder variable. Here, the right option is A since the bean annotated with @Alternative is specified in alternative's element of beans.xml. It will be used. The next question is about create Java applications using web sockets. The query asks which WebSocket message types can be registered as handlers. There are two correct options here. B and C. The three valid WebSocket message types are text, binary, and pong. The WebSocket API limits the registration of message handlers per session to be one message handler per native WebSocket message type. In other words, the developer can only register at most one message handler for incoming text messages. One message handler for incoming binary messages and one message handler for incoming pong messages. The next question is about create Java applications using WebSockets. It asks which statement is true about the relationship between HTTP and WebSocket.

Option A says a WebSocket connection is a full-duplex HTTP session with message-handling support.

This option is not correct. WebSocket is a full-duplex connection, but it is not an HTTP session. It is a different protocol than HTTP. Option B says WebSocket and HTTP use the same port 80. This option is correct. Any WebSocket implementation must use HTTP for the initial handshake as mandated by the WebSocket protocol specification, RFC 6455. Option C says a WebSocket connection can be initialized by either client or server. That's not true. It can be initialized only by the client. Option D says a WebSocket connection uses HTTP protocol to exchange data with the browser. That's not true. HTTP is used only for the handshake. Once the WebSocket handshake is done, only the WebSocket protocol is used to exchange the data. So, the right choice option is B. The next question is about create Java web applications using JSPs. There is a SQL code tag here and the question asks, which directive would be required to resolve the SQL tag behavior? The right option is A. JSTL defines the URI http://java.sun.com /jsp/jstl/SQL for SQL-related tags. Option D could potentially be a valid directive if there is an SQL.tdl file in web inf directory.

However, since we are using the JSTL tags, the TDL is present in the JSTL JAR itself. I would like to explain a little more about this question. The value of the URI attribute is just a name that must be mapped somehow with either the actual TDL file or the JAR file containing the TLD file. Even if the value of the URI attribute is an absolute URL beginning with http://, the container does not download anything. The container does not download anything. Usually, the tag lib element of web.xml ties the URL given in the JSP page with either the actual TLD file or the JAR file containing the TLD file. In this case, taglib-uri should be the same as the value of the uri attribute of the taglib directive, while the tag lib location should point to the TLD file or the JAR file. However, a taglib JAR file can also specify the uris in the tag library descriptor, for the tag library contains using a uri element. If that is the case, you do not have to explicitly specify the taglib element in the web.xml. You can import this library in the JSP pages using the following taglib directory, %@taglib prefix=any prefix uri=http://www.abccorp.com/htmllib%. Note that the uri must be the same as the one given in the TLD file. The next question is about create Java web applications using JSPs. It asks, which of the following approaches would result in the system locale being added to the output of a JSP? Let's inspect options. Option A is not true because it gives compile error. Option D is not true too. It will print the system locale in the servlet log file. Options B and C are true. 

The next question is about develop web applications using JSF. In this question, it has been asked to implement internalization in your JSF web application. Where do you configure the supported locales? Here, option A and C are correct. I want to say that if you define multiple locale in faces-config.xml, you need to create a different message dot properties file for each of them. The next question is about create Java Web applications using servlets. It asks, which option allows you to share surveillance attributes across your entire web application? Let's have a glimpse on options. Http sessions in option B is not correct because attributes stored in the session are only shared while the session is alive and only with the resources that are participating in the session. ServletConfig in option D is not correct too. Parameters in ServletConfig are also shared across the entire web application. However, these are parameters specified in web.xml and not attributes. You can't change them. ServletResponse in option C is not correct either. It is obviously a misleading option. Here, the right option is A. The next question is about create Java applications using web sockets. It says, you need to interchange large binary messages using chunks in a websocket application. Select ways in which you can receive partial messages. There are two correct options in this question.

One of the correct options is C, using a class extending MessageHandler.PartialByteBuffer. You can declare such class like this. The other correct option is D. Defining an @OnMessage method with byte as the first parameter and a boolean as the second. You can define it like this. The next question is about understand Java EE architecture. It says, select options that cannot be injected by using an @Inject annotation. Before looking at options, I want to talk about injectable fields and methods. We can list properties of injectable fields like this: are annotated with @Inject, are not final, may have any otherwise valid name different from inject. And we can list properties of injectable methods like this: are annotated with @Inject, are not abstract, do not declare type parameters of their own, may return a result, may have any otherwise valid name, accept zero or more dependencies as arguments. So, we can see that option B and D cannot be injected. 

The next question is about implement rest services using JAX RS API. It asks, which URLs represent a valid approach to pass a parameter to arrest resource? Option A is a valid usage. Query parameters appear in the URL after the question mark, after the resource name. Option B is not true. You can concatenate multiple parameters using ampersand symbol, but you cannot start a query parameter with an ampersand. Option C is true; template parameters appear in resource paths. They give API developers a flexible way of parameterising resources. Option D is not true. @ doesn't define a parameter. So, option A and C are true. The next question is about manage persistence using JPA entities and a bean validation. Here, a JPQL code is given. The question asks, which clauses can you add to this JPQL query to retrieve only those employees with between 7,000 and 7,500 salaries? Option A is not true. It has error either logically or syntactically. You cannot use max or min aggregate functions in where statements. Option B is not true. It has error logically. It doesn't give us what we want. Option C and D are true. The next question is about create Java Web applications using servlet. It is given a code fragment and the question says, identify the URL patterns against which this servlet will be mapped. Here, option B is true. As per servlet specification, URL patterns when specified in a descriptor for a given servlet name, overrides the URL pattern specified via the annotation. The next question is about implementing business logic by using EJBs.

A code fragment is given and the question asks, which annotation should be used on line one to ensure that clients immediately time out when attempting to concurrently invoke callfirstmethod() while another client is already accessing the bean. Here, the right option is B. The bean provider may optionally specify that concurrent client requests to a state full session bean are prohibited. This is done using the access time out annotation or the access time out deployment descriptor element with a value of zero. In this case, if a client invoked business method is in progress on an instance when another client invoked call from the same or different client arrives at the same state full session being instance, if the second client is a client of the bean's business interface or no interface view, the concurrent invocation must result in the second client receiving the javax.ejb.concurrentaccess exception.

By the way, given an option D, an access time out value of -1 indicates that a concurrent client request will block indefinitely until it can proceed. The next question is about use concurrency API in Java EE 7 applications. Here, a code fragment is given. The question asks, how many times does the submitted task run? In this query, the right option is A because it should be given more details to solve the problem. The next question is about develop web applications using JSF. Here is given a code fragment. The question asks, which steps when performed independently enable the index.xhtml page to print the following text? The user Id is 5432. Here, the right option is B. We can enable the index.html page to print the text by injecting set user method. The next question is about use concurrency API in Java EE 7 applications. It asks, how can you limit, in a portable way, the number of threads used by a ManagedExecutorService? The right option is C. We can configure the number of threads by configuring the thread pool info in the deployment descriptor. The next question is about create Java web applications using JSPs. It asks which code fragment shows that the page you are designing is capable of handling errors? The right option is B. A JSP is considered an error page if it sets the page directives isErrorPage attribute to true. Default value of this attribute is false. If a page has isErrorPage set to true, then the exception implicit scripting language variable of that page is initialized. The next question is about use CDI beans. A code fragment is given and the question asks, how do you specify to use this mock CDI bean implementation instead of the regular implementation class?

The right option is C, the alternative version of the bean is used by the application only if that version is declared with alternative tags in the beans.xml file. If the alternatives elements is commented out in the beans.xml file, the real implementation for SoundFileEditor class will be used. The next question is about create Java web applications using servlets. Here, a few lines of code fragment are given. The question asks, how long does the declared cookie persist? Here, setMaxAge method sets the maximum age in seconds for this cookie. A positive value indicates that the cookie will expire after that many seconds have passed. Note that the value is the maximum age when the cookie will expire, not the cookie's current age.

A negative value means that the cookie is not stored persistently and will be deleted when the web browser exits. A zero value causes the cookie to be deleted. So, the right option is B, because of negative value of setMaxAge parameter. The next question is about create Java web applications using servlets. A code fragment is given. The query asks, when the context root is requested, http://host:port/context, how does the container resolve this mapping? As per section 12.2, specification of mappings of servlets, if the effective web.xml after merging information from fragments and annotations, contains any URL patterns that are mapped to multiple servlets, then the deployment must fail. So, the right choice here is option D.

The next question is about implement business logic by using EJBs. The question says, select true options about Message-Driven Beans. Here, the only true option is B. Only the not_supported and required transaction attributes may be used for Message-Driven Bean message listener methods. The use of other transaction attributes is not meaningful for Message-Driven bean message listener methods because there is no pre-existing client transaction context and no client to handle exceptions. The next question is about managed persistence using JPA entities and bean validation. There is a code fragment, and the question asks, how can you apply MyDateConverter to the registrationDate field? The right option is A. If the autoApply element is specified as true, the persistence provider must automatically apply the converter to all mapped attributes of the specified target type for all entities in the persistence unit, except for attributes which conversion is overridden by means of the convert annotation or xml equivalent.

The next question is about create Java Web applications using JSPs. The question asks, how do you declare a default error page in your web.xml file? If an error page element in the deployment descriptor does not contain an exception type or an error code element, the error page is a default error page. With that in mind, when we look at the options, we see that option C is true. If you specify an error code, the error pages served only related error occurred. The next question is about create Java web applications using JSPs. The question asks, which code fragment prints the exception error message as part of the page output? Let's look at options. Option A is a valid option and it prints the error message. Option B doesn't work because message is not a public variable in exception and you cannot use it directly. Option C doesn't give us what we desired. It is a valid script line but it will not print anything. Option D is not true option too. Error is not a valid variable name for an implicit variable. So, the right choice is option A. The next question is about implement SOAP services by using Jack's WX and Jack's B APIs. It asks, which statement is true about the WS-Security standard? Before having a glimpse at options, I want to talk about Web Services-Security. Web Services-Security, WS-Security, WSS is an extension to SOAP to apply security to web services.

The protocol specifies how integrity and confidentiality can be enforced on messages and allows the communication of various security token formats such as Security Assertion Markup Language( SAML), Kerberos and X.509. Its main focus is the use of xml signature and xml encryption to provide end-to-end security. The following summarize the Web Service-Security requirements. The use of transport security to protect the communication channel between the web service consumer and web service provider. Message level security to ensure confidentiality by digitally encrypting message parts. Integrity using digital signatures and authentication by requiring a username X.509 or SAML tokens. So, the correct option is D. Basically, it provides message-level security. The next question is about implement business logic by using EJBs. There is a code fragment here. The question asks, if an exception is thrown inside the if block, what will happen with the transaction?

Option A says the transaction will be rolled back. An application exception does not affect the transaction unless it has been specified as causing rollback. So, option A is not correct. Option B and C can't be drawn from given code, so they are also false. The most proper option for this question is D. The next question is about secure Java EE 7 applications. The question says, you want to allow one set of roles to POST to a resource and another set of roles to GET it. Which configuration option should be used? When we look at the options, we easily eliminate option C and D because it is not enough of being neither a single @HttpMethodConstraints annotation nor a single web resource collection. Right options are A and B and you can implement it like this. The next question is about managing persistence using JPA entities and bean validation. The question says, a Persistence application locks entity xyz with a LockModeType.PESSIMISTIC_READ lock type. Select true statement about this situation. Here, the right choice is option C. The next question is about implement business logic by using EJBs.

There is a code fragment here and the question asks, how are transactions managed? The right option is C. I need to say if session mode is set to JMSContext.SESSION_TRANSACTED, then the session will use a local transaction which may subsequently be committed or rolled back by calling the JMS context's commit or rollback methods. The next question is about develop web applications using JSFs. There is a piece of code and the question says, a user clicks the button and submits the form and no errors occur while processing the request. Please select true statements. The right option is C. That's because the action listeners are always invoked before the action in the same order as they are being declared in the view and attached to the component, while an F:AJAX listener is always invoked before any action listener. The next question is about use CDI beans. The question says, a developer is building user profile page of an application. 

A user can change values such as his or her name, password, address, company, and so on. These values are sent to a CDI backing bean via AJAX when the user tabs out of each field. However, the values must be retained in the CDI bean and stored in the database only when the user clicks the "Save" button. Which of the following scopes will allow the CDI bean to retain its state while the user is interacting with the User Profile page? One of the right options is A. When this annotation along with the javax.inject.name is found on a class, the runtime must place the bean in a CDI scope such that it remains active as long as navigation handler dot handle navigation does not cause a navigation to a view with a view ID that is different than the view ID of the current view. The other right option is E. This scope exists longer than the view scope but will do the job in this case. The next question is about understand Java EE architecture. There is a code fragment, and the question asks, when you make a HEAD request, what will be the response?

The right option is A. In JAX-RS, an incoming HTTP HEAD request is handled by a target resource method successfully if: the resource method is annotated with @HEAD, the resource method annotated with @GET. In this case, any returned to entity is discarded for HTTP HEAD request. The next question is about UCDI beans. A code fragment is given, and the question asks, assuming this bean is only used in the code above, how long will the injected ExampleCDIBean instance be available. Option A is the only right option.

Bean is a non-contextual instance, and it exists until the containing bean is destroyed. In this case, the service object itself is a contextual object and will last for the lifetime of the session. The next question is about implement soap services by using JAX-WS and JAXB APIs. The question says, select true statements about Java methods that are exposed as web service operations by using JAX-WS API. Before moving on to the operations, I want to remind a few things. When starting from Java, the developer must provide the JAX-WS tools with a valid endpoint implementation class. This implementation class is the class that implements the desired web service. JAX-WS has a number of restrictions on endpoint implementation classes. A valid endpoint implementation class must meet the following requirements. It must carry a Javax.jws.web service annotation. Any of its methods may carry a javax.jws.web method annotation. All its methods may throw java.rmi.remote exception in addition to any service-specific exceptions. All method parameters and return types must be compatible with the JAXS B 2.0 Java to xml schema mapping definition.

A method parameter or return value type must not implement the java.rmi remote interface either directly or indirectly. So, considering what I've mentioned, we easily see that the right option is B. The next question is about create Java web application using surveillance. A code fragment is given. The question asks what should be done at line 1 to enable the servlet receive request data without blocking? Let's look at option B first. It is not correct. The dispatch method dispatches the request and response objects of this AsyncContext to another resource. It has nothing to do with callable and managed, executer service. Option C is not correct. An AsyncListener is used if you want to be notified in the event that an asynchronous operation initiated on a servlet request to which the listener had been added has completed, timed down, or resulted in an error. Option D is not correct either. That method can't provide the servlet to receive or request data without blocking. Here, option A is correct. The next question is about develop web applications using JSFs. It asks, select valid flow/s of view IDs through the application. There are two correct options.

They are B and C. The next question is about create Java web applications using servlets. It asks, how can a servlet specify to the browser that cookie data should be sent over a secure connection? The right option is B. The setSecure method indicates to the browser whether the cookies should only be sent using a secure protocol, such as HTTPs or SSL. The default value is false. You should run it with true parameter to enable sending data over secure connection. The next question is about implement business logic by using EJBS. The question asks, there is a system using JMS publish-subscribe operations. What happens when a producer publishes a message to a topic for which a durable subscription exists but there are no subscribers available? The right option is A. The next question is about develop web applications using JSFs. It says, there is a JSF application. When handling a JSF request, the application code decided to redirect the call to another URL by using HTTP redirect. Which action should be taken to correctly compile the handling of the JSF lifecycle? We need to choose option =D to complete the handling of the JSF lifecycle correctly.

The next question is about secure Java EE 7 applications. It asks, which of the following capabilities are supplied by the Java Authentication and Authorization Services (JAAS) API? There are two correct options here. Option C and D. Option C is provided by authentication part and option D provided by authorization part. The next question is about understand Java EE architecture. The question says, let's assume your Java EE application using an EJB container must communicate with the legacy system developed using non-Java technologies. Which of the following Java EE technologies can you use in the integration tier of the application? There are two right options. B and C. At first glance, option B may not seem right, but it is. The new Java application can remain decoupled with the legacy application by sending messages to the message driven bean. The next question is about managed persistence using JPI entities and bean validation. It asks, when does a JPA entity need to implement the serializable interface? Here, the right option is C. That's because if an entity instance is to be passed by value as a detached object, the entity class must implement the serializable interface. By the way, option D may seem correct, but it is not because only the primary key class must always be serializable in JPA entities.

 

About the Author
Students
2748
Courses
64
Learning Paths
4

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