February 2006 Archives

Amir Shevat

AddThis Social Bookmark Button

Just came back from Hong-Kong. What a city! Hong-Kong is like New York on steroids, it is the most technologically advanced city I have ever been in. Everybody is connected to some sort of high-tech miniature gadget. I felt like a cave-man with my poor old digital camera because everybody was using their cellular phones to take video and pictures (my cellular phone’s camera produces unrecognizable, low-quality pictures). People still use cellular phones for regular voice conversations, but that is just a small percentage of the usage. Cellulars are used for games, chats, IM and for playing music. I even saw one woman at the bus, monitoring her kid in the kindergarten using a live video-stream to her phone.

I know, Hong-Kong is not the only place people use handhelds. But the intensity and the variety of usages were overwhelming. Another example of high-tech miniature gadget is the “octopus card”. This is a small and smart prepaid card that you get for free and charge with money. Using this card one can pay for many things; from busses and subway all the way to pay your “7-11” bill at the counter. The octopus card is state-full so in some conditions it charges you according to the pre-knowledge it holds. For example, it remembers in which station you entered the subway and it charges you accordingly at your final destination. This card was a great friend and I did not use my credit card at all. At the last Java One conference I saw a J2ME example of a smart card. I really hope that the octopus card has java inside.

The bottom line is that it looks like the future is in the palm of our hands. Handhelds are going to take a bigger part of our life. Programmers and architects should get to know handhelds and handhelds technologies like J2ME. Although the programs in these small devices might seem simple and not challenging (how hard it is to write the code for a simple pre-paid card?) these “simple” programs are extremely useful and sometime very complex to write. Moreover, when considering any new solution one must always take into account the handheld angle.

Is J2ME the right tool for handhelds and smart cards?

Tim O

AddThis Social Bookmark Button

Related link: http://www.javablackbelt.com/jbb/

Java Black Belt is an interesting site. It has a good set of community developed tests for projects such as Ant, JUnit, Hibernate, Spring, XML, Struts, JSP, and OO.

Tim O

AddThis Social Bookmark Button

Related link: http://wiki.fckeditor.net/FCKeditor

The problem was straightforward, all I needed was a rich-text editor that would allow me to create XHTML that I could then send back to the client. I already had a textarea, and I just wanted a rich-text replacement. I thought this was going to be simple, but the problem cost me hours. In this entry, I show the process I used to identify a suitable AJAX/Javascript library, read on…

All this for pretty rich text editors, doesn’t seem worth it.

Paul Browne

AddThis Social Bookmark Button

Related link: http://www.firstpartners.net/blog/web/web-20/2006/02/21/web-20-presentation-link…

Yesterday we presented the Irish Web 2.0 Event at the Morgan Hotel , Temple Bar , Dublin - the other half of ‘we’ being Fergal Breen of IrishDev. Being a Web 2.0 event, we made it a bit more interactive than your usual presentation, so I ended up learning a lot. Here are the top things that I didn’t know before yesterday:

1) In Ireland at least , awareness of Web 2.0 is highly concentrated in the tech , and not the business community. 90% of the audience described themselves as technical , despite the event being co-hosted by the Irish Internet Association (IIA), a business group. I expect this to change over the next 6 months following patterns elsewhere.

2) Walter (from Sxoop.com) described the recent Web 2.0 conference in London. One thing he said surprised me: He said that there was a feeling that developers in the area were doing it to ’scratch their own itch’ (a good thing) but were hostile to ‘Enterprise’ development (bad as somebody has to pay the bills!). A gap in the market for an ‘Enterprise Web 2.0′ conference perhaps?

3) 10% of the Audience were Johnny Cash fans. Johnny Cash is a perfect example of the ‘long tail’. 18 months ago (before his untimely demise and biopic starring Joaquin Phoenix) it was nearly impossible to get his records (in Ireland at least) - a classic case of ‘long tail’ demand. Now, he’s a blockbuster again, so mainstream shops are stocking his CD’s in high profile positions. In 18 months time , will be back on the long tail again?

