Archive for the ‘Java’ Category

XINS (XML Interface for Network Services)

Tuesday, November 15th, 2005

Over the past 5 years or so, the hype around web services has grown continuously. At the same time, the complexity of the relevant specifications has steadily increased. Just think of all the buzzwords like SOAP, WSDL, XML Schema, etc. Now it seems like many developers are taking a step back and thinking of simpler solutions to lower the barrier of entry into web services, which seems like a good thing.

One interesting Java based framework that caught my eyes is XINS (XML Interface for Network Services). Its purpose is to expose APIs using various protocols, such as SOAP, XML-RPC, or REST, while avoiding unnecessarily complex descriptor formats such as WSDL. I have not had a chance to look at it in great detail, but apparently you implement the Java classes that make up your API, provide some relatively simple XML configuration files, and XINS automatically makes your API available using all the protocols it supports (as well as custom ones!). It also generates appropriate Javadocs as well as test pages that allow you to easily invoke your remote APIs with arbitrary parameters, which seems very useful for debugging purposes. You can see this illustrated in the primer.

It looks like you can even plug in your own protocol implementations (which XINS refers to as “custom calling convention”).

I’ll make sure to give this a shot the next time I need to remote-enable an API.

Java: pass-by-value vs. pass-by-reference

Tuesday, November 1st, 2005

One of the Java programming questions I like to ask in interviews is: “Is Java pass-by-value or pass-by-reference?”

A surprising amount of Java developers get this wrong, generally because the variables you mostly deal with in Java (other than primitives) are actually references to objects, rather than containing the objects themselves. Most developers blurt out something like: “Objects are passed by reference, and primitives are passed by value.”

This is of course completely incorrect. Java is very strictly pass-by-value, which you should easily be able to confirm if you’ve ever (unsuccessfully) tried to write a swap() method that swaps two variables that reference immutable objects, such as Strings. It just so happens that the values that are being passed are generally object references. Instead of the statement above, one might say: “Object references are passed by value.”

Scott Stanchfield has written a great explanation of why Java is pass-by-value. He also has some strong thoughts on the terminology “references” vs. “pointers”. He argues that it was a bad idea of SUN to use the word “references” in order to differentiate them from the pointers as you might find them in C or C++. While the syntax for dealing with Java’s references is much simpler than C’s pointers, references otherwise behave exactly like pointers. Maybe calling Java’s object variables pointers instead of references would eliminate some of the confusion with regards to pass-by-value vs. pass-by-reference…

Java Web Parts

Sunday, September 25th, 2005

I just came across Java Web Parts, a collection of open source, lightweight web components such as servlet filters, custom taglibs, utility classes etc. I still need to take a closer look at it, but it looks like there’s some useful functionality.

(via TheServerSide.com)

Ruby for Java Programmers

Monday, September 5th, 2005

If you are a Java programmer and you’re interested in Ruby, you should read this presentation about 10 Things Every Java Programmer Should Know About Ruby.

This blog entry also has some nice Ruby information for Java developers.

About the most dangerous thing about Ruby is how more elegant and less verbose it is. And this is not only reflected in the core language, but also in the various Ruby frameworks and extensions (such as Ruby on Rails) and the developer community that has adopted these philosophies. Even though I consider myself pretty much a Java expert but only a beginner at Ruby, I already feel more productive solving many problems in Ruby than in Java.

You may find yourself swearing at the verboseness and clumsiness of Java once you’ve done some Ruby programming. Don’t get me wrong – Java is a great language and I enjoy programming in Java, although I guess this is more because I am very familiar with Java and its various libraries, including excellent open source software and IDE support. But it is definitely well suited (and proven) for enterprise software, whereas Ruby still needs to prove itself in this area.

Eclipse WTP 0.7

Monday, August 1st, 2005

The final version 0.7 of the Eclipse WebTools Platform (WTP) was released a few days ago. I’ve been using the recent milestone releases for a few months now, and they’ve already been very stable and functional. If you’re using Eclipse 3.1 or planning on upgrading to 3.1, I highly recommend that you install WTP as well.

If you’re installing 3.1 from scratch, you may want to grab one of the All-in-one packages that include Eclipse 3.1, WTP, and all prerequisites.

