Tuesday, December 11, 2007

Emacs Using 100% CPU

Looks like I will be using EMACS more, again. I am getting sick of waiting for my IDE to "help" me by getting in the way, being slow and hogging lots of memory. I did run into a problem with EMACS hogging the CPU which is fixed by: (custom-set-variables '(semantic-idle-scheduler-idle-time 200)) Emacs Using 100% CPU: "quick fix is to set the Emacs variable semantic-idle-scheduler-idle-time to a large number (by default it is 2 seconds) so that the idle scheduler does not kick in (which is what is using all the CPU)!"

Book Review: Effective Java

If I had to choose one single book on Java programming, I would choose Effective Java.

Thursday, December 6, 2007

Mylyn User Guide - Eclipsepedia

I have been having problems with Mylyn hogging the CPU and making Eclipse unusable. The workaround is to exclude certain parts of the project from being included in Mylyn. I excluded all the generated directories. Mylyn User Guide - Eclipsepedia: "If an external builder (e.g. Maven, pydev, or other Ant-based builders) is producing output files that are being automatically added to your context because they are not being marked 'derived' as with Eclipse-based builders. You may note that such files are always show as interesting when they are generated or updated and can not be filtered away, since Mylyn expects all files that have changed as part of the task context to have interest. In this case you can explicitly exclude these files from being added to the task context the Preferences -> Mylyn -> Resources page. For example, if the output folder of the builder is 'target', you could set this the following way. Similarly, you could add a filter for '*.pyc' to exclude all files generated with that extension."

Developer's Guide - Google Chart API - Google Code

Developer's Guide - Google Chart API - Google Code: "The Google Chart API lets you dynamically generate charts. To see the Chart API in action, open up a browser window and copy the following URL into it: http://chart.apis.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld"

Wednesday, December 5, 2007

You WILL experience the Day of the Ninja -- December 5

You WILL experience the Day of the Ninja -- December 5: "As last year (and every year from now on), December 5th is the Day of the Ninja. Plague your co-workers with ninja-ness and wear a ninja mask to work! Got the day off? Run wild in the streets, or dress like a ninja at the mall! Just show the world that YOU ARE NINJA!"

Tuesday, December 4, 2007

Springframework Presentations

Not sure if you guys are aware of this website http://parleys.com/display/PARLEYS/Home. It has lots of video presentations (mostly focusing on Spring).

Thursday, October 18, 2007

visualvm: Introduction to VisualVM

visualvm: Introduction to VisualVM: "VisualVM is a tool that provides detailed information about Java applications while they are running. It provides an intuitive graphical user interface that allows you to easily see information about multiple Java applications. Java applications are run by a Java Virtual Machine, or VM. The name VisualVM comes from the fact that VisualVM provides VM information visually. As of October, 2007 VisualVM is still under development and is therefore considered an experimental tool. All feedback and suggestions are welcome! Please send your ideas to feedback@visualvm.dev.java.net. System Requirements The VisualVM tool itself must be run with JDK 6. It can display information, however, on any Java application that is running on JDK 1.4.2 or higher. The amount of information VisualVM can provide on a Java application is determined by the version of the JDK that is being used to run that Java application (more details below)"

Tuesday, October 16, 2007

Which class or resource is being lodaed?

I was having a problem with spring not being able to parse the applicationContext.xml. I finally checked and found out the wrong applicationContext.xml was first in the CLASSPATH. The code to do this is easy: System.out.println(this.getClass().getClassLoader().getResource("applicationContext.xml")); You can also find class files. To find java.lang.Object use System.out.println(this.getClass().getClassLoader().getResource("java/lang/Object.class")); The result is something like: jar:file:/C:/Program%20Files/Java/j2sdk1.4.2_14/jre/lib/rt.jar!/java/lang/Object.class Notice how the JRE version is in the output.


Retrotranslator is a Java bytecode transformer that translates Java classes compiled with JDK 5.0 into classes that can be run on JVM 1.4. Of course there is a Maven plugin. I needed to do some unit testing of some code that uses JavaMail. Poking around I found mock-javamail that does just that. However, it is written in Java 5 and I am stuck in the prehistoric world of Java 1.4. At first, I converted the code to 1.4 but that leaves 2 different code bases. Then I was pointed at retrotranslator that would give a 1.4 compatible jar from 1.5 source. One code base. Nice.

Monday, October 8, 2007

Using Maven to create a one-jar executable jar.

Oliver's Blog: "Using Maven2 to generate an executable JAR" Has instructions on getting the onejar-maven-plugin to work. This is similar to what UberJar used to to do. It takes all maven dependencies and places those jars into the output jar. It does not explode the jars as the assembly plugin is wont to do. Instead, it used the one-jar package that has a classloader that knows how to look into the jar file for other jar files. It makes for a cleaner jar file that is easier to maintain later. It does allow the filename to be specified, but does not seem to allow manifest entries, like Implementation-Version. Thanks Oliver.

Friday, September 28, 2007

ASP.NET caching based on a cookie

You have to use VaryByCustom parameter. Your OutputCache directive will look like this <%@ OutputCache Duration="600" VaryByCustom="StyleSheet" %> and you have declare the following method in which we access the Cookie and pass the value back
public override string GetVaryByCustomString(System.Web.HttpContext context, string custom) {
    if (custom == "StyleSheet"){
        return "StyleSheet=" + this.Request.Cookies["StyleSheet"];
Given this method, you should be able to cache based not only on cookies, but any other string value or anything that can be converted into a string.

Monday, August 20, 2007


Originally uploaded by dratz

What have they done with com/sun/corba/se/connection/ORBSocketFactory?

We are using Weblogic 8.1.4 and I am writing a monitoring program that will let me know if all the required EJBs, data sources and other resources are up. My current project is a enterprise level system with hooks into lots of things. It can take some to to determine which resource is causing the problem. I was using the weblogic.jar but it is way too big. replacing it with wlclient.jar results in:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/corba/se/connection/ORBSocketFactory
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
 at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
 at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
 at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
 at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
 at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:169)
 at weblogic.corba.j2ee.naming.ORBHelper.(ORBHelper.java:113)
 at weblogic.corba.client.ClientORBInitializer.initialize(ClientORBInitializer.java:84)
 at weblogic.jndi.WLInitialContextFactory.(WLInitialContextFactory.java:29)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 at java.lang.Class.newInstance0(Class.java:355)
 at java.lang.Class.newInstance(Class.java:308)
 at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
 at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
 at javax.naming.InitialContext.init(InitialContext.java:223)
 at javax.naming.InitialContext.(InitialContext.java:197)
 at org.springframework.jndi.JndiTemplate.createInitialContext(JndiTemplate.java:105)
 at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:83)
 at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:121)
 at com.ihc.phc.monitor.JndiMonitor.getStatus(JndiMonitor.java:29)
 at com.ihc.phc.monitor.Monitor.getAllStatus(Monitor.java:21)
 at com.ihc.phc.monitor.Main.main(Main.java:12)
