Posted by Stefan Camilleri on {2008.August.28}
/** The more we abstract, the more a performance hit we get. Paraphrasing Mr Donald Knuth, having an efficient and elegant solution, is an oxymoronic claim */
So is it all lost? I love code elegance, I find it exciting; and yes, I know that is a very geeky thing to say. Even though Java is potentially one of the most elegant languages around nowadays, the myriad of frameworks and modular approaches available lead to levels of abstraction that definitely have a performance hit on the vm.
But not all is lost, Kirk Pepperdine, who as most Java people know, is a top Java Champion, wrote an interesting article about this on sun.com {
I invite you all to hop over and have a look. The tips in here are not totally specific to Java, so you can learn a lot from this.
http://java.sun.com/developer/technicalArticles/Interviews/community/pepperdine_qa.html
}
Posted in dev, java, performance, tips | Tagged: dev, java, performance tuning, tutorial | Leave a Comment »
Posted by Stefan Camilleri on {2008.July.30}
/** A common problem which I have come across multiple times in the past is that of forcing a browser (any browser) to download a file rather than try to open it. */
There’s a myriad of solutions out there on the web discussing this very issue, and I never gave much thought to it until yesterday. {
I came across an excrept of code at my client which was trying to send a csv file to the client (i.e. the client pc), yet the browser (all flavours) insisted on trying to render it, rather than download it.
The solution turned out to be particularly simple; something we all learnt how to do very well when we wanted some sweets as kids… i.e. LIE (to the browser this time)
All you have to do is set the content type to application/binary and the browser will simply not bother trying to do anything with it.
Here’s the magic expression in Java, yet of course this also applies to any other lingo (and if you have a problem, ask me, tell me your language, and if I can, I’ll show you how).
response.setContentType("application/binary");
NOTE: IE works slightly different from other browsers (what's new?), in that if you cancel the download, it will close the socket throwing an exception on the server. You of course will need to cater for this.
}
Posted in dev, java | Tagged: java | 1 Comment »