Saturday, January 22, 2011

Emacs vs Vi reminds me of the Iran-Iraq war. A war that went on for ages, in a place that nobody cared about, between two groups that nobody cared about, that stagnated and stunted their development, while the rest of the world left them behind.

"Stormbringer" nails it.

http://news.ycombinator.com/item?id=2125283

Thursday, September 30, 2010

OpenJDK and Project Lambda on MacOS X 10.6

Want to try out the upcoming JDK 7 on your Mac? And closures from Project Lambda, due in JDK 8? There are currently no official binary build available for MacOS X, but it turns out that it's actually gotten pretty easy to build these projects yourself. With just 10 minutes of work and a little waiting you could have a working build! Here's my account of how to do it.

First, install Mercurial and the forest extension. If you have Macports, this is as easy as

$ sudo port install mercurial
$ sudo port install hg-forest

Now check out the OpenJDK bsd-port tree:

$ hg fclone http://hg.openjdk.java.net/bsd-port/bsd-port

You have to download soylatte16-amd64-1.0.3.tar.bz2 from

http://landonf.bikemonkey.org/static/soylatte/#get

and unpack it. This is needed for bootstrapping the build.

Use this build script:

export SOYLATTE_HOME=$HOME/src/soylatte16-amd64-1.0.3
export JAVA_HOME=$SOYLATTE_HOME


cd bsd-port


time env -i PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin \
 make \
 CC=gcc-4.0 CXX=g++-4.0 \
 ALT_BOOTDIR=$SOYLATTE_HOME \
 JAVA_TOOLS_DIR=$SOYLATTE_HOME/bin \
 ALLOW_DOWNLOADS=true \
 ALT_FREETYPE_HEADERS_PATH=/usr/X11R6/include \
 ALT_FREETYPE_LIB_PATH=/usr/X11R6/lib \
 ANT_HOME=/usr/share/ant \
 NO_DOCS=true \
 HOTSPOT_BUILD_JOBS=1

This is based on Sam Pullara's Building OpenJDK 1.7.0 post. I just had to add ALLOW_DOWNLOADS=true to avoid this error:

ERROR: Cannot find source for project jaxp.

When you run the script (if all goes well) you should get a lot of output that ends with

Control bsd i586 1.7.0-internal all build finished: 10-09-30 15:37

On my MacBook Pro (Core i7, 4 GB RAM, SSD) this took a little over 20 minutes.

Now move your newly built JDK somewhere more sensible:

$ mv bsd-port/build/bsd-i586/j2sdk-image ~/jdk7

Test the install:

$ jdk7/bin/java -version
openjdk version "1.7.0-internal"
OpenJDK Runtime Environment (build 1.7.0-internal-kjetilod_2010_09_30_15_15-b00)
OpenJDK Server VM (build 19.0-b05, mixed mode)

Project Lambda
For bonus points, here's how you build Project Lambda (based on a post by Rémi Forax to the lambda-dev mailing list):

Checkout the source:

$ hg clone http://hg.openjdk.java.net/lambda/lambda/langtools

Build it with Ant (I just used 1.7.1 which comes with MacOS X):

$ cd lambda/langtools/
$ ant -Dboot.java.home=$HOME/jdk7 -f make/build.xml

From Rémi's post:

To run the compiler: 

/bin/java -cp classes.jar

com.sun.tools.javac.Main yoursource.java



and to run your code:

/bin/java -cp classes.jar:. YourClass

Wednesday, August 12, 2009

WAS tip: Application build level

If you want WebSphere to display "Application build level" for your application, your EAR Manifest has to contain "Implementation-version".

For Maven to add this automatically, add this to your EAR pom:

<project>

    ...

    <build>
    <plugins>
    <plugin>
        <artifactId>maven-ear-plugin</artifactId>
        <configuration>
            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
         </configuration>
    </plugin>
    </plugins>
    </build>

</project>

Tuesday, March 24, 2009

IdeaPad FTW!






Just got a new toy to satisfy my geek needs: a Lenovo IdeaPad S10e. So far, I'm pretty happy with it. Here are some thoughts after a couple of days' use.

It's a decent browsing machine. A 1024x576 screen resolution is just barely adequate for normal web browsing these days. Heavy flash use sometimes make scrolling a bit choppy. But the fantastic portability more than makes up for these shortcomings. (No, an iPhone doesn't really compete.)

The keyboard is not fit for serious development work. I'm typing this on the somewhat smaller-than-usual keyboard and I'm doing ok. However, there is only one Ctrl key, the tab key is tiiiiiiny, and the layout is kind of cramped together which makes it hard to touch type anything else than normal letters. The CPU and RAM might not be particularly impressive compared to your workstation, but for me they're not the main bottlenecks.

I like it. I've never had a laptop this portable. My normal work laptop is a 17" workstation model, which is great for the performance and screen size, but not so much for taking notes in meetings.

Now, to try out Ubuntu Netbook Remix in my copious free time...

Thursday, March 12, 2009

Mac Keyboard layout driving you crazy?

I'm officially giving up adapting to the incompatible Mac keyboard layout. This page explains what you need to do to fix it.

I'm also switching IntelliJ over to the standard PC-style layout, which is trivial to do. Life's too short to make adjustments to this crap.

Wednesday, January 14, 2009

Leaving it here so I'll find it later: If RAD complains that an EAR project won't build because
"The deployment descriptor of the module 'xxx.war' cannot be loaded." for WAR or EJB modules, you have to add them to the org.eclipse.wst.common.component file in the .settings directory in the project directory, like this
/">
WebModule_
uses

Found this here: http://www-128.ibm.com/developerworks/forums/thread.jspa?messageID=14048396&#14048396

Tuesday, September 23, 2008

String constructor considered useless turns out to be useful after all (film at 11)

When you were still a Java neophyte, chances are you wrote some code that looked like this:
String s = new String("test");
Brings back some embarrassing memories, doesn't it? You soon learned that instantiating Strings via the constructor was hardly ever done, and the String constructors seemed to be, well, utterly useless. When do you really ever need to do "new String(oldString)"? Come on, IntelliJ IDEA even flags all occurrences of this as "redundant"!

It turns out that this constructor can actually be useful in at least one circumstance. If you've ever peeked at the String source code, you'll have seen that it doesn't just have fields for the char array value and the count of characters, but also for the offset to the beginning of the String. This is so that Strings can share the char array value with other Strings, usually results from calling one of the substring() methods. Java was famously chastised for this in jwz'  Java rant from years back:
The only reason for this overhead is so that String.substring() can return strings which share the same value array. Doing this at the cost of adding 8 bytes to each and every String object is not a net savings...
Byte savings aside, if you have some code like this:
// imagine a multi-megabyte string here
String s = "0123456789012345678901234567890123456789";
String s2 = s.substring(0, 1);
s = null;
You'll now have a String s2 which, although it seems to be a one-character string, holds a reference to the gigantic char array created in the String s. This means the array won't be garbage collected, even though we've explicitly nulled out the String s!

The fix for this is to use our previously mentioned "useless" String constructor like this:
String s2 = new String(s.substring(0, 1));
It's not well-known that this constructor actually copies that old contents to a new array if the old array is larger than the count of characters in the string. This means the old String contents will be garbage collected as intended. Happy happy joy joy.

Sometimes, seemingly useless constructs reveal hidden gems of usefulness. Be sure to check out the source for String to find how this works!