4) Google has huge mindshare amoung Ajax developers and Web 2.0 people. Nearly every single person present had used Google maps (so much so that we didn’t need the demo video). Most were also aware of the awesome Ajax stuff coming out of the Googleplex such as the Ajax based XSLT transformation and image handling libraries.

5) People don’t want to do Javascript. While Ajax has rekindled their interest in this language, there was almost a relief that that frameworks such as DWR and Dojo do most of the work for you. To be fair, many people’s opinion are based on Javascirpt circa 1999, but there was a definate preference for using Atlas ,Ajax.net and Java Server Faces (JSF) / Oracle ADF.

6) There was a healthy representation of Microsoft people. Given that the consensus is that Web 2.0 and it’s Ajax capabilites are the most serious challenge to Redmond on the Desktop, it’s healthy to see such a strong interest. Healthy as in competition (from Firefox) has given us Internet Explorer 7 and will continue to drive innovation.

7) Nobody can agree what Web 2.0 is. This is not surprising considering that Web 2.0 is about individual experience. Big, shared, events like the Superbowl (or Champions League final , for us that prefer our football in other formats) are now the exeption rather than than norm. Even these events will be customised - choose your own camera angle, choose which sports blogs you read leading up to the game , choose the device (TV , PC, Mobile) that you want to watch on, and when you want to watch.

8) There is a healthy balance of Buzz and scepticism around Web 2.0. A lot of the companies (such as eats.ie) that are ‘doing’ Web 2.0 would not use the web 2.0 label. They’re doing the Ajax / online hosting / word of mouth marketing / self funding / continual updates thing , but they find that the label just gets in the way.

9) Some people were concerned about ‘how do you test Web 2.0 and Ajax apps?’. The answer - the same as before , only involve your users. While Ajax gives us incredible power (including the ability to ‘break’ the web browser), people have got used to certain conventions with Web and PC apps that will take time to evolve.

10) There was a lot of interest in using Agile techniques to deliver Web 2.0 apps (e.g. Flicker s update of code every half hour). Which is a nice lead in for the Agile event at the Irish .Net Developers Association.

Finally , if you are going to a joint presentation (with the two speakers stepping in and out as required), try to see the final version of the slides more than 10 minutes beforehand. You know who you are (Fergal!). Luckily , the feedback from the people so far has been good (e.g. Robert Burke. I think the word ’supurb’ was used. Was Kieran at the same event ? !

Were you there? Do you wish you were there? What do you think?

Tim O

AddThis Social Bookmark Button

Related link: http://www.xml.com/pub/a/2006/02/22/rome-parse-publish-rss-atom-feeds-java.html

Mark Woodman writes a great piece about ROME for XML.com titled “ROME in a Day: Parse and Publish Feeds in Java”. I’ve used ROME in a few applications that called for syndication, it’s a really simple way to generate RSS from a Java app.

Tim O

AddThis Social Bookmark Button

Related link: http://ndpsoftware.com/JSPXMLCheatSheet.html

Andrew Peterson of NDP Software has created a simple cheatsheet for JSP 2.0, JSP EL, and JSTL. I’m constantly “flipping” through the JSP 2.0 specs PDF trying to figure out what implicit objects are available in a JSP page and what the syntax is for fmt:formatDate, and Andrew has captured almost everything I needed in a single HTML page. del.icio.us.

Click here for the cheat sheet

Tim O

AddThis Social Bookmark Button

Related link: http://osgroup.raindance.com

If you are curious about Apache Geronimo, there is a recorded presentation by Jeff Genender over at raindance.com. Jeff gives a good overview of Geronimo: why it was created? what differentiates it from other servers? the sign up is free, and the presentation is about 71 minutes long.

click here to go to raindance.com

Tim O

AddThis Social Bookmark Button

Related link: http://jakarta.apache.org/commons/scxml

Stumbled upon an interesting utility last month: Commons SCXML promises to be an interesting tool for anyone who has to work with state machines. This component is based on a W3C recommendation form the Voice Working Group, and much of the initiall work has been completed by Rahul Akolkar.

Tim O

AddThis Social Bookmark Button

Related link: http://www.c-span.org

The hearing was chaired by Jim Leach (R-IA), and I believe that the committee was the House Subcommittee on International Relations (East Asia and Pacific). Regardless of where you stand on the issue, you have to admit that this is one of those interesting questions that involves an intersection of technology, economics, and government.

If you are interested in watching this hearing for yourself here are the links to C-SPAN. Note: These links require Real to be registered for the rtsp format:

  • House Hearing on Internet in China, Part 1 (realplayer)

    In Washington, DC, Chairman Representative Jim Leach (R-IA) and Chairman Representative Chris Smith (R-NJ) hold a hearing on the internet in China.

    2/15/2006: WASHINGTON, DC: 3 hr. 30 min.
  • House Hearing on Internet in China, Part 2 (realplayer)

    In Washington, DC, Chairman Representative Jim Leach
    (R-IA) and Chairman Representative Chris Smith (R-NJ)
    hold a hearing on the internet in China.

    2/15/2006: WASHINGTON, DC: 3 hr. 45 min.

Reactions to this hearing?

Tim O

AddThis Social Bookmark Button

Related link: http://saxonica.blogharbor.com/blog

Here’s an interesting resource. Michael Kay’s new Saxon Blog promises to be a good resource for anyone using Saxon XSLT.

Paul Browne

AddThis Social Bookmark Button

Related link: http://firstpartners.net/blog/

If your CV is like mine (viewable online), then the chances it is:

a) accurate but terse
b) full of technical details
c) covers years of your life in one sentence

