Top 10 Most Read Last Week On Javablogs.com, Week 20


Most read last week

  1. The Worst Java Job Interview Questions. (269): Why are you looking for a job? Strictly speaking, this is not a java question, but it shows up in almost every job interview I've been to. [read]

  2. Goodbye Ant , Welcome Maven 2 (219): After years of using Ant for building my applications, I have moved to something different, Apache Maven 2. And now it seems there is no looking back. [read]

  3. Google Web Toolkit: A Brief Review (219): Google has released GWT - a java window toolkit which converts your java applications (using the toolkit API) to javascript (incl. AJAX) and HTML. [read]

  4. A *bold* paper against Threads (214): Edward A. Lee wrote a paper called "The Problem with Threads", you can find his pdf paper here. There is no rant here but facts, and sound reasoning. [read]

  5. Outsourcing your code is so cheap ... but why are so many jobs coming back from their indian trip ? (202): There are websites where you can get very cheap developpers, here are the one I know: http://www.getacoder.com/ http://www.rentacoder.com/ http://www.getafreelancer.com/ http://www. [read]

  6. Signs You're a Crappy Programmer (and don't know it) (190): Please read this great post from Damien Katz, and watch the signs Java is all you'll ever need. "Enterprisey" isn't a punchline to you. [read]

  7. Google Web Toolkit: Web Applications Just Got Harder (182): Oh the buzz. Oh the excitement. Oh the AJaX Gods has released their secret sauce with an Apache license. Google Web Toolkit allows one to develop AJaX web applications entirely in Java, [read]

  8. PDFs available for JavaOne 2006 Sessions (177): Check out the JavaOne 2006 Conference Session Catalog: “Presentation files available for download are indicated with a paperclip icon. After clicking on a paperclip, [read]

  9. Google Web Toolkit for building AJAX apps in Java (173): Google has introduced a toolkit for building AJAX applications in Java, though its in beta. It has also supplied some sample applications with the kit. [read]


Most read last week-end

  1. PDFs available for JavaOne 2006 Sessions (177): Check out the JavaOne 2006 Conference Session Catalog: “Presentation files available for download are indicated with a paperclip icon. After clicking on a paperclip, [read]

  2. Cringely: Why IBM Is in Trouble (159): Robert X. Cringley doesnt have a high opinion of IBM. Last week, he wrote, ...what is IBM? IBM is a disaster-in-the-making. [read]

  3. JavaOne Gossip: NetBeans Pulls a Prank on Eclipse (147): Humor makes life fun. Life just got a lot funnier. For some I guess. netBeans - Eclipse 1-0. Post your suggestions on how Eclipse should get even. [read]

  4. Day 5: McNealy, Gosling, Gage: "Forget the box" (139): With a mixture of sadness, relief, and hope for the future, former Sun CEO Scott McNealy took the stage this morning at the final keynote address of JavaOne 2006. [read]

  5. Project Harmony gets AWT/Swing Contrib from Intel (127): This may be a bit late but at JavaONE this year JEdit was shown running on the AWT/Swing contribution that Intel gave to Project Harmony. [read]

  6. Java 7.0 (Dolphin): Evolving in the Ecosystem (121): Sun developer Danny Coward says "Compatibility is king", but Sun is not staying still in the Java space. [read]

  7. This is genuine Microsoft (120): I started playing with Google Web Toolkit beta- actually I didn’t really start. Because I had to uninstall IE7 (which I don’t use at all), but hey I’d been curious. [read]

  8. Become a Java Champion, stay in useless Country, Learning Java for what? (120): I just thinking, what should we learn Java? Why dont use dotNet, I read Matt blog about his income US$ 200k more, or Mike Conan in OZ, that become the good best company. Today I just dont know, [read]

  9. jBixbe: a java tool I consider ... buying ! (90): I found this tool on Erik's linkblog, thanks to him ! [read]


Top 10 Most Read Last Week On Javablogs.com, Week 19


