Archive for the 'Java' Category

Java 1.5 and String operators

Thursday, October 28th, 2004

Java 1.5 changed the implementation of StringBuffer and introduced a new StringBuilder (actually both inherit from AbstractStringBuilder). It looks + operator can be either compiled to use StringBuffer (slower, but synchronized) or StringBuilder (faster, thread unsafe). (more…)

Java access modifiers

Thursday, October 28th, 2004

Just a reminder:

  • package protected - Scope that indicates that an instance variable is visible to other classes within its same package, or to subclasses of the class containing the instance variable. This scope is the default scope in Java, and is indicated by no scope indicator.
  • private - Scope indicator that hides an instance variable from all other classes, regardless of their package or their class hierarchy relationship to the class containing the variable.
  • protected - Scope indicator that makes an instance variable visible to subclasses that inherit from the class containing the instance variable.
  • public - Scope indicator that makes an instance variable visible to any class, regardless of package or class hierarchy relationship to the class containing the instance variable.

AspectJ in ANT

Wednesday, October 27th, 2004

Supposedly works, and there are three ways of doing it. Note that there can be a problem when using it with Javac and source lists:

“Beware of using regular source lists with this; javac may prune unchanged files, which excludes them from the compile process for ajc, which requires that all files affected by any aspects be listed explicitly.”

I haven’t tried it yet, but it looks like a nice thing to know.

XDoclet

Wednesday, October 27th, 2004

Xdoclett seems to be a nice way of generating web.xml descriptor based on the JavaDOC style comments in a source code. From what Chris showed me, it looks it’s quite difficult to run though. (more…)

Getting a class name from a static method

Monday, October 25th, 2004

public class ClassFromStatic { public static void main(java.lang.String[] args) { someStaticMethod(); }

public static void someStaticMethod() 
{
    System.out.println("I'm in " + new CurrentClassGetter().getClassName() 
        + " class");
}

public static class CurrentClassGetter extends SecurityManager 
{
    public String getClassName() 
    {
        return getClassContext()[1].getName();
    }
}

}

Java non-blocking I/O

Wednesday, October 20th, 2004

Java SUCKS! Platform independence doesn’t come with a high price. The last two days I have been trying to do asynchronous non-blocking I/O and got really frustrated. Moreover, I come to think that what I really wanted is simply not possible.

Correction - Java sucks LESS ;-) It’s not so well documented though…

I have a fully functional non-blocking IO for Java 1.4. It is multithreaded and it works great. (more…)