Oh how pleasant. This error has been report as bug 6340079 which states: Reason for compilation errors: ------------------------------
The following packages are not there on jdk1.5.0 but they are in j2sdk1.4.2 1.com.sun.corba.se.connection.* 2.com.sun.corba.se.internal.core.*
How was this problem resolved? Remove the offending unit test of course. There is also another thread on the subject stating basically the same thing but without helpful suggestions. The only helpful suggestion seems to have been to try the wlclient jar from a newer version of the WebLogic server (9 or 10). I tried that and now the ClassDefNotFoundError goes away. Now there is a runtime error:
              [java.rmi.MarshalException: CORBA MARSHAL 0 Maybe; nested exception is: 
 org.omg.CORBA.MARSHAL:   vmcid: 0x0  minor code: 0 completed: Maybe]
You know, indecision is bad enough in humans, I do not need it in computers. Maybe it worked? Slight chance I would say. Ok, looks like the newer (9.1) wlclient.jar is not compatible with older (8.1) weblogic instances. Funny thing is, the weblogic.jar with all its bloat works. I wonder ..... Looks like the weblogic.jar has it's own version of the ORBSocketFactory and that is does not use the sun one. Oh bother! Guess it is back to the bloated weblogic.jar for me.

Thursday, August 16, 2007

Watch "Advanced Topics in Programming Languages: Java Puzzlers, Episode VI"

Advanced Topics in Programming Languages: Java Puzzlers, Episode VI 1 hr 13 min 49 sec - Jul 23, 2007 Average rating: (23 ratings) Description: Google Tech Talks July 23, 2007 ABSTRACT Java Puzzlers, Episode VI: The Phantom-Reference Menace/Attack of the Clone/Revenge of the Shift. Josh Bloch and special guest star Bill Pugh present yet another installment in the continuing saga of Java Puzzlers, consisting of eight more programming puzzles for your entertainment and enlightenment. The game show format keeps you on your toes while the puzzles teach you about the subtleties of the Java programming language and its core libraries. Anyone with a working knowledge of the language will be able to understand the puzzles, but even the most seasoned veterans will be challenged. The lessons you take from this session are directly applicable to your programs and designs. Some of the jokes may even be funny. If you loathed Episodes I--V, you'll detest Episode VI. Come early, because overripe fruit will, as usual, be given to the first 50 attendees. This is a repeat of a talk given at Google in May and at JavaOne 2007.

Want to see more cool videos? Go to video.google.com/

Think you have an even cooler video? Add it at video.google.com/videouploadform