Most read last week

  1. Axis2: Why bother? (257): The Axis team is kicking up a big fuss about their recent release of Axis 2 (1.0!) Surprisingly, this library is so so abysmally bad, [read]

  2. Google trends proves: Java is doomed (251): Google trends is a nice idea, and I had to apply it adhoc to Java, Ruby, Python and C#. Interesting results, I can see a decline in Java! [read]

  3. Rich Open Source Webmail that doesn't suck (219): Guys...lets face it. Squirrel Mail... So check out our killer rich webmail. [read]

  4. Your Next Programming Language (216): Many people talk about how, as software developers, we should learn new programming languages frequently. [read]

  5. How to recognize a "Sacred Code" (210): You know you are dealing with a "sacred code" when you ask a previous developer (or the designer of the code) a question about the code and his immediate reply is .... [read]

  6. All you ever wanted to know about Workflow and how it relates to Java, Transactions and Concurrency (204): Read this blog carefully and you're in for a PAYRAISE. Workflow and business process technology will be essential in developing next generation applications. The knowledge about it is scarce. [read]

  7. Omg - I love this (Mac users may not) (203): This guy doesn't like Macs Damnation this is funny.... [read]

  8. 7 Reasons Why Web Apps Fail (179): Web applications are popping up faster and faster every day, and quite a few are using the power that Ajax offers to their advantage. [read]

  9. Scaling out 37 Signal-style applications is convenient (179): I had someone telling me that: Ruby can scale. Basecamp prooves that. Now, you all know that I do not think that Ruby has ANY problems with scaling. However, [read]


Most read last week-end

  1. Omg - I love this (Mac users may not) (203): This guy doesn't like Macs Damnation this is funny.... [read]

  2. How to Design a Good API (176): I was reading this presentation on the Design of API's by Joshua Bloch it talk's about how to design a good api but more importantly the reasons why doing certain things results in a good design. [read]

  3. JRuby on Rails Is Born (172): JavaOne attendees are in for a treat. Not only will they be receiving a DDJ issue which calls Rails a tipping-point to a new era in enterprise computing (or something like that)... [read]

  4. JavaOne day -1 : Bird Strike (147): The plan was to fly out from Sydney to San Francisco today. The plane was fueled, the travelers boarded. The aircraft taxied out to the runway, takeoff speed was reached, [read]

  5. 10 things i love about my Mac (125): A switcher Top 10 of nice things on Mac OS X: 1. The way programs live in the system (no registry shit) 2. The shell 3. Firewire boot capabilities 4. Apps like iChat, iSync and Addressbook 5. [read]

  6. YouTube bandwith usage/costs ... AMAZING ! (121): While looking for successfull video hosting I found this techcrunch article about youtube called Did YouTube Just Raise another $25 million? [read]

  7. 10 things i hate about my Mac (113): A switcher Top 10 of ugly issues with Apple Mac OS X: 1. No @ key in boot camp windows installation available 2. All banking programs on mac really suck 3. adv. [read]

  8. Commons Collections 3.2 Released (113): Commons Collections 3.2 has been released. Commons Collections is a library that builds upon the Java Collection Framework. It provides additional Map, [read]

  9. GoogleTrends : Java vs C# vs PHP (112): La comparaison est un poison. Ceci dit, comparer "l'intérêt" pour java, C# et PHP avec GoogleTrends, le nouveau service de Google, était très tentant... [read]


First Steps With EhCache

