Saturday, May 16, 2009

First Experiences with Java

I thankfully got the chance to do a little bit of coding over the past few weeks, working on an alerting services framework that is an extension of our CEP system.

Because we have a lot of systems that are in Java, I needed to deliver both a C# and a Java SDK. I used to do a tiny bit of Java back in the late 1990's, but I haven't touched it in over ten years.

So, I had a completely finished C# SDK, and I needed to port it over to Java. The C# SDK lets a system publish alerts over Tibco EMS and over WCF using the webHttpBinding. I knew that I was going to have an issue doing the Java interop to WCF. and, I wanted to do this entire effort without reading a lot of documentation.

I started off by downloading Eclipse. I created an empty Java project and started to port my C# code over. Immediately, I started to miss some of the features of C# and Visual Studio that I was used to.

1) Properties. Where are they in Java? Especially the automatic properties of C# 3.0. I don't want to have to write separate get and set methods for every property.

2) Events. That's a big miss for me. I had to end up using the Observable and Observer classes/interfaces. By the way, I used to the names of interfaces starting with the letter "I". It's not obvious in Java what is an interface and what is a class.

3) The ability to easily create Web Service proxy code. This is a no-brainer in Visual Studio. For the Java project, I ended up having to download and use the NetBeans 6.1 IDE (which is a lot slower than Eclipse). NetBeans was a nicer IDE. It understands Eclipse projects. It has a very easy way to create a Web Services client. I found out through a bit of pain and a lot of blogs postings that it is best for interoperability if your WCF service uses the basicHttpBinding instead of the wsHttpBinding or webHttpBinding.

So now, after all of these years, I can say that I have coded in Java. And, I can say that I have a greater appreciation of C# and Visual Studio.





©2009 Marc Adler - All Rights Reserved.
All opinions here are personal, and have no relation to my employer.

6 comments:

Hans said...

Eh - some of this is just you being unfamiliar with the tool set. Once you get a tool set working for your goals, that part pretty much comes out as a wash with VS. I mean, the tools are free so yeah, you trade off having to do more setup. If one is willing to pay, they can use IDEA by IntelliJ which integrates many tools.

In terms of tools, I remember before ReSharper, all the MS-only developers would drool over the extensive refactoring support that came with every Java IDE. The tools just keep leapfrogging each other.

In the last couple of years, the language features have become a problem for Java, IMO. I mean, no one understands why Java still doesn't have properties. But then C# 3.0 really upped the bar on language features and Java is way, way behind now. Sun has this idea that they are protecting Java developers from creating unmaintainable code by leaving out language features that are "too complicated". That is really ridiculous at this point, I hope Oracle does a better job of stewardship over Java.

But if you *really* want a reason to hate Java, try writing a GUI. :)

Sanjay said...

Really its a matter of familiarity and comfort level with the tool sets and language that you are used to. My experience/feelings with C#/.NET is exact opposite of Marc's, I can get stuff done a lot faster and am a lot more productive with Java/Eclipse (sometimes NetBeans or Intellij) and not to mention rich source of opensource libraries/platforms to choose from and use. Setters/Geters are autogenerated by Eclipse and other IDEs, Delegates/Events (nice to have but not a problem with what Java has) for me bigger issues are things like Generics impl between C#/Java (C# has better approach here), JVM's GC capabilities compared to CLR GC (Java is extremely rich here, checkout Sun JRE, JRockit and IBM). Another area where Java tools shine is in profiling JVM for performance - that area is very rich (very good commercial products and some great free ones). GUI frameworks - well Java based toolkits run on all platforms of interest to enterprise folks (RCP platforms such as Eclipse's or NetBeans' can
make writing a rich gui app simpler).
Once you learn them they are quite ok (can be improved surely but they don't suck unless you come from Windows/WPF world and are used to what is available in that world - most of the complaints have to do with comfort level/learning involved).

Sanjay

marc said...

I have mentioned a few times on this blog that I was jealous of the amazing Java open source community and the ways that interesting frameworks keep coming out. Now that I have gotten over the hump and have done my first Java framework, I hope to explore more of what make Java Java.

One of the things I liked about Eclipse is the way that it tags the files in the Package Explorer that have errors and warnings ... and the way that the error and warning tags are propagated up each node of the source tree. Visual Studio can certainly use this feature.

Hans said...

I love the Java IDEs including Eclipse.

If you have the latest full version of Eclipse, look at Mylyn from Help->Help Contents. It sets up shared, task specific work contexts so when you switch between tasks or need to transfer a task to someone else, there's no searching around for which classes you were working on and where you saved that debug output.

Marco Seiriƶ said...

I have been in the open source/Linux camp for ages. But lately I have found my self tired of all the open source/java tools. It seems that they are all almost done. For some reason I get the feeling that the last 20% or so is missing in more or less all open source tools. Why sit down and polish your tool and actually write some usable documentation when there is a new shiny feature that you could implement instead.

Just count the number of 3D desktop thing vs. really good printing systems for Linux. Building a printing system is boring so nobody does it, but there's always place for another 3D desktop.

Being tired of everything being half way done, I actually enjoy VS2008 and related tools more and more. If MS could just give us a decent execution environment I'm sure more Linux coders would start looking at .net tools too.

Joeyw said...

Have to agree with Marc here. I program in both (Eclipse and VS2008) and find Eclipse to be frustrating and very difficult to use.

On the actual VM side, I'm interested in reading more about GC optimizations on Java. I find minimizing allocations and performance work easier on the .NET side (with the use of stackalloc, better generics support and unsafe code with pointers). I'm not sure how to do the same on the Java side.