Archive for the ‘Java’ Category
Most ignored class of Java!
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?
Java: Not so stupid series
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 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.
JDBC: Java DataBase Chaos
"Write once run everywhere!” this tagline has won many developers. Java has been there for more than a decade and I love the way it ports itself to various platforms with little or no platform specific code. But, when it comes down to JDBC I feel like loosing my patience. We recently wrote a Database specific layer for our application, and that took lots of energy and time of my team. We first analyzed the behavior of different databases, their error codes and then code specific handling.
When, Java seamlessly works with multiple operating systems, what happens to that when it comes to JDBC? For any exception or error it only throws "SQLException" and a long database specific error code and message string.
I find it very common to encounter ColumnNotFound, DuplicateKey, IncompatibleDataType and similar exceptions in my application. Since, my application is designed to handle data at runtime; we are not having control over strict scrutiny of the data to check compatibility. If we do that, it will consume our lot of bandwidth to check input query data against dynamically generated table structures. So we directly push incoming data traffic to database without any strict checking. This leads to 98% hit ratio of proper insertion which saves our lot of processing power as well code efforts. To handle different kinds of errors we have inherited our custom exception hierarchy which wraps SQLException object. This way we always get proper exceptions and the design remains easy to understand.
So far there seems no problem, the real problem starts when we try to make our application compatible with other databases. We have to study each exception or error codes, their messages and other tons of database specific information which seems pretty difficult to manage. Although rare but if any database vendor changes an error code our whole application is for toss and we are forced to run a rigorous test cycle to ensure integrity and working of application!
This becomes very difficult if we are supporting large number of databases. So I was wondering, instead of hundreds of database specific error codes why JDBC doesn't cover exception hierarchy. Then database vendors have liberty to use their error codes while making implementation of JDBC driver generic. Since complete JDBC exception hierarchy will be arranged in similar to IOException, if any user doesn’t want to catch granular exceptions they are free to use generic SQLExceptions.
This will surely help me to chop my code size by 1.5 K of lines
Will Callisto help eclipse to beat NetBeans?
It’s been a while since Callisto has been announced. I don't have statistics about how many downloads happened for Callisto since first release. Most of you might know that, Callisto is collection of 10 most popular eclipse projects which will be released as a distribution. That really helps! In fact, I was waiting for such thing from so long.
Eclipse has hundreds of plugins and each of them has different dependencies. Once I tried to update WTP 1.0.7 in Eclipse 3.0.1 and every time it gave me a version mismatch error. I did not even know how to resolve the plugin version dependency!
That was good example of plugin hell! The same feeling I had in Windows when it used to say XXX.dll has this version and you need XXX.dll with some different version. Now where I am supposed to get the newer version? I finally downloaded wtp-1.0.7-all.zip which has all things in-built from eclipse 3.1 to wtp latest version. Then I faced another problem, after downloading WTP, I had two versions of eclipse on my machine!
Callisto is good effort to address all such problems. Many times, I ask one of my team-member that, "Hey pal, you don't have xml editing feature installed in eclipse? Go get WTP and then it will allow you to edit/format xml in the editor." That guy spends almost half-day to build his workspace environment for editing couple of xml files.
That’s even worse example of increasing productivity by using tools!
Now Callisto will give me one URL which should broadcast throughout my team and within couple of hours everybody's eclipse workbench will be restored to latest version of top 10 projects from eclipse.org.
For those who don't know which are those top-10 projects here is the list:
- Business Intelligence and Reporting Tools (BIRT) Project
- C/C++ IDE
- Data Tools Platform
- EMF
- GEF - Graphical Editor Framework
- Graphical Modeling Framework
- Eclipse Project
- Eclipse Test and Performance Tools Platform Project
- Eclipse Web Tools Platform Project
- VE - Visual Editor
This was needed by eclipse from long time. One URL, one distribution and you are ready to go. Really it should be that simple!
I was wondering will it beat NetBeans. There are few things which NetBeans is doing good. Good examples would be Enterprise pack and Profiler. These packs integrate very tightly with NetBeans. WTP needs that simplicity. Be it anything, BPEL, Glassfish or your favorite relational database, they just get part of IDE! That’s really a great feature of NetBeans. Visual studio always has such kind of integration with all available tools. NetBeans has exactly delivered same power.
I like Xml Schema editor, Schema refactoring, Web Services development and lots of other features which are great! I tried almost each type of project creation in NetBeans since my last post. I must say, its worth to give a try to NetBeans by all those people who love eclipse.
No! No! No! I am not advocating NetBeans, I am just saying just try another project which is powerful, next-generation and perhaps best Java IDE on planet!
And above all, it’s free! So get your latest copy of NetBeans, Enterprise Pack & Profiler and start working on that. Remember it’s just another open-source project so there is nothing I can give to this community than my praising words! Soon I will get involved in editor development of NetBeans. (My current schedule doesn't permit me to blog too
)
Cheers Eclipse & NetBeans team! I really owe you a, "Thanks!”

