$ thought | blog

Place to serialize my thoughts…

Archive for December 23rd, 2006

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

Java: Not so stupid series

with 3 comments

I always read the "Not so stupid questions" series on Java Today. It was becoming difficult for me to keep the questions list. Sometime, you need the questions list and you don't find it; don't you hate that? First thing came to mind was my blog! After all we are supposed to use these tools to organize our personal information; isn't it? Blogs were invented for that,so I thought to make a list as a post and let others find the entire list in one place.

I googled for stupid questions list but I couldn't find a single page enlisting all of them. :( But this problem is not there anymore. You would like to bookmark this page for your reference ;)

(Not So) Stupid Questions series:

Q 01: Should I try to declare more of my methods to be static?

Q 02: Some side-effects of String equality don't make sense

Q 03: Some uses of the private keyword don't make sense.

Q 04: I have no idea when to create a new package and what should go in it.

Q 05: When should I implement an interface, over inheriting from a parent class?

Q 06: How can you justify Dimension java.awt.Component.getMinimumSize() when Dimension does not implement Comparable?

Q 07: There are some weird Java operators I don't understand.

Q 08: What's the deal with serialVersionUID?

Q 09: I'm attending my first JavaOne. What should I plan on?

Q 10: Other than bundling my classes, what good does a JAR do me?

Q 11: I have a question about a Java feature. Who do I ask?

Q 12: Can I use the 'Java' name in an open-source project?

Q 13: Why do constructors have to start with a call to super()?

Q 14: Why is if (true); considered valid Java syntax?

Q 15: How can a constructor be private?

At the time of writing this post, only 15 questions were available. If any additional questions are appeared, I will update the post.

Written by Sachin

December 23rd, 2006 at 2:58 pm

Posted in Articles,Java

Tagged with