Thursday, July 10, 2014

I'm an OCE JEE6 1Z0-895 Certified!

I've passed the exam for 1Z0-895 Java Platform, Enterprise Edition 6 Enterprise JavaBeans Developer Certified Expert with 83%!


My training materials were:

1. Enterprise JavaBeans 3.1 (the most recommended book, ignore JPA chapters, this is the Bible from where to learn all the exam topics, but it's incomplete concerning the deepness of needed knowledge - complete the knowledge from the EJB 3.1 specification!)
Andrew Lee Rubinger, Bill Burke
O'Reilly Media; Sixth Edition edition (September 24, 2010)

2. EJB 3 in Action (EJB 3.0, ignore JPA chapters, I don't remember what I learned from this book that I didn't learned with the O'Reilly book. Be aware that in version 3.0 there are no singletons, so this book does not mention it)
Debu Panda, Reza Rahman, Derek Lane
Manning Publications Co.; 1st Edition

3. Head First EJB (EJB 2.0, just for the basic concepts, like the EJB Roles and how to understand the "equals" between EJBs - ignore EJB 2.0 specific stuff)
Kathy Sierra, Bert Bates
O'Reilly


4. OCP JavaEE 6 EJB Developer Study Notes by Ivan A Krizsan (very complete! Read it! Learned the structure of an .ear and .jar from here and also the Exceptions tree structure for distinguishing between Application Exceptions and System Exceptions)

5. Frits Walraven OCPEJBD 6 EJB3.1 (a very good short study notes! I became aware of the "equals" questions between EJBs from here. If you know all the topics mentioned here, then you should be prepared for the exam)

6. JSR-000318 Enterprise JavaBeansTM 3.1 Final Release (The EJB 3.1 specification: it has all the needed information but it is really hard to read, but it must be read to complement the knowledge)

7. Interceptors 1.1 (The EJB 3.1 Interceptors specification: It's very quick to read!)

8. Enthuware 1Z0-895 exams (some questions are very similar to the real exam, really good software for practice! I was getting around 80% in this software and I got 83% in the real exam!)

After all this study, if you are passing in Enthuware exams, then you should pass on the real exam!
Good luck!

Sunday, June 22, 2014

EJB 3.1: Transactions and Exceptions

It confuses me a bit how transactions and exceptions get together in the EJB specification.
It always depends on the transaction type (CMT or BMT), the type of the bean (Session or MDB), and the type of the exception (Application or System Exception).

The O'Reilly Enterprise JavaBeans 3.1 book summarizes this into some tables. I hope that this can help you like it has helped me about how to think about the transactions and exceptions.

For Session and Entity Beans:


For MDBs:

Chef Programming Language

I love all these esoteric programming languages!
Chef is a programming language where your programs look like a recipe!
You can have measures like cups and tablespoons, use liquid ingredients (output as unicode characters) while dry or unspecified will output numerics, to be put on a mixing bowl (which acts like a stack) or a baking dish!

The recipe starts with a title of the dish, which is a short description of what the program does.
Next we have the ingredients, which represent the variable declarations. Next, the method, that contains the real recipe instructions, like "take ingredient from refrigerator" which means to read a numeric from an input.

Check on DangerMouse for the language specification.

Here is the "Hello World Souffle" example:


Hello World Souffle.

This recipe prints the immortal words "Hello world!", in a basically brute force way. It also makes a lot of food for one person.

Ingredients.
72 g haricot beans
101 eggs
108 g lard
111 cups oil
32 zucchinis
119 ml water
114 g red salmon
100 g dijon mustard
33 potatoes

Method.
Put potatoes into the mixing bowl. Put dijon mustard into the mixing bowl. Put lard into the mixing bowl. Put red salmon into the mixing bowl. Put oil into the mixing bowl. Put water into the mixing bowl. Put zucchinis into the mixing bowl. Put oil into the mixing bowl. Put lard into the mixing bowl. Put lard into the mixing bowl. Put eggs into the mixing bowl. Put haricot beans into the mixing bowl. Liquefy contents of the mixing bowl. Pour contents of the mixing bowl into the baking dish.

Serves 1.

Tuesday, June 10, 2014

EJB 3.0: Mapping between annotations and XML elements

This table is not specific for EJB 3.1, it misses some new stuff like the Singleton annotation, but it is pretty cool to have an idea of the mapping between XML elements and annotations.


EJB 3.1 Timer Service

We can inject the Timer Service using:

@Resource TimerService timerService;

Then we create the Timer and we can attach an object to it:

public void doSomething(SomeObject obj){
//...
timerService.createTimer(15*60*1000, 15*60*1000, obj);
}

The createTimer can have 4 different signatures. In the used signature, the first parameter represents the time after which the timeout should be triggered, after the method invocation. The second parameter represents the repetition period and at last, the last parameter is the object that can be attached to this timeout (it must be a Serializable object) The other signatures concerns to a single-event timer with no repetition, by receiving a long value (in miliseconds) or a Date object, and the other concerns to a timer event with repetition, but the first parameter is a Date instead of a long.

When the timer is triggered, it calls the method that is annotated with the @Timeout annotation.

@Timeout
public void methodName(Timer timer){
SomeObject obj = (SomeObject) timer.getInfo();
//...
}

The signature for the method annotated with the @Timeout annotation must have the following signature:

void <METHOD NAME>(Timer timer)

Accessing the Timer Service
Instead of injecting the Timer Service, we can retrieve it from the Session Context:

@Resource SessionContext ctx;
//...
TimerService service = ctx.getTimerService();


Monday, June 2, 2014

EJB 3.1 Interceptors

Interceptors implementation can be found where @AroundInvoke annotation is declared. The @Interceptors annotation should be used to say where it could be found the interceptor(s) implementation and to where should be applied (could be at class level or method level).
E.g
@Interceptors(Impl.class)

The method where @AroundInvoke is applied, should have the following signature:
Object <METHOD>(InvocationContext) throws Exception

The @AroundInvoke method should contain a invocationContext.proceed() invocation, in order to allow the execution chain to go on.

A default interceptor can be declared (only at the deployment descriptor file):
<assembly-descriptor>
  <interceptor-binding>
    <ejb-name>*</ejb-name>
    <interceptor-class>actionbazaar.buslogic.ActionBazaarLogger</interceptor-class>
  </interceptor-binding>
</assembly-descriptor>

The default interceptor can be disabled, at the class or method level, using the @javax.interceptor.ExcludeDefaultInterceptors
The class interceptor can be disabled, at the method level, using the @javax.interceptor.ExcludeClassInterceptors

EJB 3.1 Exceptions



SessionContext is used for Session Beans.
MessageDrivenContext is used for Message Driven Beans.