If you need to cache objects in your system, Ehcache is a simple cache written in Java, widely used and well tested. I will present here a short tutorial on how to use EhCache for people who don't want to look around the documentation at first, but just want to test if it works in their project and to see how easy it is to setup.
Installation
Download Ehcache from the Download link on http://ehcache.sourceforge.net. Current release is 1.2.
Unpack Ehcache with an unpacker that knows the tgz format. For unix users, it is trivial, for windows users, 7zip is a free (and open-source) unpacker. It is probably the most popular, but there are other ones like tugzip or izarc or winrar.
In your java project you need to have ehcache-1.2.jar, commons-collections-2.1.1.jar and commons-logging-1.0.4.jar (versions numbers may vary) in your classpath, those libraries are shipped with ehcache.
Cache Configuration
Write an ehcache.xml file where you describe what cache you want to use. There can be several files per project, several cache descriptions per file. I use here a persistent cache. Configuration file is well described at http://ehcache.sourceforge.net/documentation/configuration.html
<ehcache>
<cache name="firstcache" maxElementsInMemory="10000" eternal="false" overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0" diskPersistent="true" diskExpiryThreadIntervalSeconds="120"/>

</ehcache>

Code
static  {  
//Create a CacheManager using a specific config file
cacheManager = CacheManager.create(TestClass.class.getResource( "/config/ehcache.xml"));
cache = cacheManager.getCache("firstcache");
}

/**
* retrieves value from cache if exists
* if not create it and add it to cache */
public String doit(String key, String value) {
//get an element from cache by key
Element e = cache.get(key);
if (e != null) {
value = (String)e.getValue();
LOGGER.info("retrieved "+ value+" from cache ");
}
else {
value = "new value" ;
cache.put(new Element(key, value));
}
return value;
}

/**
* refresh value for given key */
public void refresh(String key) { cache.remove(key); }

/**
* to call eventually when your application is exiting */
public void shutdown() { cacheManager.shutdown(); }
Conclusion
Using EhCache is as simple a using a Java Map with an additional configuration file.

Null vs. Errors

I am not particularly a fan of  JCS (Jakarta Cache System) as I find ehcache code very clean and simple. But I have to say the author has some good comments on the site:
 
Nulls vs. Errors
 
I started to support ObjectNotFoundExceptions for failed gets but the overhead and cumbersome coding needed to surround a simple get method is ridiculous. Instead the JCS return null.
 
For having seen too many times the ObjectNotFoundException "pattern", I can only agree!
 

Algorithms in Java (Third Edition) Book Review

