First thoughts about Java

Something does not work. In my head, I mean. If you know me, you should be aware I’m pretty skeptical about Java. Let’s say that the first thing I do when I hear someone talking about Java is: Hey, there is Python out there, that is much better.

Still I heard much talking about Java Tiger, that is to say Java 5 (or 1.5, I still haven’t figured out which is the correct version number). There are *generics* (that is to say “templates” if you know C++). And autoboxing. These were the two single things I hated most in Java. Still I won’t talk about it here, there is plenty of places on the Internet when someone says that a strongly typed language that forces you to cast everytime you have to use a resizeable collection simply sucks.

I’ve quite changed my mind on this, but let’s go further. With generics it is not necessary anymore.
And with autoboxing you have not to change integer types back and forth from Integer objects.

So, I bought Core Java Volume I, written by Horstmann and Cornell. In fact I find it a well made book. It’s clear. And complete. Probably it’s not meant for a newbie. But I already new some Java and am quite skilled in C++ and Python, at least. I’m not new to theoretical object oriented programming (and for this I have to thank my university teachers) and have made many practical stuff, in very different environments, ranging from QT and Python or Cocoa to old C version GTK 1.

I thought I’d read it in some time, just to know what was happening out there in the Java world. Well. I was impressed. Java 1.5 is much better than Java 1.3. Its standard library is fabolous (something I knew even if not believed). And programming Java is not bad.

It has faults. And that is something that Core Java authors do not fear to stress. I find it really honest. It’s not a fan book. They like Java, but they are able to show its weaknesses.

This morning I bought Core Java Volume II. There are many things to learn… it’s really interesting. Even if I tend not to program cross platform anymore (thanks to Cocoa) I occasionally need some crossplatform environment.
QT 4 is giving me some troubles, and I think I could give Java a try… well, I won’t say more. ☺

And, oh… one of the first thing I chose to develop is a small plotting applet (which could be extended, if I have time to finish it and to make code readable). And I chose not to use 1.5 features, to let more people use it. Well… in fact a part from a pair of crappy hacks I had to do since it’s not as dynamic as I liked and I could not use generics, it is not that bad. Oh, the code I’m talking about is this:

public void stateChanged(ChangeEvent event){
    JComponent source = (JComponent)event.getSource();
    if(source.getClass() == spinner.getClass()){
        /* wow... heavycode! */
        newValue = ((Double)((JSpinner)source).getValue()).doubleValue();
        newValue *= factor;
        slider.setValue((int)newValue);
    } else if (source.getClass() == slider.getClass()){
        /* wow... heavycode! */
        newValue = ((JSlider)source).getValue();
        newValue /= factor;
        spinner.setValue(new Double(newValue));
    }
    firePropertyChangeEvent(
            new PropertyChangeEvent(this, "syncChange", new Double(0.), 
                    new Double(newValue) ));
}

Probably there is a javish cleaner solution. But in Python it would have been

def stateChanged(event):
    source = event.getSource()
    # source.factor is appended to each source before passing it
    # and can be > 1 or 
Advertisements

3 Responses to First thoughts about Java

  1. hiparrot says:

    wordpress eat up my space chars when I paste an article. How can I leave the spaces as they are? Thank you.

  2. rik0 says:

    I use a blogging software that uses wordpress web services. In fact I never tried to paste an article directly in WordPress.
    If you use a Mac, I can suggest you a couple of applications.

  3. codeoop says:

    Thanks for sharing with us

    Can you share some more <a href="http://codeoop.com/category/code/java/"exmple code ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: