Let the Programming Begin: Generics with Java, Javadoc’s @version Tag.

This past week marked the start of my re-entry into the world of Java programming. My first assignment in CP213: Introduction to Object-Oriented Programming was due today. I learned a few neat things while doing this assignment so I’m going to try to outline some of them in this post.

  • Java has a very useful feature called Generics, and Eclipse will yell at you if you don’t use it.
    Generics allows you to define classes without a specified type. Instead, you can specify the type of an object by parameterizing it when it is initialized. This ensures that only objects of the specified type are inserted or removed from the initialized object. For this example I’ll use a stack:

    Stack<String> = new Stack<String>();

    As I’ve mentioned before, Eclipse is a very useful IDE, and thus is very strongly suggests parameterizing your stacks.

    Type Safety Warning

    Using code such as the above will yield the following:

    “Stack is a raw type. References to generic type Stack<E> should be parameterized”

    This can be easily fixed by parameterizing the code, as mentioned above.

    Parameterized

    Not only will Eclipse not yell at you for using the latter code versus the former, but the latter will help ensure that only the appropriate data is inserted and removed from the stack.

  • When using Javadoc, don’t use the @version tag.
    After struggling with Javadoc for a while trying to figure out why it wouldn’t properly display the version tag, just as a displays the author tag, I decided to do a little bit of googling on the subject. Eclipsepedia gave me a simple answer.

    @version Tag

    Using the @version tag sort of works, but it doesn’t look as nice as the @author, or any of the other tags.

    Javadoc with @version

    Does anyone know of any way to get this to work properly? It does make sense to have a version tag for classes, so I’m not sure why it doesn’t work properly.

That about wraps it up for the tips I learned from this assignment. As I hack around with Java more, I’m going to try to post various tips that I come across.

If anyone has any tips to add to the above, or information pertaining to the @version tag, please let me know.