If you're having trouble watching the video, try copying the following URL into your browser: http://video.google.com/videoplay?docid=9214177555401838409&pr=goog-sl

Monday, August 13, 2007

LISP Cycles

I admit it, I like LISP. There are a certain set of programming problems that it handles elegantly. I feel the same about AWK, BASH, SQL and even JAVA. Each language has a sweet spot, that domain of problems it is well suited to solve. While other languages can address the issue, some are more painful than others. My "perfect world of programming": Allow the programmer to solve the problem using the correct tool. That is, remove the "If all you have is a hammer, everything looks like a nail" attitude. I am sick to death of OR mapping in Java, as an example. If there were some way to build pieces using the proper tool and then combine them into a complete solution. See SEWER.

Monday, June 18, 2007

Felipe Ortiz's Blog: The Last JavaOne 2007 Wrap-up

Felipe Ortiz's Blog: The Last JavaOne 2007 Wrap-up: "Even though it has been more than a month since JavaOne, I hope you enjoy this blog post here where I list the best of the best at this year's JavaOne. Feel free to contribute your best experience or top moment from JavaOne 2007! JavaOne Wrap-ups JavaOne wrap-up, from Gosling JavaOne 2007 Wrapup, from Javalooby JavaOne 2007 Wrap-up, Final Thoughts, and Open Questions, from Wolf Paulus JavaOne 2007 Wrap-up, from Netzooid JavaOne 2007 Conference Notes, from Juixe"

Tuesday, June 5, 2007

Linux.com | GNU Emacs 22 finally released

I have just recently switched from Emacs to Eclipse for my Java development work. I still use Emacs almost everyday I even have an Emacs related project on sourceforge: starteam-el.sf.net Linux.com | GNU Emacs 22 finally released: "GNU Emacs 22 finally released Monday June 04, 2007 (04:50 PM GMT) By: Joe 'Zonker' Brockmeier Emacs fans, limber up your fingers -- there's a new GNU in town. Almost six years after the release of the previous version, the Free Software Foundation has announced the release of GNU Emacs 22. (Actually, 22.1, but who's counting?) This release includes support for GTK , drag and drop support for X, a number of new modes, and a graphical interface to the GNU Debugger (GDB). The FSF has come under some criticism for taking so long to release a stable version. The previous release, Emacs 21, came out in October 2001."

Friday, June 1, 2007

Open Source Technical Support by OpenLogic

This gets filed under the category of "Why didn't I think of this?". What an excellent business model. Take a free product and sell support for it. The reason these products are around is because you do not really need any outside support. It is pure genius. Open Source Technical Support by OpenLogic: "OpenLogic provides comprehensive technical support for the OpenLogic Enterprise platform as well as for over 200 certified open source software packages. The OpenLogic technical support model combines a traditional 'one number to call' approach with the strength of the open source community. Whether you have questions regarding the use of an open source software package, need help troubleshooting a complex issue, or have encountered a bug in a particular package, you can rest assured that OpenLogic has the expertise necessary to assist you."

Thursday, May 24, 2007

JavaOne Online Technical Sessions - Java EE

JavaOne Online Technical Sessions - Java EE: "JavaOne Online Technical Sessions" This includes the PDFs. The labs are also available. The multimedia should be added over the next month or so.

Wednesday, May 23, 2007

JPC - Computer Virtualization in Java

OK, I admit it. This is awesome. JPC - Computer Virtualization in Java: "Welcome to the JPC Project JPC is a pure Java emulation of an x86 PC with fully virtual peripherals. It runs anywhere you have a JVM, whether x86, RISC, mobile phone, set-top box, possibly even your refrigerator! All this, with the bulletproof security and stability of Java technology."

JavaOne 2007 BOF 9529: Hudson

Kohsuke Kawaguchi's Blog: My JavaOne report: "The other talk was about Hudson, and you can see the slides here. The talk was quite late in the night at 10pm after the JavaOne 'after dark bash' party, yet there were quite a few people to my pleasant surprise. I managed to prepare my 2nd orb in time, so I was able to demo that, too. The only problem I had was that the talk was so late that the parking garage was closed by the time I get back. So Ramesh and I had to take Caltrain back to the south bay. By the time I got home it was almost 2am."

Slides For JavaOne BOF-2958 Dynamic Scripting BOF — PushToTest - The Open-Source SOA Governance and Test Automation Company

Slides For JavaOne Dynamic Scripting BOF — PushToTest - The Open-Source SOA Governance and Test Automation Company: "Download the slide deck for the Dynamic Scripting Languages BOF: http://downloads.pushtotest.com/javaone2007/2007_JavaOne_Scripting.pdf Here is the abstract: Dynamic Scripting Languages and Java Java 6 introduces native support for dynamic scripting languages (JSR 223, scripting languages and Java technology.) This BOF session brings together leaders, users, and critics from the Jython, Groovy, PHP, Ruby, and many other scripting camps for an exchange of ideas to develop a common understanding of the state of the art and practical examples of using dynamic scripting languages to solve problems. -Frank"

