Monday, December 15, 2014

IntelliJ shortcuts


I'm using IDE IntelliJ for the first time. Until now, my favorite IDE is Eclipse. Why am I trying IntelliJ? Because everyone that uses it says that it is much better than Eclipse. So, I'm trying it to see for my self.

First of all, I've downloaded the IntelliJ Community Edition, and after running it and setting up my Project, I'm faced with a new challenge: so, what shortcuts should I use?

IntelliJ welcomes me with a few shortcut:

IntelliJ shortcuts


  • Search Everywhere with Double Shift
  • Open a file by name with Ctr + Shift + N
  • Open Recent Files with Ctrl + E
  • Open Naviagtion Bar with Alt + Home
  • Drag and Drop file(s) here from Explorer

(I' ll adding useful shortcuts as long as I discover them)

Which IDE do you prefer? Eclipse? IntelliJ? Some other? Why?

Monday, November 24, 2014

Wiki Markup language in Atlassian Crucible


Atlassian Crucible is a collaborative peer code review tool, where you can leave comments about reviews created based on some commited code.
It allows the development teams to catch major defects, improve code architecture, and discuss desired improvements, without the need for meetings. With FishEye, it lets you view the contents of your Source Code Management (SCM) repositories in your web browser.


And, it supports integration with Jira, which is a very important thing about these collaborative tools. Integration is the key for a better handling.


The Crucible documentation, the FishEye documentation and the Jira documentation can be found at the Atlassian Documentation page.

Did you know that you can use Wiki Markup in Crucible, just like for incorporating some code block in the comments? Check out this Crucible Help page about the Wiki Markup and learn how it can be used.

Tuesday, October 7, 2014

How to create an ico file?

How to create an ico/png file?

It's very easy! Just follow these tutorial steps.

  1. Go to  http://converticon.com
  2. Upload your gif, jpeg or png file and press the "Export" button.
  3. Select the Export options, like sizes and type of the file to be exported: ico or png.
  4. Press the "Save As" button.


That's it! No need to download any software to make the ico file!

How to create an ico
How to create an ico
Tips:
If the purpose of the ico file is to be used as a favicon, export it with the 16x16 option selected.
If you want to change the icon on a folder, export it with the 32x32 option.

As an alternative, you can use the http://iconverticons.com/ online tool.

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.

Sunday, June 1, 2014

EJB 3.1 Message Driven Bean Lifecycle


MDB Lifecycle, from book "Oreilly Enterprise Javabean 3.1, 6th Edition"

EJB 3.1 Component Types

EJB 3.1 component types are:

  1. Session Beans
    1. Stateless Session Beans (SLSB)
    2. Stateful Session Beans (SFSB)
    3. Singleton Session Beans
  2. Message Driven Beans (MDB's)
  3. Entity Beans




  • The Stateless Session Bean does not preserve conversational state.
  • The Stateful Session Bean preserves conversational state and there is one instance of the session bean per client.
  • The Singleton Session Bean is new to the EJB 3.1 Specification. There is only one instance of this bean type.
  • The Message Driven Bean acts as an event listener. It cannot be called from the client.

For each Bean, there are lifecycle callbacks that must follow the pattern void <METHOD>().

EJB 3.1: Stateful Session Bean lifecycle



SFSB Lifecycle, from book "Oreilly Enterprise Javabean 3.1, 6th Edition"
Lifecycle events:
@PostConstruct
@PreDestroy
@PrePassivate
@PostActivate

With SessionSynchronization:
SFSB Lifecycle with SessionSynchronization, from book "Oreilly Enterprise Javabean 3.1, 6th Edition"
Programming Rules for Stateful Session Beans:

  • The Stateful Session Beans maintain conversational state, so the instance variables must be Java primitives or Serializable objects.
  • Since the SFSBs cannot be pooled like the SLSBs, there can be the risk of accumulating too many of them. So the client can explicitly request the removal of a bean by calling a method annotated with the @Remove annotation.

EJB 3.1: Asynchronous Methods

New to EJB 3.1, by using the @javax.ejb.Asynchronous annotation, we can achieve fire and forget invocations, useful when having long time processing methods. When the client needs to use the result, it can take use of the facilities provided by the java.util.concurrent.Future
We can use the @Asynchronous annotation on class level, so all the methods are asynchronous, or we can use the @Asynchronous annotation at the method level.

A void method can also be marked with the @Asynchronous annotation, but in this case, no exceptions will be delivered to the client.

@Asynchronous
public Future<String> doStuff(final String input){
    // do stuff and return
    return new AsyncResult<String>("myResult");
}


If the asynchronous method has a return type Future<V> and it throws an exception, the the client will get an ExecutionException when trying to retrieve the result.

Cancel a request:
The client can request a cancel on the Future<V> invocation, using
Future<V>.cancel(boolean mayInterruptIfRunning)

where the boolean parameter represents if the asynchronous method can see if the cancel was requested.
The asynchronous method can check if cancel was called by the client, by using the SessionContext.wasCancelCalled()

Retrieving the results:
final Future<String> futureTask= myEjbProxyReference.doStuff(input);
final String result= futureTask.get(10,TimeUnit.SECONDS); //should catch the TimeoutException

Please notice the if the get() method is called with no arguments, then the get() will block until the result is available. To be assure that the result is retrieved after an undefined amount of time, then the Future<V>.isDone() method should be called, to check if the asynch result processing was already finished.

Thursday, May 8, 2014

Text editors for log analysis

Notepad++
I usually use the Notepad++, that deals well with big files, allows me to search in all opened files, search on a folder, use a regular expression for the search and even allows the usage of plugins for extra-stuff, like validating XML.


Baretail
For checking the tail of a log that is being written, I like to use Baretail.

Otros Log Viewer
I have already tried Otros Log Viewer, that is good to filter by threads, but I found it difficult to use... maybe it's lack of practice with this tool.

Other text editors for log analysis that I would like to try:
- LogExpert
- Sublime Text

Sunday, March 23, 2014

EJB 3.1 Stateless Session Bean lifecycle

The SLSB (StateLess Session Bean) has a lifecycle with only 2 phases, the "Does Not Exist" and the "Method-Ready Pool" phase, because it does not preserve conversational state, which is the big characteristic of this EJB.

SLSB Lifecycle
SLSB Lifecycle, from book "Oreilly Enterprise Javabean 3.1, 6th Edition"

Life-cycle Events
@PostConstruct
@PreDestroy

When going from the "Does Not Exist" to the "Method-Ready Pool", the no-argument constructor is called by the contained; next the container proceeds with code injection where applicable and the calls the method that is annotated with the @PostConstruct annotation. It is not mandatory the presence of this method, but if it exists, then it can be called with a what-so ever name, but it need to be void, have no arguments and must not throw checked exceptions.

In the "Method-Ready Pool", the bean is ready to attend the execution of the business methods.

When the container decides to destroy the bean, the bean goes back to the "Does not Exist" state and the method annotated with @PreDestroy is called, if it exists. Like the @PostConstruct method, it follows the same rules: can have anyname, needs to be void, have no arguments and must not throw checked exceptions.

Tuesday, January 28, 2014

Easymock: matcher calls were used outside expectations

You are running your unit tests with EasyMock and then you face this kind of error "matcher calls were used outside expectations".

java.lang.IllegalStateException: matcher calls were used outside expectations
at org.easymock.internal.RecordState.replay(RecordState.java:86)
at org.easymock.internal.MocksControl.replay(MocksControl.java:169)


This happens because you are having some kind of code like this, where the .andReturn is not returning an object.
expect(mockdao.bark(EasyMock.anyObject(Dog.class))).andReturn(EasyMock.anyObject(Noise.class)));

To fix this, you should use the null return or return an instance of an object, or even a mock object:
expect(mockdao.bark(EasyMock.anyObject(Dog.class))).andReturn(new Noise()));

Sunday, January 26, 2014

Online Photo Editor: PicMonkey

Edit a photo, create a collage, easy, fast fearless photo embetterment! It's their slogan.
I've already tried and it is really easy to use.

Use the free photo editor PicMonkey (no registration is required) or use the Upgrade (Royale) that has ads-free editing, more glorious effects and exclusive designs! Register using this link and get one day of a Royale account!


This screenshot has been edited by PicMonkey in a few minutes.