Now that the WTP release is final, it would be cool if the Ruby on Rails guys would build an RST release on top of that, as WTP was conceived as a generic platform with JST being only one implementation. With RubyEclipse there’s already a basic Ruby plugin for Eclipse, but it’s rather limited and development seems to have stalled. Taking this to the next level and adding Rails support at that opportunity would be awesome.

Java web service resources

Sunday, May 15th, 2005

I came across this nice collection of web service frameworks, tools, and resources for Java.

Eclipse WTP Milestone M4

Sunday, May 1st, 2005

The Eclipse Web Tools Platform Project has released WTP Milestone M4 yesterday. It was built against the Eclipse SDK 3.1M6 release, which was released about a month ago.

A few months ago, I tested WTP M3 in conjunction with Eclipse SDK 3.1M5, but it wasn’t quite there yet… Two weeks or so ago I installed the latest nightly build of WTP M4 on Eclipse 3.1M6 on my home machine, and this already looked very promising, although I haven’t had much of a chance to really exercise it, and I didn’t quite dare to install it on my PC at work. Now that there are at least official milestone releases for the latest WTP and Eclipse builds, I think I’ll give this a try.

To be honest, I don’t really care about the app server integration features of WTP, as I prefer to handle deployment and related issues using Ant, outside my IDE. But at least being able to edit JSPs with full support for syntax highlighting, code completion, etc. is a feature that I consider absolutely essential, and this seemed to work very well when I tried it a few weeks ago. Maybe not quite like IntelliJ IDEA, but it’s definitely a huge step in this direction.

I’ll let you know how it goes.

Spring Framework

Monday, January 31st, 2005

I’ve been reading up a little on the Spring Framework, which seems very impressive. It can be used in several tiers of a typical web application, and depending on where it is used it either cooperates or competes with other established frameworks. For example, Spring comes with its own MVC imlementation that competes with Apache Struts and addresses several of Struts’ shortcomings. On the other hand, Spring’s container framework can be used to build a business tier in conjunction with another front-end technology, such as Struts (for example as an alternative to more heavyweight J2EE solutions such as EJB).

For a new application, it seems like it would definitely be worth checking out Spring as an alternative to Struts and other frameworks, as it appears to offer a nice balance between full-featuredness and ease of use.

Axis / Web Services

Thursday, January 13th, 2005

I finally got an opportunity to work with web services. I had of course read about these in the past and in fact implemented web service like applications prior to the emergence of SOAP, but I had never really had a chance to actually work with web services on a project. On my current project, I am using Apache Axis to expose some of our functionality to third parties, a prime example of what web serices are good for. Axis makes it very easy to expose existing Java classes through a web service, as well as (although we are not currently using this functionality) access an arbitrary web service through a set of automatically generated proxy classes, based on the service’s WSDL. Still, I had to at first catch up on WSDL and SOAP in order to define a clean web service that will (hopefully) work with most SOAP / web service client implementations.

One of the main things I was not aware of is the fact that there are several styles of WSDL. Mainly, there’s the traditional RPC-encoded style, the newer document-literal style, and the wrapped variant of the latter. I am not going to explain the differences here, but this article helped me understand the pros and cons of the various WSDL styles. In the end, I decided to go with the document-literal wrapped style, which should work well for our purposes and seems to be the direction in which WSDL and SOAP are evolving. It allows us to fully define the input and output parameters of our web service using XML Schema notation embedded within the WSDL file, while allowing for an RPC-style invokation mechanism.

So far, I have been able to easily access our web service using the client stub that Axis was able to generate from our WSDL, as well as using very simple, low-level SOAP code using the SAAJ (Soap with Attachments API for Java), for which Axis also provides an implementation. Based on what I have read, it should be straightforward to access the same service using .NET or other web service clients.

I originally used Axis to generate the WSDL file based on a Java interface that I had written for this purpose, but I ended up customizing the WSDL to come up with a nicer XML Schema for input and output types. Based on various sources on the web, the recommended way to implement a web service using Axis seems to be to use some kind of tool to generate the WSDL file, and then use Axis to auto-generate the necessary glue (the actual web service, marshalling / unmarshalling code, etc.).

Another invaluable tool that Axis provides is a simple TCP monitor. This essentially acts as a proxy that sits between the web service client and the actual service and that provides a nice UI to inspect SOAP requests and responses. Very nice for debugging a service.

Definitely fun to work with.

Gentoo and Java

