aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes EJB3 mock questions available now! (Section 2) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "EJB3 mock questions available now! (Section 2)" Watch "EJB3 mock questions available now! (Section 2)" New topic
Author

EJB3 mock questions available now! (Section 2)

Shoaib Khanzada
Ranch Hand

Joined: Jan 24, 2004
Posts: 34
Hi guys,

Following are few mock questions available about the section 2 of 311-091. I prepare these question to test myself and just to guess what could be asked in real exam. It might not be very difficult but could be helpful to test where you stand in section 2. (Ignore any compile time errors)

I will add further question about this section and other sections later.

Guess your answers and post them in reply of this thread.

------------------------------------------------------------------------
Section 2: General EJB 3.0 Enterprise bean knowledge
------------------------------------------------------------------------

Q1: If there is not any compile time error in the following bean what it will be print when client invoke someBusinessMethod first time?

@Stateless
Class MyBean implements IMyBean {

{
System.out.println(0);
}

Public MyBean() {
System.out.println(1);
}

@Postconstruct
Public void init() {
System.out.println(2);
}

Public void someBusinessMethod() {
System.out.println(3);
}

}

A.It will throw a RuntimeException because we can not use std out in bean
B.It will throw an EJBException because we can not use std out in bean
C.0, 1, 2
D.2, 0, 1
E.0, 1, 2, 3

Q2: What will be the result of invoking someBusinessMethod for the following bean?

@Stateful
class MyBean implements IMyBean {

{
System.out.println(0);
}

public MyBean(String str) {
System.out.println(str);
}

@Postconstruct
public void init() {
System.out.println(2);
}

public void someBusinessMethod() {
System.out.println(3);
}

}

A.0, 1, 2
B.Bean instance will not be created
C.0, 1, 2, 3
D.2, 3

Q3: Suppose someBusinessMethod is in or required transaction and timeout of bean occur, cleanup method will be called or not?

@Stateful
class MyBean implements IMyBean {

@Postconstruct
public void init() {
System.out.println(�bean initialized, opening connections��);
�..
}

@Predestroy
public void cleanup() {
System.out.println(�closing open connections��);
�..
}

public void someBusinessMethod() {
��
}

}

A.yes
B.no
C.EJBException will be thrown
D.IllegalStateException will be thrown
E.Stateful bean can not be timeout while in a transaction

Q4: A timeout occur while bean was in ready state. cleanup will be called?

@Stateful
class MyBean implements IMyBean {

@Postconstruct
public void init() {
System.out.println(�bean initialized, opening connections��);
�..
}

@Predestroy
public void cleanup() {
System.out.println(�closing open connections��);
�..
}

public void someBusinessMethod() {
��
}

}

A.yes
B.no
C.Stateful bean can not be timed out
D.Depends upon vendor implementation or container specific

Q5: Where dataSource injected resource will be available?

@Stateless
class MyBean implements IMyBean {

@Resource(mappedName=�myDataSource�) DataSource dataSource;

public MyBean() {
// here 1
}

@Postconstruct
public void init() {
// here 2
}

@Predestroy
public void cleanup() {
// here 3
}

public void someBusinessMethod() {
// here 4
}

}

A.2, 3, 4
B.2, 4
C.1, 2, 3, 4
D.Will be available in 2 and 4 but for 1 and 3 depends upon vendor implementation

Q6: What will be the output if someBusinessMethod is called?

@Stateless
class MyBean implements IMyBean {

public void someBusinessMethod() {
System.out.println(2);
}

@AroundInvoke
public Object doSomething(InvocationContext inv) {
System.out.println(1);
return inv.getTarget();
}


}

A.2, 1 will be printed
B.1, 2, 1 will be printed
C.1, 2 will be printed
D.Only 1 will be printed
E.It will throw an EJBException

Q7: How can I disable default and class interceptors for someBusinessMethod?

@Stateless
@Interceptors(MyInterceptor.class)
class MyBean implements IMyBean {

public void someBusinessMethod() {
System.out.println(2);
}

}

A.By using @ExcludeDefaultInterceptors
B.By using @ExcludeAllInterceptors
C.By using @ExcludeClassInterceptors
D.By using @ExcludeDefaultInterceptors and @ExcludeClassInterceptors
E.There is not way to override class interceptors