but worst of all

d) is boring and doesn’t really show whether or not you have the skills, experience and attitude needed to do the job.

In fact, do you suspect that some people you are working with may have ’stretched the truth’ a little too far on their CV?

Now imagine if your CV was in a blog format. A good example from Texas is here (all 3rd party examples in this post have been picked at random via Google). Apart from being trendy, what are the advantages of doing your CV this way?

  • Because the sections in your Blog / CV are ‘tagged’ you can give more details, and let employers view just the areas that they are interested in.
  • Because you update your Blog / CV on a regular basis, with more information, it is harder to fake. A one or two page CV is easy to write as a work of fiction. A blog that represents your life for the last 3 years would take too much effort to fake, so it is more likely to be trusted.
  • Because you write about things you are interested in, people get a better idea of your motivation, and what you are really good at.

Taking this to extreme, your CV can be searchable via Google to allow recruiters to quickly see if you have the right skills and experience. This example of Thomas Hauchcorne is in French but you’ll easily find your way around the Google-Like interface.

What do you think, are blogs the new CV? If you’re looking to use Blogging to land yourself a new job, then Jobster isn’t too bad a place to start.

What do you think, are blogs the new CV?

Paul Browne

AddThis Social Bookmark Button

Related link: http://nounit.sourceforge.net

NoUnit is an open-source code coverage tool that shows you the effectiveness of your JUnit tests.

After a suitable pause , I’m now thinking of starting work on the next version of NoUnit. Some of the features I would like to see included are:

  • Eclipse Plugin , so that you can run NoUnit code coverage reports as easily as you do JUnit tests in Eclipse.
  • Support for JUnit 4 and Java 1.5 Annotations
  • Support for EJB 2.0, EJB 3.0 and Spring - currently NoUnit only shows direct calls between Java classes.
  • Various outstanding bugs and change requests from users.

Is there anything else you think should be included? Leave your comments on the NoUnit blog.

Is there anything else you think should be included?

Chris Adamson

AddThis Social Bookmark Button

This blog comes from two different places. The first is my decade-long general indifference to really using the clipping rectangle, which in Java2D is a shape that indicates what part of a Graphics object is to be painted in. It offers the potential for graphics optimizations because the rendering code can assume that anything outside of the clipping area is unchanged, meaning it can be copied from a back buffer, not repainted, etc., depending on context.