JHat update jar

Edward Chou's Blog (周甘泉 的 博客): "JavaOne BOF on Memory Leaks For those of you who came to Frank and myself's BOF session at JavaOne, you can download my 'modified' jhat here jhat.jar. My modification of original jhat include: * add exclude functionality on query results to make it easier to filter out hundreds of duplicate reference chains, this way it will be possible to find unique leaks (see Figure 1) * add classloader browser to nicely display classloaders' parent-child relationship, as well as number of classes loaded in each classloader (see Figure 2) To run jhat, simple do 'java -Xmx512m -jar jhat.jar '"

JavaOne 2007 - BOF-8847: Developing Components for Java Business Integration: Binding Components and Service Engines

Frank Kieviet : Weblog: "BOF8847: Developing Components for Java Business Integration: Binding Components and Service Engines Presented by Frank Kieviet, Alex Fung, Sherry Weng, and Srinivasan Chikkala Attendance: about 100 You cannot cover how to write JBI components in just 45 minutes. We were also not sure about what the audience was interested in. That's why we assumed that the audience would consist mostly of people who have never written a JBI component before, and are relatively new to JBI. That's why we decided to talk mostly about general information on JBI and JBI components, and highlight the power of JBI and discuss how to go about developing one. As an experiment I wanted to try a new format (at least new for me): rather than slicing up the session into four parts of 10 minutes, we cast the session into a 'discussion forum'. Of course the questions and answers (and even the jokes) were well rehearsed. Unfortunately, the audio/visual people that control the meeting rooms, had forgotten to start the session timer. As a result the audio was cut unexpectedly just a minute before we could finish up. Nevertheless, I think it was an interesting session. Presentation JavaOne07-BOF8847 (pdf) Audio JavaOne07-BOF8847 (mp3)"

JavaONE 2007 - BOF 8034 and BOF 8745

JavaONE 2007 - BOF 8034 and BOF 8745: "JavaONE 2007 - BOF 8034 and BOF 8745 I along with my colleagues presented 2 BOFs, and here are the slides and audio cast. The presentation slides for the BOF 8034 are @ http://blogs.sun.com/bhavani/resource/BOF-8034.pdf The presentation slides & audio cast for BOF 8745 is available in Frank's blog - http://mediacast.sun.com/share/fkieviet/JavaOne07-BOF8745-EESE.pdf http://mediacast.sun.com/share/fkieviet/JavaOne07-BOF8745-EESE.mp3"

JavaOne 2007 BOF 5000: Glassitrope - Java Desktop Widgets

Desklets: "Slides from the Glossitope BoF Due to a deluge of requests (both of them) here are the slides for our Awesome BoF 5000. You can see them as a PDF or a QuickTime movie. I recommend the QuickTime if you can as it contains the rad transitions and animated jokes. * QuickTime 7.4MB * PDF 2.6 MB"

JavaOne 2007 BOF 3908 Slides: JAVA 3D API

java3d: Java 3D BOF @ JavaOne 2007: "Java 3D BOF @ JavaOne 2007 Here are the Java 3D BOF slides that we presented at JavaOne 2007. Thank you to all those who came and participated. * View HTML slides * Download PDF file"

Mandy Chung's Blog: JavaOne 2007 BOFs slides 9123 and 2816

Mandy Chung's Blog: JavaOne 2007 BOFs slides: "BOF-2816: The Troubleshooting and Diagnostic Utilities in JDK Release 5 and 6 BOF-9123: Visualize Runtime Problems: A New All-in-One JDK Troubleshooting Tool"

JavaOne 2007 BOF 4108 Slides: Interoperable Web Services Security between Java and .NET with WSIT: Ease of Development and Performance

Ashutosh's Blog: "Jiandong, me and Shyam presented a BOF - Interoperable Web Services Security between Java and .NET with WSIT: Ease of Development and Performance"

Thursday, May 17, 2007

Bug ID: 5084229 javax.naming.NamingEnuermation should be closed when parent DirContext is closed

We came across this using LDAP. The problem was that it was keeping the file handles open from the NameingEnumeration which meant we ran out of connections. Bug ID: 5084229 javax.naming.NamingEnuermation should be closed when parent DirContext is closed: "Bug ID: 5084229 Votes 10 Synopsis javax.naming.NamingEnuermation should be closed when parent DirContext is closed Category jndi:other Reported Against 1.4.2 Release Fixed State Closed, not a bug Related Bugs Submit Date 09-AUG-2004"

Monday, May 14, 2007

JavaOne 2007 in Review