Q8: Which of the following statements are true about interceptors?

A.Interceptors are invoked in the same call stack of the business or life cycle methods
B.All Interceptors can throw checked or unchecked exceptions
C.Interceptors follow the life cycle of the bean for which they are being invoked
D.Interceptors can be given public, private, protected, or default access and they can be final or static.
E.Callback interceptors can not be declared as final or static

Q9: What will be the order of statements when someBusinessMethod will be called?

public class MyInterceptor1 {

@PostConstruct
public void initInterceptor(InvocationContext inv) {
System.out.println(�PostConstruct interceptor�);
inv.proceed();
}

@AroundInvoke
public Object wrapBusinessMethod(InvocationContext inv) {
System.out.println(�business interceptor1�);
return inv.proceed();
}

}

public class MyInterceptor2 {

@PostConstruct
public void initInterceptor(InvocationContext inv) {
System.out.println(�PostConstruct interceptor2�);
inv.proceed();
}

@AroundInvoke
public Object wrapBusinessMethod(InvocationContext inv) {
System.out.println(�business interceptor2�);
return inv.proceed();
}

}

@Stateless
@Interceptors({MyInterceptor1.class,MyInterceptor2.class})
public class MyBean implements IMyBean {

@PostConstruct public void init() {
System.out.println(�PostConstruct�);
}

public void someBusinessMethod() {
System.out.println(�business method�);
}

@AroundInvoke
public Object wrapBusinessMethod(InvocationContext inv) {
System.out.println(�local business interceptor�);
return inv.proceed();
}

}

A.local business interceptor, business method
B.local business interceptor, business interceptor, business interceptor2, business method
C.business interceptor, business interceptor2, local business interceptor, business method
D.order of statement is unknown
E.local interceptor can not be used with class interceptors

Q10: With the Q9 code in mind, What will be the order of statements when new bean instance is created?

A.PostConstruct interceptor1, PostConstruct intercept2, PostConstruct
B.PostConstruct interceptor2, PostConstruct intercept1, PostConstruct
C.order of statement is unknown
D.PostConstruct, PostConstruct interceptor1, PostConstruct intercept2

Q11: Which of the following statements are correct?

A.Timeout callback method can not throw application exceptions
B.Timer can be registered in setEntityContext
C.When multiple timers are registered and timed out the sequence of callbacks is unknown
D.Timout callback doesn�t run in any client�s security context
E.Timer survive the system crashes
Lawrence Johnbosco
Greenhorn

Joined: Dec 03, 2006
Posts: 21
Great effort Shoib,

Please find below my answers. I answered it as if I took the original exam -- didn't refer any notes or practiced anything , while answering these questions.

1) E. 0, 1, 2, 3
2) B. Bean instance will not be created
3) E. Stateful bean can not be timeout while in a transaction
4) A. yes
5) None of the answers are right. For stateless session beans the "Resource manager access" are available only in business method in this scenario. so the right answer should be 4)
6) E. It will throw an EJBException
7) D. By using @ExcludeDefaultInterceptors and @ExcludeClassInterceptors
8) All
9) C. business interceptor, business interceptor2, local business interceptor, business method
10) A. PostConstruct interceptor1, PostConstruct intercept2, PostConstruct
11) A,C,D,E
Benoît de Chateauvieux
Ranch Hand

Joined: Aug 10, 2007
Posts: 183
Hi Lawrence,

I don't understand your answer to Q6.
For me, it's "D. Only 1 will be printed".
Where do you think the Exception comes from?

Beno�t


SCJP5 | SCBCD5 | SCEA5 Part 1
Camilo Morales
Ranch Hand

Joined: Jul 14, 2007
Posts: 92
Hey Shoaib,

You may find many more mock questions and links to other mock examn in our study group. It would also be great if you could share your questions with us there, maybe as a text/doc/pdf file.

Here is the link:

[Christophe: Removed]

Regards,
[ September 13, 2007: Message edited by: Christophe Verre ]

Camilo Morales<br />SCJP 5, SCBCD 5
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Camilo, please check your private messages.


[My Blog]
All roads lead to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB3 mock questions available now! (Section 2)