But I got burned the first time I played with the clipping rectangle (back in Java 1.0, it wasn’t an arbitrary shape…). Dutifully typing in programs from Laura Lemay’s Teach Yourself Java in 21 Days, I found that the Mac JDK 1.0 mis-implemented the clipping rectangle. Every time you set it, the resulting clipping rect would be the intersection of your rect and the existing clipping rect. This meant that setClip() calls could only make the clipping rectangle smaller, and ultimately making it impossible to draw to your Graphics. Not good. So, I was a little gun-shy about clipping after that, even after Sun was chased away from the Mac and the job of writing Mac Java runtimes fell to Roaster, Metrowerks, and ultimately Apple.

Fast forward to today. I seemingly can’t shake this insane idea I have about writing a kick-ass podcast editor with QuickTime for Java. Insane because I don’t have enough time to take care of my editing responsibilities for ONJava and java.net as it is. I guess I’m really itching to code something, and I think QTJ’s editing API’s would really help move such a project along quickly.

One of the things I worried about, though, is the idea of the waveform viewer. This is a custom component that represents the samples graphically, which requires (among other things) looking up a bunch of samples to determine how high to draw the bar. Yeah, there’s already one of these in Swing Hacks (courtesy of contributor Jonathan Simon), but this needs to be different because it won’t necessarily be able to load all the audio into RAM (or, at the very least, I want to just be able to call a QuickTime sound media’s getSample() and not care how the data gets to me). After all, at CD quality of 44,100 samples a second, a one-hour podcast would have 44100 samples/sec * 60 sec/min * 60 min/hr * 1 hr = 158,760,000 samples. If you zoom into a detail view of the wave-form, all the way down to the individual sample level (i.e., one pixel per sample), that component’s going to get mighty big.

That got me thinking that a component that’s tens of thousands, or even millions of pixels wide, would not necessarily be a good thing to put in a JScrollPane. After all, if you have a custom component, with a custom paintComponent() method, you’ll do all your painting, blissfully unaware of whether a given pixel is going to be seen through the scroll pane’s viewport or not, and if you’re showing just a few hundred horizontal pixels of something thousands of times wider, that’ll be wasteful. In fact, it will be intolerably expensive if you have to do a lot of work (e.g., looking up samples) in order to draw pixels that won’t even be shown.

That brings me back to the clipping rectangle. Graphics, an instance of which is handed to your rendering code in paintComponent(), has a getClip() method. I wondered to myself if this represented the sub-section of the Graphics that would actually be seen, i.e., the portion in the scroll-pane’s viewport. If so, there’s a potential for optimization: before you go to draw something, look to see if any part of it is in the clip area. If not, don’t bother painting it.

Here’s a piece of code to exercise this approach. It creates a custom component, PaintyThing, that consists of a horizontal series of numbered red boxes. By default, it draws 10,000 100×200 boxes, meaning the component is one million pixels wide. That should be an appropriately brutal test of the rendering optimzation.


import java.awt.*;
import javax.swing.*;

public class ScrollClip extends JFrame {

    public static final int PAINTY_HEIGHT=200;
    public static final int PAINTY_WIDTH_INCREMENT=100;
    public static final int PAINTY_COUNT = 10000;
    public static boolean useClipOptimization;
    static {
        String useClipPref = System.getProperty ("use.clip.optimization");
        useClipOptimization = (useClipPref != null) &&
            useClipPref.equalsIgnoreCase ("true");
        if (! useClipOptimization)
            System.out.println ("Run with -Duse.clip.optimization=true "+
                                "to use cliprect optimization");
    }

    JScrollPane pain;
    PaintyThing paintyThing;

