Motivational quote of the day

Often people attempt to live their lives backwards: they try to have more things, or more money, in order to do more of what they want so they will be happier. The way it actually works is the reverse. You must first be who you really are, then, do what you need to do, in order to have what you want.

Margaret Young

Explanations of common Java exceptions

Lets have some geek fun:

Here are some nice explanations of the most common java exceptions like:

ConcurrentModificationException = Someone else has modified your Java code. You should probably change your password.
IndexOutOfBoundsException =  You have put your index finger in an unacceptable place. Reposition it and try again.
RuntimeException = You cannot run fast enough, possibly due to obesity. Turn off your computer and go out and get som exercise.
NumberFormatException =  You are using outdated units of measurement, for example inches or pints. Convert to SI. There is a known bug that causes this exception to be thrown if you are very short or tall.

…and much more you cane find at http://rymden.nu/exceptions.html

Have fun

N

OSGi…on and on…

Since I am big fan of OSGi platform, here I come with yet another set of links published by Kirk Knoernschild on he’s blog:

<Transcript from http://eclipse.dzone.com/news/osgi>

Why OSGi

Here are some posts that describe the motivating factors behind OSGi.

  • Rotting Design – Discusses how a system’s design tends to rot as change occurs, and what we can do about it. Introduces OSGi at the end of the post.
  • Java Components & OSGi – My first “official” OSGi post where I talk about JAR files as components on the Java platform.
  • Enterprise OSGi -The advantages of what OSGi will bring to Enterprise development. We certainly aren’t here yet, but this is the direction things are moving.
  • JAR Design over Class Design – An indication of how few development teams spend time designing JAR files. Very unfortunate, but true.

How OSGi

Here are some posts describing how to use OSGi. They are simple tutorials.

  • Simple OSGi Service – The simplest OSGi service just to show the basics of OSGi. A good “getting started” guide if you’re not familar with OSGi.
  • OSGi & Modularity – Uses the OSGi service registry and separates interface from implementation to create a module that can be replaced with another without restarting the system.
  • OSGi & Spring – Shows how Spring Dynamic Modules can be embedded in an OSGi runtime (Felix) and OSGi services registered with the service registry. Spring takes care of registering the services, so that application code has no dependencies on the OSGi API.
  • OSGi & Embedded Jetty – A simple tutorial showing how Jetty can be embedded in OSGi. The example is fully functional and can be checked out of my Google Code SVN repository. I used Felix for the example, but also tested it under Equinox.
  • Embedding OSGi in Tomcat – A tutorial that shows what’s necessary to embed OSGi in an application server. This is the inverse of OSGi and Embedded Jetty.

OSGi Market

Here are some posts on the OSGi market.

 <End of transcript>

The original article can be found here.

Happy coding

N

Eclispe IDE Tip: Speed-up Eclipse startup

I was just reading some article related to Eclipse and OSGi plugin and bundle concepts, and found a nice tip of optimizing the Eclipse boot time and also spare some used memory too.

In the Eclipse runtime there a extension point defined specially to handle the early activation of some code/bundle. This extension point is called org.eclipse.ui.startup and causes preinitialization of all the implementors (extenstions) right before the Eclipse UI is started. There are several plugins which do implement this extension point and hereby are always starting up even if You don’t use them.

It seams that there is a simple way of managing these extension to be started or not at boot time:

If you open the Window>Preferences… and go to General/Startup and Shutdown, there is a list of the plugins activated at startup, which can be checked or uchecked if needed. This is a really cool feature. ;-)

I have deactivated some of the plugins from there which I don’t use on daily basis and it seams like my Eclipse is starting up a bit faster. (Or it just seams like ;-) )

Happy coding,

N

To Assert or Not to Assert

And one more for you:

Do you use the Assertion framework defined in java language? If so than what for?

I kind of have a problem with this, since the first time I ran into this assertion functionality was way back when only JUnit had this implemented. And I have to admit that it is the most simple and powerful code FOR UNIT TESTING.

Now that we have assert keyword in Java, I still do not see the point of having an assertion in the regular code instead of a simple if statement.

Now let me demonstrate one thing. Which is more readable?

public MyClass(String name) throws  IllegalArgumentException{

   if(name == null){

      throw new IllegalArgumentException("Name cannot be null");

   }
  // the rest of the code

}

or

public MyClass(String name) {

   assert (name != null);

   // the rest of the code

}

Another thing, which of the above examples will imply the  necessity of defining the thrown Exception in the javadoc? That leads to my previous post How Not to Write Java Documentation…

Well, I personally like the first approach (You know I am kind of old fashioned).

As much for the using the Assert (as junit.framework.Assert) class from JUnit framework in a class not belonging to a test case, I only can say: Oh nooooooooo!!!
JUnit is meant ONLY for module testing purpose(at least I like to consider this), and not for regular java code usage.  It is kind of mixing apples with oranges…or something.

And now read the article of Misko Hevery posted on Javalobby: http://java.dzone.com/articles/assert-or-not-assert

Happy coding,

N

How Not to Write Java Documentation…

Back to “how not to” series.

Today I found a more or less funny article about this topic.

I think that most of us Java developers have spent tons of hours reading badly written javadocs (in the lucky case), and we can tell long stories about these memories.
Even if you consider yourself an experienced developer sometimes you can fall into a trap put by an outdated javadoc comment.

I personally have developed an interesting habit: don’t read javadoc only if it is longer than the autogenerated joavadoc, and instead use JadClipse and decompile the code. It kind of spared me a lot of time. In Eclipse it is very easy to have a class decompiled, so don’t need to leave the IDE, but for those developing in other environment this is also possible using external tools like Front End Plus and others.

One thing is true: badly written code is even worse in a decompiled format, but most of the time for me it was even educative to see different coding approaches.

So my advice, ignore the Javadoc reading in case of too short text and go directly to decompiling of the code.

Read the whole article at http://java.dzone.com/news/how-not-write-java

Happy coding

N