Links

  • 1. Sogeti
  • 2. JBoss
  • 3. IBM
  • 4. Oracle
  • 5. SpringSource
  • 6. NL-JUG
  • 7. Java

Archives

Syndication  RSS 2.0

RSS 1.0
RSS 2.0

Bookmark this site

Add 'JCN Blog' site to delicious  Add 'JCN Blog' site to technorati  Add 'JCN Blog' site to digg  Add 'JCN Blog' site to dzone

Posted by Barend Garvelink at 23:16 on Sunday 2 March    Add 'Awkward little oversight in java.util.Formattable' site to delicious  Add 'Awkward little oversight in java.util.Formattable' site to technorati  Add 'Awkward little oversight in java.util.Formattable' site to digg  Add 'Awkward little oversight in java.util.Formattable' site to dzone

I was implementing the rarely used java.util.Formattable interface on a class today when I ran into an awkward little oversight. The single-method formattable interface is defined as follows:

/**
 * [...]
 * @since  1.5
 */
public interface Formattable {
    //Javadoc left out for brevity
    void formatTo(Formatter formatter, int flags, int width, int precision);
}

The way to implement this method, as per an example in the Javadoc header, is to build your string representation and then call formatter.format(String) on the given formatter instance to include it in the output. This does mean that if you’ve used a StringBuilder (or StringBuffer) during formatting, you have to toString() it, which involves copying the underlying char[] in memory and, one method call later, copying the entire thing again as your string is embedded in the formatted output.

You can work around this by calling formatter.out(), which returns an instance of java.lang.Appendable. Appendable has a method signature that accepts CharSequence (which StringBuilder implements), and passing your text to the formatter in this way saves you one of these two array copies. Depending on context and frequency of use, this can be anything from a “root of all evil” kind of optimization to a noticeable improvement.

Now, let’s look a little closer at the bit of Java code posted above, the Appendable interface and the calling code in java.util.Formatter that invokes the Formatter.formatTo(...) callback we’re implementing.

/**
 * [...]
 * @since 1.5
 */
public interface Appendable {
    //...
    Appendable append(CharSequence csq) throws IOException;
    //...
}

The code that calls into our method:

/**
 * [...]
 * @since  1.5
 */
public final class Formatter implements Closeable, Flushable {
//...
    private void printString(Object arg, Locale l) throws IOException {
        //...
        ((Formattable)arg).formatTo(fmt, f.valueOf(), width, precision);
        //...
    }
//...
}

Can you spot the problem?

Yep. Appendable.append(CharSequence) declares IOException. The calling code declares IOException. The interface we’re implementing does not. There’s absolutely nothing meaningful our formatting code can do with that exception other than to re-throw it, but it’s not allowed to. Instead, we’re forced to wrap the IOException inside some RuntimeExeption, thereby obscuring the original stack trace and obfuscating the formatTo implementation with a try...catch block.

Clearly, the only proper solution is for Sun to declare IOException on the Formattable.formatTo(...) method. This is technically a breaking change, but I doubt anyone would notice. The Formattable interface is rarely used as it is and it’s a platform callback invoked by a method that won’t notice the difference. It could be worse. Any takers?

Posted by Barend Garvelink at 22:21 on Tuesday 4 December    Add '“The future of reading”' site to delicious  Add '“The future of reading”' site to technorati  Add '“The future of reading”' site to digg  Add '“The future of reading”' site to dzone

Een paar dagen terug postte ik over de Amazon Kindle. Op slashdot stond vandaag een linkje naar een blog post getiteld The Future of Reading, waarin een aantal goed gekozen paragrafen uit de Terms of Service van dat apparaat worden gerelateerd aan citaten van o.a. Jeff Bezos (oprichter en CEO van Amazon) en George Orwell. Confronterend…

Posted by Barend Garvelink at 13:52 on Sunday 2 December    Add 'SAP Memory Analyzer' site to delicious  Add 'SAP Memory Analyzer' site to technorati  Add 'SAP Memory Analyzer' site to digg  Add 'SAP Memory Analyzer' site to dzone

SAP has an interesting tool called SAP Memory Analyzer. It’s basically a JVM profiler, altough limited to memory and GC analysis. It’s built on Eclipse RCP and it’s a free download, altough registration is required.

SAP Memory Analyzer screenshot

At the moment, it will only attach to SAP JVM’s, but they’ve announced they’re open-sourcing it, so this is likely to change in the forseeable future.

Profilers are a fantastic thing to diagnose performance problems, or even just to satisfy your curiosity. The modern fancy-pants GUI based profilers (notably: YourKit) are a breeze to use and if you’ve never used one, you should, right away. You’ll be enlightened.

YourKit profiler screenshot

Since you’re probably not running a SAP JVM, the subject of this post is useless to you. Keep an eye on it though, cause I suspect broader JVM support to be the first thing added after it’s opened up. Free of charge, it’s easily added to any toolset. In the mean time, I recommend picking up the trial version for YourKit, it’s excellent, and very powerful. It gives insight in a lot more than just memory use (monitors and locks, for one thing) and lets you compare snapshots, which is brilliant.

Posted by Barend Garvelink at 17:34 on Tuesday 20 November    Add 'Amazon heeft het toch beter begrepen…' site to delicious  Add 'Amazon heeft het toch beter begrepen…' site to technorati  Add 'Amazon heeft het toch beter begrepen…' site to digg  Add 'Amazon heeft het toch beter begrepen…' site to dzone

Een paar weken geleden presenteerde Selexyz in Nederland de Iliad, een e-book reader in zakformaat. Het is een leuk apparaatje, met een e-ink display. E-ink is helemaal passief, heeft geen backlight, en leest dus echt als papier, je krijgt geen eyestrain zoals bij een CRT of TFT. Toen de aankondiging van dit ding onlangs het NOS Journaal haalde was ik gelijk enthousiast… tot ik zag dat ze er 650 euro voor vragen en er nauwelijks ebooks voor te krijgen zijn.