The book Algorithms in Java is huge, but unlike the usual huge books, the content is very interesting. It can be used as reference material, or as toilet book (to learn things while you're wasting time in the toilets).

You will learn simple things, like what is the "raison d'être" of linked lists. The author gives very good examples to illustrate his propositions. He explains through the sieve of erathostene and through Josephus problem the advantages of arrays or linked list.

You will learn step by step everything that is to be known in algorithms. Recursion, divide and conquer, Tree knowledge will be useful for the later sorting and searching chapters.

The chapter on Hashing will make you understand very clearly why the source of String.hashCode() is
public int hashCode() {
  int h = hash;
  if (h == 0) {
     int off = offset;
     char val[] = value;
     int len = count;
     for (int i = 0; i <  len; i++) h = 31*h + val[off ++];
     hash = h;
  }
  return h;
} 

There might be too much info on different types of sorting algorithms and the book becomes there more a reference book than anything else. But overall, you will learn plenty with this book. It is very well written, complete, and will refresh one's memory. I find it useful to read back things I learnt after a few years as I then have a very different view of the subject, and I pay closer attention to some details I completely missed the first time (sometimes).
Tags:

Caching HTTP Responses in Java

Caching HTTP response can dramatically improve performance of your app if what you generate is in reality not very dynamic. There are many free caching frameworks in Java. Most popular seem to be ehcache, oscache, jcs and JBoss Cache.

ehcache is quite simple to use and its code is clean. They have a CachingFilter that you can put in your webapp server to cache transparently HTTP responses. However as the framework only allows you to store Objects (which makes sense for most uses), I was wondering how they cached the HttpResponse which is a stream. I was a bit disappointed by the answer, they just create a copy ByteArrayOutputStream and call toBytes() to store it in the cache. While this is optimal for a memory cache store (the whole response will anyway be in the cache, although I am not sure if they check for particularly big responses to avoid caching those or try to cache those) I don’t think it is that good for a disk cache store.

Ideally one would like the response to be stored using a buffer, to avoid having the whole response in memory. This would enable a much higher concurrent use. I think it is doable by writing your own CachingFilter and by using the concurrent utils Queue to block writing when the buffer is full.

I googled for this kind of stuff without success. I only found solutions similar to ehcache one (for example sun CachingResponseWrapper and CachingFilter or oscache CacheFilter (a bit more careful, but still a toBytes())) I wonder why it is not already done and public.

Javablogs.com 2005 Top 20

Most read in 2005

  1. New in Hibernate 3: Criteria API enhancements (816): Projection, aggregation, subselects, detatched criterias - its all there in the Hibernate 3 Criteria API. Let me show you some examples, starting with the new projection API.… [read]

  2. Hello, IDEA! (555): From the recent Java IDE discussions, it seems like there's a good portion of Java programmers who don't know IntelliJ IDEA, or simply haven't tried it yet. In this short screencast,… [read]

  3. Hey Gosling: This is why we don’t use Java 5.0 yet! (461): Whenever there is a major JDK update everyone on the Sun Microsystems side seems to love to beat the drum of upgrading.… [read]

  4. MSN7.5?? (450): ?????Google Talk????????????????????????????????????Google Talk???????? Google Talk????????????????????????????????????   [read]

  5. The worst code I've ever seen. Yes, that's true. (422): I've been in this business for 25 years and have been programming since the mid seventies. Even when I was a young pup, full of bright ideas and hubris and those around me were at least as bad,… [read]

  6. JSP is officially dead (407): Well, it looks like with the Final Draft of Java EE 5, the final nail has been placed in JSP's coffin.… [read]

  7. My wife is hot and she can code, too (400): My wife Keri loves puzzle games--tetris, scrabble, crosswords, text twist--any game where you have to figure something out, she's on it. She has a degree in CS, and is employed as a UI specialist,… [read]

  8. IBM announced SOMA - Service-Oriented Modelling and Architecture (396): [read]

  9. G-mail runs on Tomcat???!!!!! (390): Well, hello guys and gals...haven't been in the Java blog scene recently, but am glad to know Java is going strong as ever (not that I ever doubted it,… [read]

  10. Web Services articles (374): [read]

  11. Bill Gates tries Firefox (362): Tim Weber of the BBC reporter rustles up Bill Gates quote of 2005: Bill Gates is one of the people with Firefox on his computer, so I asked him for his opinion. I played around with it a bit,… [read]

  12. Language Oriented Programming: Everything is a Language (361): Some people don't 'get' Language Oriented Programming. It's a different perspective. Once you make the mental shift, everything starts to fall into place. Over the past few months,… [read]

  13. The killer app for Web 2.0 has arrived (356): Time to throw in the towel, 37 Signals. The future has arrived: iClock (via flocksucks) [read]

  14. New Search Engine Blows Google Away (356): After months of incredibly secret development, PreviewSeek Limited has launched the PreviewSeek search engine. My initial impression? It blows google away with its far more powerful searches. [read]

  15. Death to Apache (356): So our Apache heros have now decided that it isn't quite enough to prove to the world that they are abysmal failures at producing a J2EE container,… [read]

  16. WebSphere 6.0 System Management Enhancements (356): [read]

  17. It's Official, Struts is History! (352): [read]

  18. What Steve isn't telling us (348): So the rumors were true, Apple is really switching to Intel.  There are a lot of interesting things in Steve Jobs' keynote, as usual, but the most interesting part is,... [read]

  19. RE: Why I Ditched Hibernate (346): I saw this post and couldn't help but respond. The post's author, Bruce, is ditching Hibernate and Spring b/c he wants to use a connection pool (configured in Tomcat) instead.… [read]

How To Use Java With Blogger: A Tutorial

Blogger has a REST API. I use it to retrieve particular posts or to post transformed data. There is no Java API that I know of, but you will see here it is not very difficult to interface with Blogger API in Java using plain old XML.

Using libraries commons-httpclient and DOM4J it would be quite easy to implement your own Java Blogger API as the following code will suggest.

Authenticate
All requests need to be authenticated and are done in HTTPS. I use common-httpclient to perform requests. Here is how to setup the client:
private  HttpClient initHttpClient()
{
HttpClient client = new HttpClient();
List authPrefs = new ArrayList(2);
authPrefs.add(AuthPolicy.DIGEST );
authPrefs.add(AuthPolicy.BASIC);
client.getParams().setParameter (AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
client.getState().setCredentials(new AuthScope( "www.blogger.com", 443, AuthScope.ANY_REALM), defaultcreds);
return client;
}


Get Your Posts
To retrieve the posts, you just have to query the right url, and parse the XML response. I prefer to use DOM4J, because of its handy asXML() method to print a node as XML. For simplicity I use a Map to store an XML entry.

public Collection getPosts() throws  HttpException, IOException, ParserConfigurationException, SAXException, DocumentException 
{
GetMethod get = new GetMethod("https://www.blogger.com/atom" +"/"+blogId);
int statusCode = client.executeMethod(get);
if (statusCode != HttpStatus.SC_OK)
{
throw new RuntimeException(" Could not make HTTP request properly: " +get.getStatusLine());
}
InputStream response = get.getResponseBodyAsStream();
SAXReader reader = new SAXReader();
Document doc = reader.read(response);
Collection posts = new ArrayList();
List entries = doc.getRootElement().elements("entry");
if (LOG.isDebugEnabled())
{
LOG.debug("found "+entries.size()+" entries");
}
for (int i = 0; i <entries.size();i ++)
{
Element entry = (Element) entries.get(i);
Map m = new HashMap();
for (Iterator it = entry.elementIterator();it. hasNext();)
{
Element detail = (Element) it.next();
String name = detail.getName();
if (name.equals("link"))
{
m.put("link ",detail.attribute("href").getValue());
}
else if (name. equals("content"))
{
m.put("content",detail.asXML());
}
else
{
m.put(name,detail.getTextTrim());
}
}
posts.add(m);
if (LOG.isDebugEnabled())
{
LOG.debug( "found="+m.get(" title")+", url= "+m.get("link"));
}
}
return posts;
}

Create XML for a new Post
Nothing particular here, just XML production.
private String createXmlForCreatePost(String postTitle, String postContent) throws   IOException, DocumentException
{
SAXReader xmlReader = new SAXReader();
xmlReader.setValidation(false );
Document doc = DocumentHelper.createDocument();
QName rootName = DocumentHelper.createQName("entry", new Namespace("", "http://purl.org/atom/ns# "));
Element root = doc.addElement(rootName);
Element title = root.addElement("title");
title.addAttribute("mode"," escaped");
title.addAttribute("type ","text/plain");
title.setText (postTitle);
Element generator = root.addElement("generator ");
generator.addAttribute("url" , "http://31416.org");
generator. setText("31416 Java Generator ");
Element content = root.addElement("content ");
content.addAttribute("type" , "application/xhtml+xml");
//Element div = content.addElement(DocumentHelper.createQName("div",new Namespace("","http://www.w3.org/1999/xhtml")));
//div.add(...); //YOUR XHTML HERE
StringWriter result = new StringWriter();
XMLWriter writer = new XMLWriter (result);
writer.write(doc);
writer.close();
return result.toString();
}

That's it


Last week Javablogs.com top 10


Most read last week

  1. Stupid Command Prompt Tricks (289): These Stupid (Windows) Command Prompt Tricks actually look rather useful. [read]

  2. The truth about Tudu Lists!! (260): I've now been working on Tudu Lists for more than one year, and I'm releasing today version 1.1. With this latest release, it is now time for me to tell the truth about Tudu Lists.… [read]

  3. Toplink vs hibernate (258): I still remember the excitement I felt when I started working on Toplink. It was early 2000. Before that, I was working mainly in visual c++.… [read]

  4. Why RedHat bought JBoss (249): RedHat has a market cap of roughly 20x revenues, which quite frankly is unheard of; most companies would kill to have a P/E ratio that high, let alone a price-to-sales ratio!… [read]

  5. Red Hat Acquires JBoss (214): It is official. Now the corp office is in my back yard!… [read]

  6. Google Calendar is now live (212): The subject says it all... Go ahead: log in, play around and post your suggestions and impressions as long as it's not "It doesn't work on Safari" (usually the... [read]

  7. Why is Tomcat called Tomcat (208): Every now and again the topic of why Tomcat is called Tomcat pops up and I don't know anyone who actually knew Anyway I thought I would look it up so if anyone else asked me I could tell them the… [read]

  8. RANT: Eclipse Sucks (186): Eclipse has an AI engine that realizes when I haven't used it often enough for it to have burned me recently to kick in and do something really painful to me.… [read]

  9. Top ten use case mistakes (170): Top ten use case mistakes -Tyner Blain: We’re reiterating the top five use case mistakes from Top five use case blunders and adding five more. For details on the first five, go back to that post.… [read]


Most read last week-end

  1. Top ten use case mistakes (170): Top ten use case mistakes -Tyner Blain: We’re reiterating the top five use case mistakes from Top five use case blunders and adding five more. For details on the first five, go back to that post.… [read]

  2. Netbeans versus Eclipse (155): Eclipse has been the leader of the pack for the last five years but with Netbeans becoming free, is Eclipse's title of most popular IDE coming to an end.… [read]

  3. MacBook vs. Athlon XP Java benchmark (150): So i finally made a first mini benchmark regarding my new hardware. Of course i was curious how the macBook performs against my old (somewhat outdated) PC platform.… [read]

  4. Eclipse 3.2 RC1 Released (143): Eclipse 3.2 RC1 is out and is available for download. Other Callisto release projects are releasing over the next two weeks. 39 words.… [read]

  5. 7 Hour Daily Commute (139): This person does an astonishing 7 hour commute to get to work. Everyday. And he's been doing it since 1989. I'm too astonished to criticize. Also, it's just too easy..... [read]

  6. Google Calendar - Oh so close! (135): It took me a few years to switch from Yahoo!… [read]

  7. MacBook Pro Update (121): I’m loving my new MacBook Pro, but… it’s definitely far from perfect.… [read]

  8. Next Generation Frameworks are only superficially competitors (117): There's an interesting thread over on the Grails mailing list.… [read]

  9. Is Memory Management in Java Garbage? (117): A friend of mine who was learning C# commented he felt C# was a more powerful because you had to memory manage yourself and it took more effort to create and destroy objects.… [read]


Web Services No Better Than CORBA?

Richard Monson-Haefel (RMH), author of the famous Enterprise Java Beans (O'Reilly) and of a Web Services book is making an alarming claim about JAX-WS, the new Java web services standard:
JAX-WS still sucks!
 
In an effort to write a client to real world web services (for Google, Amazon, Ebay), he mostly failed. Errors seem to be largely related to WSDL to Java conversion. Jason Green, a JBoss developer, managed to get quickly a web service working for Ebay, but analysis by RMH suggest that hundreds of classes were generated for this simple one method web service.
 
Recently I had to try to do CORBA client classes by hand in Java since the rmic tool was not working that well to generate classes that could be run on a client JVM of different version than the server JVM. It proved to be a no-go in the end, because of the complexity involved not only in coding, but more on maintaining those modified generated classes. This would have required coding a tool dedicated for that purpose. We chose to pass simpler objects, differently, which looks just like a hack to avoid having CORBA issues. I am amazed that after that many years of CORBA, there are still simple cases where it does not work properly automatically.
 
Seeing that there is the same kind of problem with Web Services (IDL to Java translation) makes me wonder about Web Services "improvement" over CORBA. And WSDL is definitely less readable than CORBA IDL.
 

Previous

Next