    public ScrollClip () {
        super ("Scroll Clip");
        paintyThing = new PaintyThing (PAINTY_COUNT);
        pain =
            new JScrollPane (paintyThing,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        getContentPane().add (pain);
    }

    public static void main (String[] args) {
        ScrollClip sc = new ScrollClip();
        sc.pack();
        // force a reasonable size so swing doesn't really try
        // to show the whole paintyThing
        sc.setSize (PAINTY_WIDTH_INCREMENT * 3,
                    sc.getSize().height + 1);
        sc.setVisible(true);
    }

    class PaintyThing extends JComponent {
        int paintyCount = 1;
        Dimension calcSize = null;
        Stroke boxStroke = null;
        public PaintyThing (int i) {
            super();
            paintyCount = i;
            calcSize = new Dimension (i * PAINTY_WIDTH_INCREMENT,
                                      PAINTY_HEIGHT);
            boxStroke = new BasicStroke (3);
        }

        // not sure if these are useful.  habit.
        public Dimension getPreferredSize() {return calcSize;}
        public Dimension getMinimumSize() {return calcSize;}
        public Dimension getMaximumSize() {return calcSize;}

        public void paintComponent (Graphics og) {
            long inTime = System.currentTimeMillis();
            Graphics2D g = (Graphics2D) og;
            g.setColor (Color.white);
            g.fillRect (0, 0, getWidth(), getHeight());
            // System.out.println (g.getClip());
            Rectangle clipRect =
                (g.getClip() instanceof Rectangle) ?
                (Rectangle) g.getClip() : null;
            g.setStroke (boxStroke);
            for (int i=0; i<paintyCount; i++) {
                Rectangle paintBox =
                    new Rectangle (i * PAINTY_WIDTH_INCREMENT,
                                   0,
                                   PAINTY_WIDTH_INCREMENT - 4,
                                   PAINTY_HEIGHT);

                // performance boost - don't paint if no part of the
                // rect to paint is in the current clipping region
                if (useClipOptimization &&
                    (clipRect != null) &&
                    (! paintBox.intersects (clipRect))) {
                    // System.out.println ("don't paint " + i);
                    continue;
                }

                // System.out.println ("paint " + i);
                g.setColor (Color.red);
                g.draw (paintBox);
                g.setColor (Color.blue);
                g.drawString (Integer.toString (i),
                              (i * PAINTY_WIDTH_INCREMENT) + 10,
                              PAINTY_HEIGHT/2);
            }
            System.out.println ("paintComponent(): " +
                                (System.currentTimeMillis() - inTime));
        }
    }
}

The ScrollClip class is mostly just responsible for putting a PaintyThing in a scroll pane, then putting that in a reasonably-sized JFrame and putting it on screen. It also uses a static initializer to look to see if you set a system property, use.clip.optimization, to enable the optimization.

Look closely at the optimization, because that’s what matters. As it loops through the rectangle coordinates, it asks for any given rectangle “Am I doing optimization, does the Graphics have a cliprect, and is this rectangle I’m about to draw completely outside of the cliprect? If so, skip to the next rectangle.”

Here’s what the app looks like:

image

If you notice, I left in some println’s to show how long it takes to get through paintComponent(). Run with java ScrollClip and you’ll find that scrolling is somewhat unresponsive. That’s because the repaints are taking about half a second each (on a dual 1.8 G5 Mac):


paintComponent(): 354
paintComponent(): 389
paintComponent(): 348
paintComponent(): 445
paintComponent(): 389
paintComponent(): 351

Run again with java -Duse.clip.optimization=true ScrollClip to use the “paint only if necessary” optimization. Notice how much more responsive this version is. You can zip the scrollbar back and forth with impunity because the repaint time is consistently less than 10 ms.


paintComponent(): 5
paintComponent(): 4
paintComponent(): 8
paintComponent(): 5
paintComponent(): 6
paintComponent(): 4

Not bad for scrolling around a million-pixel wide component. Better than I expected, actually. Looking at paintComponent(), I can also see right away two further optimizations that could be made. Do you see them?

If you push the number of pixels higher, you see a fairly consistent two-orders-of-magnitude advantage to the optimization. Use 100,000 rectangles, and the optimized repaints will be in the 10’s of milliseconds (which is still great). As you go higher still, you approach two limits: the repainting is slow even with the optimization, and the width of PaintyThing approaches Integer.MAX_VALUE, which is the end of the party.

My Swing Hacks co-author, now a member of Sun’s Swing team, thinks this is something of an edge-case, since not that many people are creating custom components, and particularly not of this extreme size. He may be right; though I’ve created a lot of custom components in my work, they’ve never been millions of pixels wide until now.

In fact, I’ve assumed that I would probably need to drop the scroll pane and manage my own JScrollBar, dropping the fiction of the single component that shows the whole waveform and instead having one that just renders the part of the waveform indicated by the zoom level and the scrollbar. Still, it’s nice to see that that’s potentially an optimization to do later, and that use of the clipping rectangle could provide performance that’s good enough to use in early prototyping.

It also makes me think I should have been more aggressive about using clipping in my previous Swing work. Maybe the payoff won’t be big, but my sense of Swing performance is that there’s no single thing that slows down Swing, but rather that you die the “death of a thousand papercuts” from a deep hierarchy of less-than optimal layout and rendering choices. Examining the clip before you paint, and setting it yourself when you paint non-scrolling components, is a simple optimization that could basically be reduced to a standard refactoring step, and one that might score you some performance.

By the way, did you find the additional optiizations in PaintyThing.paintComponent() that I mentioned?

Paul Browne

AddThis Social Bookmark Button

Related link: http://www.firstpartners.net/blog/category/business/project/

No matter where you live, I’m sure you could tell me stories about ‘Good IT Projects that go Bad’. If you’re lucky , they happen to a ‘friend-of-a-friend’ , or you read about them in a Newspaper. Here in Ireland, our most recent example from the Newspapers is the story of a $199 million Healthcare system . The project was cancelled after it insisted on issuing million Euro Cheques to hospital cleaners. For the record , $199 million is about the price of two small hospitals.

Looking back, It now seems obvious that the Healthcare Payroll system was destined to fail. If you were working on the project, I’m sure it felt very differently at the time. How can your projects avoid a similar fate? While IT may sometimes seem disconnected from reality, the following guidelines show that ‘Real World’ lessons still apply.

