$ thought | blog

Place to serialize my thoughts…

Most ignored class of Java!

with 7 comments

I am working with java for more than 5 years. From college to professional life, Java deserved an important position as a programming language. Recently I came across a conversation in my team. One of junior developer used ArrayList to store bean objects. To avoid duplicate objects in the list, he used a simple loop for comparing state of the beans.

I suggested him to use HashSet instead of ArrayList (but forgot to tell how HashSet works ;) !) He just changed data structure and came back to me with a complaint of HashSet not working!!! (This is true! :) )

Then I suggested him to visit API doc for HashSet and then he realized that he also need to override equals() and hashCode() methods from Object class. But all this didn't stop there, he was not clear about implementing hashCode method despite of extensive API doc. It made me think about our ignorance of fundamentals.

Then I continued my search and conducted a short survey with my friends. There are total 11 methods in Java 1.4.2 version of java.lang.Object class. Most of them were not knowing how to implement hashCode() method. I am sure if they needed it badly, they will do as they are talented developers.

I found that people know complete Java Collection hierarchy, they know details of Vector class and Concurrency utilities. They know socket programming and design patterns but they miss Object class in major portion.

We tend to find other ways to implement the functionality which is provided by equals() & hashCode() by introducing extra loops or else. Now I don't wonder if I found few more highly ignored things from Java!

Do you know any similar ignored classes / interfaces?

Written by Sachin

December 23rd, 2006 at 8:13 pm

Posted in Java,Programming

Tagged with

7 Responses to 'Most ignored class of Java!'

Subscribe to comments with RSS or TrackBack to 'Most ignored class of Java!'.

  1. I have to say that this is really an intersting blog.

    Anyway, Java API doc .. is full of classes, there must be ignored ones all the time.

    Also, I sometimes feel that some classes are added just for the sake of organization, many interfaces, abstract classes and hundreds of classes that is needed solely for creating other classes.

    This class tree can definitely be more compact.

    In my last project, that included XML parsing, I found that many “factories” exist around. Still wondering what exactly the benefit.

    Last example, till now and after a week of trials. In JSF, I couldnt initiate a VariableResolver to have access to request beans because of the huge number of classes ‘USED” to initiate this class.

    Sorry for being long .. but I am a learner. Hope you help.

    Thanks.

    ibhog

    23 Dec 06 at 10:31 pm

  2. Utility methods in Collections and Arrays classes.

    BTW, chapter 3 of Effective Java discusses the equals & hashCode methods is detail. Also, this chapter is available as a free download at http://java.sun.com/docs/books/effective/.

    binil

    24 Dec 06 at 7:07 am

  3. @ibhog

    Well, thanks for appreciation.

    You are correct, there must be lots of classes which were ignored and inserted for organization. But “Object” class is root class and that is part of every class you write.

    It is expected from a average user of Java to know at least all the functions provided by Java ;) isn’t it?

    Regarding factories, you can read lots of documentation on internet. The best place to start would be “Design Patterns” book by GoF. Or just google for “Factory Pattern” :)

    Sachin

    24 Dec 06 at 7:07 am

  4. @ binil
    In Java API also you can find necessary and sufficient information about overriding equals() and hashCode() methods. But we never visit that documentation.

    In my experience I found, that people learn Java or any other language when they need a particular feature provided by language or they are forced to learn. They don’t have sufficient time to go through a book touching all the chapters. They just want to achieve what they looking for a move ahead.

    When they become a seasoned user of Java they learn design Patterns, other advanced things but ignore basics because they never used them. But definitely there are lots of people like you and me who digg all the documentation and books for the sake of our satisfaction :)

    Sachin

    24 Dec 06 at 7:12 am

  5. Check out Joshua Bloch’s Effective Java, it’s full of stuff most of us over look.

    Chris Maki

    24 Dec 06 at 10:07 am

  6. @chris

    Thanks dude. I have a copy with me. Just I need to purchase one more for my junior developer :D

    Sachin

    24 Dec 06 at 10:09 am

  7. i also think this is a kinda cool blog

    dash888

    24 Dec 06 at 8:18 pm

Leave a Reply