Thursday, December 30th, 2004

Just a few comments on Gentoo and Java. Of course, Gentoo includes many Java packages. For the most part, installing a Java application works the same way as installing a native application, using the “emerge” tool. The source code for the application is downloaded, compiled using the appropriate settings, and installed, along with any dependent packages. For example, installing the Eclipse IDE and the Tomcat application server, both of which depend on many other Java packages, was a snap (well, maybe not exactly a snap due to the lengthy compilation cycle, but easy nevertheless).

At first, I was slightly surprised that Gentoo decided to compile all Java programs from scratch. After all, all significant Java optimizations occur at runtime, rather than compile time. But it really fits better into the Gentoo philosophy. The following page on the Gentoo Wiki explains some of the reaons for building Java code from source.

The Wiki also contains a page on Java on Gentoo, as well as a nice Gentoo Java roadmap.

As I mainly work with Java, I’m glad to see that it is an important consideration for Gentoo.

JSourcery

Thursday, December 30th, 2004

I had previously mentioned JDocs on my blog. JSourcery provides a similar service. The site currently comprises the Javadocs for several common APIs (such as the Apache Commons APIs), as well as the actual J2SE Javadocs (although I suspect it is only a matter of time before SUN will force JSourcery to take these down, just like JDocs did). The unique thing about JSourcery is that it also provides access to the hyperlinked, highlighted source code. On the other hand, it does not have JDoc’s comments feature, and the list of APIs is significantly smaller.

In my opinion, these two services should merge. JDocs has probably gained a fair amount of traction, and the added source code feature would be a nice addition.

XWiki

Monday, December 27th, 2004

I recently came across XWiki, a relatively new, Java-based Wiki. For anybody looking to deploy a new Wiki, this looks like a great option. It has an extensive feature list and seems to combine the best features of other Wiki engines as well as add a few unique Features of its own, for example scripting using Groovy or Velocity, PDF export, and others. It has a plugin API and supports RSS. The website layout is very clean. Definitely worth checking out.

display tag library

Wednesday, December 22nd, 2004

I was looking for an API or (preferably) custom tag library to handle pagination and sorting of lists in JSP, when I came across the display tag library, and I have to admit that I’m very impressed.

This tag library is surprisingly easy and intuitive to use, while at the same time being extremely powerful, flexible, and configurable. It supports rendering tables based on a list of elements that can be supplied as a Collection, Enumeration, array, any object that has an iterator() method, etc. It supports both sorting and pagination. The look and feel can be configured using CSS, but in some cases the actual HTML code that is generated (for example for pagination controls) is configurable as well. Some options can be configured on a per-tag basis as well as in a properties file, which is useful to define a consistent look and feel for a site once.

But most of all, I was amazed by the quality of the documentation. The display tag library website is well organized and the documentation may very well be the best that I’ve seen for a project of this type. It certainly blows away many of the common open source projects, including Apache. It even comes with a very nice and complete collection of live examples.

Well, I know what I’ll use on my project. Nice work!

Portlet Community

Monday, December 20th, 2004

SUN has recently created a new Portlet Community website. It looks like it contains some interesting articles and links.

More info on JSP support for Eclipse

Sunday, November 7th, 2004

This is a follow-up to my previous posting on several Eclipse shortcomings, mostly regarding JSP support. As I was confused by the relationship between the official M1 release of the Eclipse Web Tools Platform Project and the various initial contributions, I did a little more research on this.

It turns out that quite a few people on the Eclipse newsgroups had the same question… The initial contributions (IBM and Lomboz) are now obsolete and will be replaced by the WTP. However, the M1 release only contains very basic functionality and most importantly does not include JSP editing support. In fact, according to the WTP Milestone Plan, support for editing and debugging is only a medium priority for the M2 release (scheduled for December 22) and a high priority for the M3 release (February 25).

The initial focus appears to be on server support, which I think is a big mistake. All of these things are already possible by using Ant, which integrates nicely with Eclipse. Editing JSPs on the other hand requires the use of a third party editor until this functionality is made available in Eclipse. 4 years ago, this may have been acceptable, but in the last few years the ability to edit all components of a project within the same IDE has become pretty standard, and certainly results in much improved productivity.

