mercoledì 15 settembre 2010

Log log log and always log !

No maters which tool you use, but you MUST log !

If you develop an application of more then 3 lines of code (and do not participate to a Java Compact Code Competition), at least one every 5 should be a log line.

The worst parts of programming are documenting and then logging, specially because most time we add add and add logging during the troubleshooting of bugs, but then we never rationalize them and so thousands of useless logs are generated and the really useful few ones got lost in an ocean of noise.

The core of a good logging is the choose of the right detail and information you put into the messages, and of a tool that enable you to easily  activate and set the needed level at runtime with out overloading too much the execution of the application.

As almost all the technical works you must find the right equilibrium between too much and too few, and you can only use your thumb as a meter.

But you MUST always keep in your mind the good old rule:

venerdì 10 settembre 2010

Errors and Exceptions....

Seems a simple argument, but often junior programmers ignore that there are Errors!
Exception handling mechanism is well known, but the fact that Exceptions are one of the two separate sub-groups of the Throwable class is not often mastered.
The result is that often we catch exceptions but ignore errors.
Is just a little thing we have to keep in mind, mainly if your programs execute inside complex environmets.
Infact an unmanaged error could cause the whole JVM to close while you think that you have managed all the possible exceptions.

Yes: you managed all possible exceptions, but not a single error ! ;)

But there is a good news for all of you folks : Errors are exactly as Exceptions, so you can manage them the same way !

So why do we have two different groups ?
Becouse Exceptions are things you should not make to happen but must manage inside of you, while Errors are lightings hitting you when you can't do much to protect yourself.... as OutOfMemoryError !

But no metter the difference between the two group, let's manage even Errors, it's not so difficult after all:

catch(Exception ex)
catch (Error er)

Have a lot of fun with your JavaCode!

venerdì 3 settembre 2010

Welcome to my Java Experience Blog

Welcome to my Java Experience Blog, where I'd like to share what I've learned in many years of  Java Development.

I hope you'll find some good tricks and why not even some usefull source code.

Keep connected and maybe I'll try to even add something you ask for, taking a Java Rabbit out of my hat !