JavaOne is always a great experience. From first thing in the morning to late in the night it is Java, Java, and more Java. One great thing about JavaOne is the opportunity to spend an hour on some technology you might not otherwise be able to spend the time on. I try and spend time on a wide range of topics. I will be adding my thoughts on each session over the next couple of days.


It was rare that I attended a session that FindBugs was not mentioned. Many of the presenters had good things to say about the project. I only attended one session that dealt with the topic of static code analysis, but it kept getting mentioned in the context of good things everyone should be doing. Take a look if you haven't already. There is support for many IDEs, even Eclipse.
Session ID/Title Speaker(s)
Tuesday , 05/08/2007
TS-9370 JRuby on Rails: Agility for the EnterpriseCharles Nutter; Thomas Enebo
TS-2707 Java Puzzlers, Episode VI: The Phantom-Reference Menace/Attack of the Clone/Revenge of the ShiftJoshua Bloch; William Pugh
TS-6381 The Future of the Java Technology Web TierRajiv Mordani; Jiandong Guo
TS-1519 All About Java Technology-Based RoboticsPaul Perrone
BOF-1692 Introducing the Sun SPOT (Small Programmable Object Technology) and Sun SPOT Community: Java on Wireless Sensor Networks Randall Smith; Ron Goldman; Arshan Poursohi
BOF-2358 Closures for the Java Programming Language Neal Gafter
BOF-4664 Dynamic Portals and Ajax in PortletsGreg Ziebold; Jai Suri
Wednesday, 05/09/2007
TS-2594 Secure Coding Guidelines, Continued: Preventing Attacks and Avoiding Antipatterns Jeff Nisewanger; Charlie Lai
TS-2689 Effective Java™ Reloaded: This Time It's for RealJoshua Bloch
LAB-1420 Nonintrusive Monitoring of Java Technology-Based Applications with Java Management Extensions (JMX) Technology, JConsole, and Aspect-Oriented Programming: Using a Spring Application as an ExamplePaul Cheung; Luis-Miguel Alventosa; Max Poon
TS-2388 Effective Concurrency for the Java PlatformBrian Goetz
TS-4604 Fast and Free SSO: A Survey of Open-Source Solutions to Single Sign-on Craig Dickson; Naveen Nallannagari
BOF-9587 Pimp My Java Application: Applying Static Analysis Tools to Boost Java Code QualityGregg Sporar; Fabiano Cruz
LAB-7210 Hands-on with Project Darkstar: The JavaOne Conference MUD Sridhar Reddy; Jeffrey Kesselman
Thursday , 05/10/2007
TS-3834 Being Productive with SwingBen Galbraith
TS-2656 JMX Technology: Who's Doing WhatEamonn McManus; Jean-François Denise
TS-7755 Advanced Spring FrameworkRod Johnson
TS-9944 PHP and Java Technology Integration: A Technical How-To Session with Cofounder and Co-CTO of Zend Andi GutmansAndi Gutmans
TS-3569 Beans BindingShannon Hickey; Hans Muller; Jan Stola
TS-3073 Write a 3-D Game in the Java Programming Language in Less Than 50 Minutes Erik Hellman
BOF-8238 Building Composite Services Applications Mike Edwards; Jim Marino
BOF-9472 Performance Statistics of Java Technology-Based Applications Using Dynamic Tracing (DTrace) and Chime Steven Reynolds
BOF-3478 Easy Test-Driven GUI Development Alex Ruiz; Yvonne Price
Friday , 05/11/2007
TS-6821 Spring Web Flow: A Next-Generation Web Application Controller Technology Keith Donald
TS-43350 Harnessing the Power of Java Platform, Enterprise Edition (Java EE) Technology With Spring Michael Keith; Shaun Smith; Colin Sampaleanu
TS-6836 Creating Amazing Web Interfaces with Ajax Ben Galbraith; Dion Almaer
TS-1786 Writing Games With Project Darkstar Jeffrey Kesselman; Chris Melissinos; Mark Rizzo

Developer Knowledge Base - A Java Developer's Guide to Google Technologies

I came across this link that lists many of Google's code projects with a summary of each. Worth a look to see what is going on in the Google-space. Developer Knowledge Base - A Java Developer's Guide to Google Technologies: "A Java Developer's Guide to Google Technologies Chris Schalk, Google Developer Programs May 2007 Java developers may not necessarily think of Google immediately when it comes to Java, but rest assured, Java development is thriving within the Google developer community. Google provides a substantial set of Java-based technologies and libraries, and even experienced Java developers using Google's Web Toolkit might be surprised to hear about the depth of Google's Java support. This article serves as an overview of the Java development possibilities with Google APIs and technologies."

Tuesday, May 8, 2007


The JDK is not open source. It has been available for download for some time. Now it is available with the GPL v 2 license.

Wednesday, April 25, 2007

Wicket and Guice