  1. Know what you want and stick to it. If you’re building a house and change the plans several times the builder is going to fleece you, no matter how low the initial quote was. The same goes for IT Projects - if you change your mind after the price is agreed, you’re going to pay more.
  2. If you don’t know what you’re doing , find a friend who does. I know very little about houses, so when I was buying my own I got a friendly surveyor to check it out. With IT projects, this ‘friend’ should be genuinely on your side, and have something to lose (e.g. financial or reputation) if things go wrong.
  3. Little and often is better. Like exercise, smaller projects that deliver results little but early are best. If the results are good, try a second (and third) round to add more functionality based on the feedback from users.
  4. It’s been all done before. Tailored suits cost a lot more than ready-made ones - and most people are happy with a ‘Good enough’ instead of ‘Perfect fit’. There are literally thousands of ‘off-the-peg’ computer systems (both commercial and open-source) ready for final alteration to what you need.
  5. If you don’t understand the answer, ask more questions. Thankfully the days we sat and nodded at the Doctor’s Latin words are long gone. IT Suppliers may sometimes speak a different language, but if they can’t explain what they’re talking about in English that you understand, the chances are they’re trying to hide something.
  6. Don’t build on sand. Like houses , projects need good foundations. For IT Projects , the good foundations are sound knowledge of the Business Processes being coded into the system. Changing processes and changing IT systems at the same time is like building on sand.
  7. Sometimes the tortoise wins the race. Unless your Company’s entire business model is built around being the very first to market, then being a tortoise and letting others race ahead has very big advantages. Not only can you learn from other people’s mistakes, but the chances are you’ll get it at a much reduced cost - For example websites now cost a fraction of what they did during the dot.com boom.
  8. Use a safety net. When building houses, often the first thing to go up is scaffolding, for safety reasons. The equivalent safety net in IT is called ‘Unit Tests’. Not only do they help you get there faster, but they let you know if you’ve broken something you’ve already built.
  9. Be a good poker player. Good poker players never give away valuable cards. For IT projects, owning all cards mean just that - make sure that you have full rights to the solution so that you can still move tables and use a different supplier. Even if you never make the move, knowing that you can is an effective bargaining chip.

And finally …

When you are in a hole, stop digging. The decision to call a halt to the projects was no doubt a difficult one, and is to be applauded. Too often, the temptation is to keep on going and hope things will turn out right. Recognising problems at an early stage means there is more chance of being able to fix them.

Do you have any advice on how to stop ‘Good IT Projects going Bad?’

Advertisement