Tuesday 27 December 2011

Critical Success Factors Of Object Oriented Frameworks

There are a lot of Frameworks out there. Making a decision on which one to use is sometimes extremely hard to do.

I found some rules at http://c2.com/cgi/wiki?CriticalSuccessFactorsOfObjectOrientedFrameworks, which I will summarize here for my convenience. (You didn't think I wrote this blog for you, do you?)

  • Iterative development
    changing requirements/uses/etc
  • Understandability
    nature of the framework, documentation
  • Quality
    faith of your users
  • Appropriateness
    time, skillevel of team, size, domain, use

Wednesday 14 December 2011

Netbeans Tips & Tricks

Contents

Netbeans 7.0.1. doesn't validate jdk 7.0 syntax in editor

Netbeans 7.0.1. doesn't start

How to automatically use a License in your new java files

Changing indentation style


Netbeans 7.0.1. doesn't validate jdk 7.0 syntax in editor

For example, editor complains about: "try-with-resources is not supported in -source 1.6 (use -source 7 or higher to enable try-with-resources)" in a try-with-resources block.

Right click project. Properties. Sources. Source-binary->jdk7. No problems after that.

Of course, there's still the problem that the new syntax in the JSP pages doesn't work.

Jk7 doesn't work with jsp pages yet, see http://java.net/jira/browse/GLASSFISH-17429 .


Netbeans 7.0.1. doesn't start

I just downloaded Netbeans 7.0.1 from http://www.oracle.com/technetwork/java/javase/downloads.

It didn't work.

No output on the console, either.

However, I was able to run Netbeans correctly from the root account.

It turns out that I had the settings of a previous version of Netbeans in my homedir. To wit:

  • .netbeans/
  • .netbeans-derby/
  • .netbeans-registration/

After removing said settings, netbeans started properly and created the setting directory .netbeans.

Hope it helps someone.


How to automatically use a License in your new java files

Add project.license=gpl30 (for example) to your project.properties file in nbproject directory of your project.


But there are easier ways to do it in Netbeans 7.4. Choose Project properties, select "License Headers" and just set the Global license to for example General Public License 3.0

Changing indentation style

To change editor settings.

Click the Tools > Options menu item.

In the icon display, click Editor.

In the right panel, select the category "Tabs and Indents" tab.

If it isn't already done, set the following:

Statement continuation Indent: 8

Number of Spaces per Indent: 4

Check Expand Tabs to Spaces.

In the right panel, select the category "Braces" tab.

If you like the Allman indentation style (like me), check the "New Line" for a Class declaration, Method declaration and Other.

References

NetBeans IDE
http://leepoint.net/notes-java/tools/netbeans/netbeans.html
Project-Level License Settings in NetBeans IDE 6.0
http://blogs.oracle.com/geertjan/entry/project_level_license_settings_in

Monday 12 December 2011

Implicit Default Constructor - good or bad?

Everyone who knows Java, knows that if you do not define a constructor in a class, the default constructor is implicitly created by the compiler.[1]

Is this a good thing or a bad thing?

Good thing:

  • we need a constructor to instantiate an object, and if we forget to make one we can simply use the default constructor.

Bad thing:
  • creating a new constructor with arguments, automatically will make the compiler NOT create the implicit default constructor, perhaps causing breakage in your program/application.

So, should we do the following?

package mrbear;

public class Main
{

    /**
     * Explicit Default Constructor. Required.
     * Defined here to prevent problems when
     * new constructor(s) with different arguments is/are added.
     */

    public Main()
    {
    }

}

I know for a fact, for example, that Hibernate requires entities to have some sort of default constructor, so Hibernate can create objects using reflection. [2]

You'd see something in the log like:

10:54:15,575 INFO [PojoInstantiator] no default (no-argument) constructor for class: mrbear.Main (class must be instantiated by Interceptor)

References

[1] Providing Constructors for Your Classes
http://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html
[2] Hibernate : Chapter 4. Persistent Classes
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/persistent-classes.html