Are you sick of XML? I sure am. While I really like Spring Framework, I am sick of all the XML. Writing unit tests is hard enough, but how do you test XML? Some might argue that it isn't really code and doesn't need testing. Some might be wrong. What I want is a way to write code WITHOUT XML. Two interesting projects have caught my attention: * Wicket * Guice
Wicket - Home: "Welcome to Wicket With proper mark-up/logic separation, a POJO data model, and a refreshing lack of XML, Wicket makes developing web-apps in Java simple and enjoyable again. Swap the boilerplate, complex debugging and brittle code for powerful, reusable components written with plain Java and HTML. * Check the feature list * Read some Wicket buzz or some Wicket blogs * Find out why you should use Wicket * Check out some examples and see them in live action * Download Wicket 1.2.6 Wicket is released under the Apache License, Version 2.0 ."
Guice wholly embraces annotations and generics, thereby enabling you to wire together and test objects with less effort than ever before. Annotations finally free you from error-prone, refactoring-adverse string identifiers. In a nutshell: * Guice empowers dependency injection. * Guice cures tight coupling. * Guice enables simpler and faster testing at all levels. * Guice reduces boilerplate code. * Guice is type safe. * Guice externalizes configuration when appropriate. * Guice lets you compose your application of components which are truly independent. * Guice reports error messages as if they will be read by human beings. * Guice is the anti-static. * Guice is small and very fast.

Friday, April 13, 2007

Felipe Gaucho's Blog: The name is One, JavaONE !

I came across a JavaOne posting that has tips fo rthis attending and for getting the most out of JavaOne. Here is a sample. Be sure and go to the link and look over the comments. Felipe Gaucho's Blog: The name is One, JavaONE !: " # Talk to everyone you can. The people at J1 are for the most part friendly, outgoing and have great experience and tips to share. Just introduce yourself and ask what cool things they do. John Gage (on the years he's there), always makes it a point to remind attendees to talk to one another. If nothing else, you can say, “Dr. Gage told me to talk to you”, and go from there. Breakfast and lunch are great places to talk. Just find a table with some folks, plop down and fire away. Some folks won't be forthcoming, but most are great. Talk to folks in line too: there will be plenty of time for that. # Have a plan of what sessions/BOFs you want to go to. For each, have a backup session/BOF you are also interested in. Sometimes rooms are full and you can't get in, or the speaker is dull or not talking about what you expected. Don't be afraid to just get up and leave for your second choice. # The most comfortable seats are on the ends or front rows. The seats are pretty close together. Usually wall sockets for charging your laptop are on the sides of the room, but sometimes they're all taken. Depending on the room and/or number of attendees, wireless access may or may not be available/reliable. # Unless you want to really immerse yourself in one topic, don't go to sessions that are all on the same track. You'll find them repeating themselves, even though each will have some new material. Diversify and learn about stuff you never even thought about using. J1 is for discovering new stuff and broadening your knowledge. # Take something warm to wear. Some of the session rooms are cold enough to freeze hydrogen. # Make sure you make it to Birds-of-a-Feather sessions as well. For those coming from Europe, the BOFs can run late, but you can really get up close and personal with the actual developers and ask questions you can't get to in the bigger sessions. Be aware, some of the presenters aren't comfortable with that and will try to hide behind a prepared set of slides, but be polite and enthusiastic about what they're presenting. Most love having folks that appreciate the work they're doing. # Visit the pavilion to learn about specific products you're interested in, but also to learn about stuff you've never heard of that might make your job easier. Don't go just to get cool junk for your kids (something of which I've been guilty!). Some exhibitors have actual developers with the marketing folk. Be kind to them all. By the end, they've been standing and talking for three days and start getting ragged. # Make sure you visit some of San Francisco. A truly unique, physically beautiful and captivating city. (Don't be surprised by the number of panhandlers, though) Be prepared for lots of walking, some steep hills and weather that can range from cold and misty to gloriously sunny in a short time. So have layered clothing and comfortable shoes. # The conference food is okay, but don't expect the eating experience of your lifetime. Save that for the evening and the San Francisco restaurants. During lunch they'll have hot food, but also lunch bags with a sandwich (turkey, ham, beef or vegie), chips, cookie and a fruit, that you can grab and take to a session. # Don't buy books unless you feel like lugging them around and paying a little bit more than Bookpool. That being said, the bookstore has an awesome selection of the classics and the latest. Sometimes you can get free books from various pavilions. They'll also have authors available for book signings and chatting with. Josh Bloch will have a new book this year and I'm sure will be signing it. Also, go to any session he gives. # Most of all, just immerse yourself in the whole JavaOne experience. Be positive (even with the guards!), get as much sleep as you can, check out the vendor parties, the After Dark party, the beer, and most of all, learn all you can about what great and creative things people are doing and just enjoy the company of other Java enthusiasts and professionals. "