Dan amazon.com… een paar weken later (vandaag) presenteert dat de AmazonKindle. Een e-book reader in zakformaat, e-ink… met 400 dollar een stuk goedkoper dan de Iliad, al is de laatste qua afmetingen en schermresolutie wat beter bedeeld.

Het grote verschil zit hem in het content-delivery model. Waar je bij Selexyz de boeken vanaf je PC in een gewone webwinkel koopt en met USB of WiFi naar je apparaat kopieert, gebruikt Amazon het mobiele telefoonnetwerk1. Waar Selexyz een vrij beperkt assortiment heeft is Amazon begonnen met het aanbod, in plaats van het apparaat. Amazon heeft gelijk al 50000 titels beschikbaar, plus een aantal toonaangevende kranten en weblogs.

De Kindle is altijd online, en je krant- en blog-subscriptions worden gepushd (Blackberry style). Belangrijker is dat jij op ieder moment bij de webwinkel van Amazon terecht kan om nieuwe ebooks te kopen, en wanneer je iets koopt wordt het onmiddellijk naar je kindle gepushed. Impulsaankopen worden dus volledig uitgebuit. Tenslotte heeft Amazon ingezien dat mensen geen verborgen kosten willen, en betaalt Amazon dus voor het mobiele dataverkeer (een les die de Nederlandse telco’s maar niet willen leren).

Conclusie kan alleen maar zijn dat Amazon het zó veel beter begrepen heeft dan iedere andere speler op de markt… als ze deze hand goed uitspelen dan wordt dit ding groot, heel groot. I can’t wait.

Selexyz Iliad Amazon Kindle
Selexyz Iliad Amazon Kindle

1) CDMA, geen GSM, dus voorlopig alleen in de USA bruikbaar.

Posted by Barend Garvelink at 15:28 on Monday 24 September    Add 'VMWare Player 2.0.1' site to delicious  Add 'VMWare Player 2.0.1' site to technorati  Add 'VMWare Player 2.0.1' site to digg  Add 'VMWare Player 2.0.1' site to dzone

Versie 2.0.1 van VMWare Player is uit. Deze release fixt een paar remote vulnerabilities in de DHCP service. Get it now…

Posted by Barend Garvelink at 17:31 on Thursday 30 August    Add 'Effective Java, second edition' site to delicious  Add 'Effective Java, second edition' site to technorati  Add 'Effective Java, second edition' site to digg  Add 'Effective Java, second edition' site to dzone

Ik zag toevallig op amazon dat de second edition van het geweldige Effective Java in november leverbaar wordt. Je kunt hem al pre-orderen.

Doen! :-)

Posted by Barend Garvelink at 0:07 on Sunday 10 June    Add 'WTF is a Data Grid, anyhow?' site to delicious  Add 'WTF is a Data Grid, anyhow?' site to technorati  Add 'WTF is a Data Grid, anyhow?' site to digg  Add 'WTF is a Data Grid, anyhow?' site to dzone

…that’s the title of Cameron Purdy’s latest blog. Like most of what he’s written lately, much of it is dedicated to just how brilliant Coherence is, but in the post is a definition of data grids that’s really quite useful.

A data grid allows an application to manage large amounts of live, transactional information in the middle-tier, benefiting from locality of information available at in-memory speed.

Using synchronous replication of information, the data grid achieves [...

...]automatically utilizing the full extent of the grid infrastructure.

WTF is a Data Grid, anyhow? (~600 words)

Posted by Sander van Der Waal at 12:20 on Friday 1 June    Add 'Global Google Developer Day' site to delicious  Add 'Global Google Developer Day' site to technorati  Add 'Global Google Developer Day' site to digg  Add 'Global Google Developer Day' site to dzone

Google organized a Google Developer Day yesterday, that was truely global because it was held in ten countries simultaneously (timezones permitting). On java.net an interesting report has been written about the sessions in California. It has some nice features on Google behind the scenes, as well as some interesting links on Google Maps and Google Desktop Gadgets.

Posted by Hans-Jürgen Jacobs at 8:23 on Thursday 17 May    Add 'Extreme GUI Makeover 2007 Video #1' site to delicious  Add 'Extreme GUI Makeover 2007 Video #1' site to technorati  Add 'Extreme GUI Makeover 2007 Video #1' site to digg  Add 'Extreme GUI Makeover 2007 Video #1' site to dzone

Download the first video of Extreme GUI Makeover 2007, presented at JavaOne. This video shows what happens when an exception is thrown internally. This effect was inspired by applications that display cryptic error messages meant for programmers only. Because those messages usually expose the internals of the application, we thought it would be a good idea to show all of the internals… The internals shown in the video are an accurate representation of the application’s source code: cranky, rusty, patched, full of holes and made of gears that barely connect to one another. [curious-creature]

Extreme GUI Makeover

Posted by Hans-Jürgen Jacobs at 11:10 on Tuesday 8 May    Add 'Salil Deshpande: Spring is the new Java EE' site to delicious  Add 'Salil Deshpande: Spring is the new Java EE' site to technorati  Add 'Salil Deshpande: Spring is the new Java EE' site to digg  Add 'Salil Deshpande: Spring is the new Java EE' site to dzone

Salil Deshpande, ex-CEO of The Middleware Company, attended TheServerSide Java Symposium after a long hiatus. He shares his perspective and experience this article is partly human-interest and partly technical. The primary conclusion: Spring is the new Java EE version. [theserverside] [direct to discussion]


© 2018 Java Competence Network. All Rights Reserved.