The best course of action in the interm will probably be to uninstall the WTP M1 release and install either the IBM or the Lomboz contribution. If neither works acceptably, I guess I’ll have to go back to editing my JSPs outside of Eclipse, for example using JEdit. Or persuade my boss to buy me an IntelliJ IDEA license… which would be sad in some ways, as I really like many aspects of Eclipse, and more importantly the idea of relying on open source tools.

To be continued…

Eclipse Shortcomings

Sunday, November 7th, 2004

In the last 4 months or so, I have made several posts on Eclipse, which I had started to use at my previous job. Overall, my experience with Eclipse up to now had been fairly positive, with the exception of some minor quirks. Unfortunately, this has changed significantly in the last two weeks, at my new job.

At my previous job, our applications were built on top of J2EE, but we did not use JSP. Instead, our Struts actions generated XML output which was then rendered into HTML using XSLT templates. Therefore, I never even realized that Eclipse does not support JSP out of the box. It does not even provide syntax highlighting! (more…)

Introducing The Road to Hibernate

Saturday, October 23rd, 2004

Here is a nice tutorial for Hibernate, a Java-based ORM (object-relational mapping) tool. In the last couple of years, I’ve been fairly removed from the database layer, as the applications I have worked on all had some kind of proprietary database abstraction layer, and most of my work was on the application layer above. It’s likely that I will get closer to the database layer again, and while I am still confident enough in my SQL and JDBC skills, I feel that an ORM tool such as Hibernate can save a lot of time in many cases. In addition, there are portability-related advantages, as ORM should make it a lot easier to migrate from one database to another.

I have had similar positive experiences with XML object mapping, which eliminates a lot of the tedious manual XML parsing using SAX, DOM, or whichever API you are using.

Thanks to TheServerSide.com for the original post, which also contains a lively discussion about Hibernate and the pros and cons of ORM in general.

Jarhoo

Saturday, October 23rd, 2004

Why hasn’t anybody thought of this before? If you’re a Java developer, I’m sure you’ve often run into class not found exceptions and had a hard time chasing down the missing JAR file. Jarhoo provides a simple search page that can identify the JAR file or package that corresponds to a particular class. Its growing database currently comprises 246344 classes, 2305 JAR files, and 25 applications.

(via TheServerSide.com)

It’s simple tools like Jarhoo and JDocs that can make a Java developer’s life much easier.

Eclipse vs. other IDEs

Saturday, September 11th, 2004

IBM has published a series of articles that compare Eclipse to various other IDEs. The three articles are titled “Migrating to Eclipse…”, which makes it pretty clear that there is an obvious bias towards Eclipse. Nevertheless, if you are familiar with one of the other IDEs, this might be a worthwhile read.

Eclipse vs. IntelliJ IDEA Eclipse vs. JBuilder Foundation Eclipse vs. Netbeans

Personally, I’m still torn between IntelliJ IDEA and Eclipse. I have evaluated Eclipse for the past 6 weeks or so, and overall I’m pretty impressed with it. It does however have a few quirks, particularly when it comes to CVS or Ant integration, and generally is not quite as polished as IDEA (except for the very nice UI).

If I had a license for IntelliJ IDEA 4.0, I would probably go with this. My somewhat dated IDEA 3.0 license makes this a tougher choice. Even though this is still a great IDE, Eclipse is a lot newer and has a few advanced features. Most importantly, it has a great plugin architecture, with many useful plugins available for free from third party developers. This makes it very powerful. I believe that the upcoming patch release is going to address many of the bugs in the final 3.0 release, which will make Eclipse an even better choice.

JRuby

Saturday, September 11th, 2004

IBM has published another article in their alt.lang.jre series, this time on JRuby. JRuby is a pure Java implementation of the Ruby language. Ruby is often described as an object-oriented scripting language, and it combines the pure OO features of Smalltalk with powerful scripting features along the lines of Perl or Python.

I have used various scripting languages (mostly Perl and Ruby) here and there, but never long enough to really become proficient in any of them. I have been planning on learning Ruby for a while, and with the availability of JRuby, it now becomes a powerful extension mechanism for Java, and learning it would definitely be a worthwhile investment.

Of course, Groovy is a strong contender as well, and in fact it borrows many features from Ruby. It seems to have a slight edge when it comes to Java integration, but can be used as a standalone scripting language as well. Then again, Ruby has the advantage that it is more lightweight as it does not require a JVM (unless of course you want to use JRuby).