Matthew Smith: JDK Community Star

Sun has been opening the Java platform for some time now. With the Mustang release, the source code was made available and a process was provided for submitting bug fixes. About this same time we discovered an issue with the LDAP code that left connections open certain circumstances. Since I had access to the source code from Sun, I was able to find the problem and send a correction. For this I was "honored" at JavaOne in 2006 as a JDK Community Star for contributing a bug fix to Java. Click on Matthew Smith.

Communciating between JSR-168 portlets and the portal containter

The JSR-168 spec does not address the need for portlets and the portlet container to communicate. Sometimes an action taken by a portlet needs to be reflected in the navigation which is controlled by the container. Conversely, an action taken in the navigation will need to change the state of the portlets. The following information applies specifically to Vignette Application Portal but should apply to other portals like Pluto, Jetspeed2 and Liferay. Communicating from the portlets to the portal container. Add a parameter to PortletURL. Then there can be something (grid, secondary page or my personal choice, a servlet filter) that is listening for that parameter. Of course, the portlet will add a lot of nonsense to the name of the parameter so the receiver needs to look for something ending with the parameter name. The servlet filter can then place the required information into the session. Of course, you need to take reasonable security into account when deciding what to pass as a parameter. Communicating from the portal to a a portlet. Again, in a servlet filter, add the information that needs to be communicated to the portlets as a request attribute. The trick is that the name of the attribute must begin with "javax.servlet.". It will be visible in the RenderRequest and ActionRequest objects passed to the portlet. We are already doing this to pass things like Remote URL to the portlets. Note: For this to work the object being passed needs to be in the classpath and not just loaded in the WAR file. The reason is that the object is loaded by one classloader and then passed to another. You end up with ClassCastException.

Wednesday, April 11, 2007

Fun with Java Enums

Way back in Java 1.5, enum types were added to the Java spec. The idea is simple enough; create an object with a fixed set of valid values. The values are constant, like coins. Coins come in a fixed number of types (penny, nickel, dime, etc) and each type has a fixed value (1, 5, 10, ... ). An enum type allows you to do just that in your code:
public class Coins {
 enum Coin {
  int value;
         Coin( int v ) { value = v; }

 public static void main(String[] args) {
  System.out.println("A penny is worth: " + Coin.PENNY.value);
A Coin enum type is declared and each possible type of Coin is given it's respective value. And the code prints just as you would expect:
A penny is worth: 1
Part of the assumption is that a penny is always a penny and always worth 1 cent. However, if we add the following lines of code to the main method, let's see what happens.
  Coin.PENNY.value = 1000;
  System.out.println("A penny is now worth: " + Coin.PENNY.value);
When the code is compiled and run again, what is the output? In case you were wondering, it does compile quite nicely.
A penny is worth: 1
A penny is now worth: 1000
Now that's the way all my investments should grow! Seriously, though, what is the problem? The problem is that the value, and any instance variables in an enum, are not magically immutable. The enum type does not do any special checking to ensure that the instances of the type (PENNY, NICKEL, ...) remain constant. Under the covers, the enum type is converted to a static class with static members for each of the declared possbile values like this:
static final class Coins$Coin extends Enum
          public static final Coins$Coin[] values()
                return (Coins$Coin[])$VALUES.clone();

            public static Coins$Coin valueOf(String s)
                 return (Coins$Coin)Enum.valueOf(Coins$Coin, s);

            public static final Coins$Coin PENNY;
            public static final Coins$Coin NICKEL;
            public static final Coins$Coin DIME;
            public static final Coins$Coin QUARTER;
            int value;
            private static final Coins$Coin $VALUES[];

                PENNY = new Coins$Coin("PENNY", 0, 1);
                NICKEL = new Coins$Coin("NICKEL", 1, 5);
                DIME = new Coins$Coin("DIME", 2, 10);
                QUARTER = new Coins$Coin("QUARTER", 3, 25);
                $VALUES = (new Coins$Coin[] {
                    PENNY, NICKEL, DIME, QUARTER

            private Coins$Coin(String s, int i, int j)
                super(s, i);
                value = j;
Our value is given the same access modifiers in the generated class as it was given when we defined the enum. Meaning that the value is not able to be modified by any member of the same package.

The fix

The fix is fairly simple. Make the value instance variable final:
  final int value;
Now when the code that tries to modify the value is compiled, this error:
Coins.java:28: cannot assign a value to final variable value
                Coin.PENNY.value = 1000;
1 error
Problem solved. Right? Well, not so fast. For primitive types, yes. But for descendants of Object, maybe not. What if instead of an int, value was something like a Map. You could then do Coin.PENNY.value.put("bad key", "bad value") and the compiler would be perfectly happy with it. To fix the problem, ensure that the Map is unmodifiable or immutable
public class Coins
 enum Coin {
  final Map value;

  Coin( int v ) { 
   Map newValue = new HashMap();
   newValue.put( "cents", v );
   value = Collections.unmodifiableMap( newValue );

 public static void main(String[] args) {
  System.out.println("A penny is worth: " +    


While the compiler will ensure that the enum types are immutable, it is the responsibility of the developer to ensure that any instance variables added to the enum are also immutable. This means the instance variable needs to be final AND the type of the instance variable must itself be immutable.

Friday, April 6, 2007

Java One 2007

I will attending Java One this year. Here is how you can contact me. Join Me at the 2007 JavaOne Conference Event Connect Tool!

Thursday, April 5, 2007

Elusive unit test error

We are using Spring Framework 1.2 and Weblogic 8.1.4. On occasion, I will get this error when running a unit test that uses JdbcTemplate. If I re-run the test with no modifications, the test completes fine. I wish I knew why. If you have an idea, post in the comments. UPDATE: The problem seems to be that Foglight/Performasure is installed on the server and is doing something with the JDBC getConnection response. The options seems to be
  1. Put the client jar for Performasure in my test classpath. I do not know if the license allows for that.
  2. Remove it from the server.
I'll leave it as an exercise for the reader to decide.
java.lang.NoClassDefFoundError: com/sitraka/pas/agent/plugin/instrumentor/method/JdbcDriverInstrumentor$JdbcImplementation
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:480)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:182)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:224)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:217)
at weblogic.j2ee.ApplicationManager.loadFromNetwork(ApplicationManager.java:652)
at weblogic.j2ee.ApplicationManager.loadClass(ApplicationManager.java:322)
at weblogic.j2ee.ApplicationManager.loadClass(ApplicationManager.java:258)
at weblogic.j2ee.ApplicationManager.loadClass(ApplicationManager.java:253)
at weblogic.rmi.internal.ClientRuntimeDescriptor.computeInterfaces(ClientRuntimeDescriptor.java:254)
at weblogic.rmi.internal.ClientRuntimeDescriptor.intern(ClientRuntimeDescriptor.java:140)
at weblogic.rmi.internal.StubInfo.readObject(StubInfo.java:124)
at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:824)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1746)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:120)
at weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:120)
at weblogic.rmi.internal.ObjectIO.readObject(ObjectIO.java:56)
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:164)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:293)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:247)
at weblogic.jdbc.common.internal.RmiDataSource_814_WLStub.getConnection(Unknown Source)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:462)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:528)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:561)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:579)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:589)
at com.ihc.provider.domain.ProviderImpl.findProviderForId(ProviderImpl.java:401)
at com.ihc.provider.domain.ProviderImpl.findProvider(ProviderImpl.java:383)
at com.ihc.phc.user.UserServiceImpl.addProviderInfo(UserServiceImpl.java:249)
at com.ihc.phc.user.UserServiceImpl.getMessagingDoctors(UserServiceImpl.java:231)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at com.ihc.phc.util.CacheInterceptor.invoke(CacheInterceptor.java:37)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy13.getMessagingDoctors(Unknown Source)
at com.ihc.phc.test.user.TestUserServiceImpl.testGetMessagingDoctors(TestUserServiceImpl.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Friday, March 30, 2007

Chapter�16.�Portlet MVC Framework

Spring Portlet MVC applies the same principles to portlet development as the the Spring Web MVC framework applies to servlet development. For a nice introduction, see: Chapter�16.�Portlet MVC Framework: "Portlet MVC Framework" There is a blog posting over at O'Reilly that has some other useful links.

Wednesday, March 21, 2007

Coding Horror: The "Works on My Machine" Certification Program

I think we will be doing this at work. Coding Horror: The "Works on My Machine" Certification Program: " 1. Compile your application code. Getting the latest version of any recent code changes from other developers is purely optional and not a requirement for certification. 2. Launch the application or website that has just been compiled. 3. Cause one code path in the code you're checking in to be executed. The preferred way to do this is with ad-hoc manual testing of the simplest possible case for the feature in question. Omit this step if the code change was less than five lines, or if, in the developer's professional opinion, the code change could not possibly result in an error. 4. Check the code changes into your version control system. Congratulations! You're fully certified. Brand your app with your shiny new Works on My Machine badge. You'll certainly want to show it off to your fellow team members and key stakeholders. But please-- do try to keep your ego in check. Not everyone is capable of such an epic commitment to quality in software engineering."

Wednesday, March 14, 2007

Sun Certified Programmer for Java 5 Study Guid

SCJP Sun Certified Programmer for Java 5 Study Guide (Exam 310-055) At work I am leading the Java Certified Programmer study group and this is the book we have chosen after extensive research. OK, I asked 1 person, but he passed so it can't be all that bad.