Skip to main content

Posts

Showing posts from 2005

Log4j vs Java 1.4 Logging – Is there a difference?

In the past, whenever I’ve done logging within a project, I’ve used log4j as my preferred logging package. This has been primarily for historical reasons as I started developing with Java before the JDK 1.4 logging package was available. Earlier this week, my RSS aggregator popped up informing me that a new version of log4j (1.2.13) had been released. It then occurred to me, is there a need for log4j anymore? I primarily target Java 1.4 and 5 VM’s so I don’t need to worry about the JDK logging package not being available. The log4j wiki has a page that attempts to answer this question and provides good reasoning for using log4j instead of Java logging, however I get the impression that these arguments are somewhat out of date. What is your preference for logging API? Are there any up-to-date comparisons? At the moment, I’m sticking with log4j, but I couldn’t honestly say whether this is the best approach or not.

Using Spring for J2EE apps

There’s an interesting thread going on over at The Server Side based upon a comment made by Ugo Cei – "I seriously wonder why anyone would want to develop anything substantial in Java nowadays without using Spring." Having done J2EE applications using both "traditional" approaches (i.e. EJB 2.x) and more lightweight approaches (e.g. Spring), I’d choose the more lightweight approach every time. Probably the majority of J2EE applications don’t need the full J2EE stack and Spring provides all the tools necessary to get the job done. As I mentioned in a previous post, when I’ve done projects without using Spring, I’ve missed not having dependency injection (why should I really care about getting a database connection?). EJB 3 looks interesting however, yet there is a large momentum with Spring at the moment, so I don’t see either technology toppling the other. I think both technologies will co-exists side by side.

SQL Server – The Best Database in the World

OK, that’s maybe overstating it a bit, but I do think that the tools that come with SQL Server are very developer friendly. Take, for instance, the SQL Profiler. I find that this is particularly useful when writing any code that accesses databases, or for diagnosing database problems. If you’re using Hibernate (and probably other libraries as well), you can get the sql dumped out to the console that is being executing. This is very useful most of the time, but it doesn’t contain the physical SQL that is going to be executed. It generally replaces the values from prepared statements with '?'s. For debugging SQL related work its often invaluable to see the exact SQL that is being performed and on what connection – this can allow you to easily identify any potential database locking problems. Running a SQL profile trace also allows you to see how long each query is taking and allows you to identify any potential bottlenecks in your application. I know you can do similar th...

Upgrading Fedora Core

I’ve just upgraded one of my development machines from running Fedora Core 1 to Fedora Core 2 using yum. This was a pretty painless procedure, I followed the instructions given at http://www.brandonhutchinson.com/Upgrading_Red_Hat_Linux_with_yum.html The system feels a lot faster now (I don’t know if it’s just me or if FC2 is actually faster). I’m going to leave it a couple of days and see if it remains stable. If it does, I’ll consider upgrading to FC3.

Less “Crap Code”

I recently wrote about how developers don’t always clean up correctly when using databases after I read this blog. In my blog entry I suggested that developers could use a library (such as Spring) to help them close up database resources. Well, today I stumbled across the Java Specialists Newsletter Issue 116 which details another library. The Jakarta Commons-DbUtils library does this for you. From the commons web site "DbUtils is a small set of classes designed to make working with JDBC easier. JDBC resource cleanup code is mundane, error prone work so these classes abstract out all of the cleanup tasks from your code leaving you with what you really wanted to do with JDBC in the first place: query and update data" If you are using JDBC for your persistence access, I recommend that you use one of these available libraries (DbUtils or Spring etc.). After all, writing JDBC code is fairly tedious and error prone.

I Miss Dependancy Injection

I’ve just started working on a fairly small web application project that uses Struts as its web framework. I like Struts, its fairly simple to use and covers just about everything I need for my application. Since I’m now using NetBeans 5 Beta 2 ( eventually !), I though I would have a read of Geertjan’s series of articles on how to use Struts with NetBeans. These are good articles if you are new to Struts or want to see how NetBeans handles Struts development. However, since I’ve used Spring in the past, Geertjan’s method of grabbing database connections seems odd. I’m not detracting in any way from the series of articles (which are great) which are intended to discuss struts development with NetBeans – this is more of a problem I have with Struts. Once you get into the rhythm of using DI, it seems strange going back to explicitly setting things up. For example datasources – injecting datasources directly into DAOs is one of the best things that I like about Spring and somethin...

Struts is Alive !!

There has been a lot of talk recently about the demise of Struts. Its true that there haven’t been any major developments recently on the core product. However looking at the most popular blogs on Javablogs.com today shows that there is still a huge interest in Struts. 5 out of the top 6 read blogs are relating to the merger of Struts and WebWork. Maybe everyone just finds this an interesting story, or maybe they just want to read about products that they used to use, or maybe people are still using Struts and are interested in what the future will bring ;) . Whatever your point of view, this is interesting news.

JBoss and NetBeans 5

If you’ve read my blog before (you do read it don’t you!), you’ve probably noticed that I tend to talk about JBoss and NetBeans quite a bit. I like the JBoss Application Server and use it for all my J2EE deployments, and use NetBeans for Java development whether this is J2EE or Swing development using Matisse. JBoss has just created a new forum "for discussing the development of J2EE applications for JBoss with the NetBeans IDE". The new forum can be found on the JBoss website.

JBoss at Work

Norman Richards has done a small review of the JBoss at Work book just released by O’Reilly. Reading this review, and looking at the Table of Contents , I like the sound of this book and will be buying it – unfortunately, Amazon currently says its out of stock.

More on “Crap Code”

I read this blog recently and thought, "yes, that’s true". I’ve seen a lot of code that has resource leaks because programmers don’t properly close database connections. This is one of the most compelling reasons to use something like Spring’s database classes – they remove the boilerplate code for you and make using JDBC just that little bit easier. If you don’t want to use Spring, then its not too difficult to write a couple of library methods that will close all database connections correctly.

NetBeans 5.0 Beta 2 released

I see that NetBeans 5.0 Beta 2 has been released . I’ve found the first beta to be very stable apart from a few issues with the new GUI builder. I’ll be downloading the new beta shortly to see how it fares. Apparently over 1880 bugs have been fixed since beta 1. That’s some going. Congratulations to the Netbeans team.

Goodbye Firefox

I’ve finally decided to stop using Firefox and use Opera instead. My main development machine is a Linux box and I’ve never been totally happy with my browsing experience compared to when using Windows (IE isn’t that bad). So why the move to Opera? Well, Firefox never seemed to display the correct fonts, everything always came out in some variant of Times. I was never able to display unicode characters and never managed to get applets working. With Opera, all of these just worked straight away when I installed it. I downloaded the RPM, ran the rpm -i command and Opera was installed. Opera doesn’t have those annoying banner adverts on it anymore – I tried it before when it had them and found it too annoying. Now without them, its a pleasure.

Busy Busy JBoss

JBoss have been very busy recently. They’ve released SEAM - an application framework for Java EE 5, they’ve got an early release of EJB 3, they’ve released the JBoss Microcontainer and have just agreed that they are going to work closer with Microsoft , plus all the other things that they are working on. What’s next I wonder? Well, time will tell, but from the look of it, we won’t have to wait long.

JBoss and Microsoft Partners

JBoss has today announced that they are to work closely with Microsoft to enhance interoperability between JBoss middleware and Windows Server products. Four key areas have been identified that are suggested will benefit both JBoss and Microsoft customers: Security Interoperability Web Services Interoperability JEMS Management via MOM Optimised use of SQL Server for Hibernate and EJB 3.0 The full press release can be read here . I think that this is good strategy by both Microsoft and JBoss as interoperability is surely one of the biggest areas that traditionally causes headaches. Many enterprises have both Microsoft and Java systems deployed and I can see how this partnership will benefit both Microsoft and JBoss. For Microsoft, they push SQL Server and .Net applications communicating with JBoss via web services. For JBoss, they are partnering with one of the biggest players in the market which will surely add a lot of credance to the JBoss range of products, plus they ...

Java HTML Parsers

Does anyone know of any good open source HTML parsers for Java? I want to be able to parse a HTML document (which may or may not be valid) and extract information from it. I’ve found a few on Google, but I’ve no idea how good they are.

Running Matisse Generated GUIs Outside of NetBeans

If you’ve been experimenting with Matisse, the new GUI builder that comes with NetBeans 5.0, you’ve probably wanted to run your app outside of the IDE at some time. The LayoutManager used in Matisse is held in a jar file called swing-layout-0.7.jar which is in the ide6/modules/ext directory of NetBeans 5.0 You just need to add this jar file to your classpath to run Matisse generated GUI apps outside of the IDE.

NetBeans 5.0 GUI Builder

I blogged recently about the need for good GUI builders in Java. Yesterday, I downloaded the latest daily release of NetBeans 5.0 and tried out Matisse. I’ve seen the demos of it being used, but never had the chance to use it myself. I was very impressed with how it all worked and how easy it was to construct dialogs. There were a few stability issues with it, but thats to be expected from a daily build. Not long now until there is a beta available!

How (not) to choose a web framework…

How do you know which web framework to use when starting a new project? It can be tricky and there are several factors which can influence your decision, such as support, learning curve, project standards etc. To help people choose their web framework, I’ve done a totally un-scientific survey and found out how many times a framework is mentioned on www.javablogs.com The results are: Spring 3439 Struts 3032 JSF 1278 WebWork 1209 Tapestry 1081 I don’t think you can draw any conclusions from this apart from the fact that javablogs.com has a search facility!!

Java EE May Loose?

How many times have we heard that LAMP or .NET is better than Java EE? There’s an interesting discussion about this going on over at The Server Side. I for one will be sticking with Java EE. I think frameworks like Spring, Hibernate, Struts, EJB3 are all things I wouldn’t like to give up. Java has made huge leaps forward in the last year or so, lets hope the momentum keeps going.

Struts and JSF Support in NetBeans

It seems that we are going to get much tighter integration with Struts and JSF in NetBeans 4.2. Geertjan describes whats going to be available in NetBeans 4.2. It looks as though Struts and JSF will be tightly integrated – the whole process of creating a new project using these technologiues can be described in 4 pictures! Its not difficult to create a Struts project in NetBeans 4.1, but little things like this make the IDE so much nicer.

First CVS then Subversion?

Netbeans has announced a preview of their new CVS support. I don’t use CVS, I much prefer Subversion so this new release doesn’t interest me too much. However, according to the release notes: …it is critical for us to know what you think before we release the final version and move to integrating support for more versioning systems such as Subversion and MS SourceSafe! So, please can everyone using Netbeans and CVS give this a try and give feedback. Then it hopefully won’t be too long before we get a similar level of Subversion integration in Netbeans.

JBoss 4.0.3 RC2 Released

JBoss has announced that version 4.0.3 RC2 of the JBoss App Server has been released. Highlights include: Support for platform mbeans under Java5 Support for Tomcat GlobalNamingResources New startup parameters to control cluster partition and udp group Improved farm service Xerces J 2.7.0 JBoss Bean deployer (early access JBoss5 microkernel)

First Steps in EJB3

I’ve just taken my first steps in EJB3 and started writing some small sample applications so that I can get up to speed on it. I’ve been doing J2EE for some time now so I thought I’d have a look at the new EJB 3 stuff and see how it differs. I’m a fan of JBoss, which provides a version of EJB3 on JBoss 4.0.3RC1. The EJB3 support can also be ported to run on JBoss 4.0.2. Installing JBoss with EJB3 support is a doddle. I used the webstart installer on the JBoss website and installation proceeded smoothly without any problems. During the installation, you are asked which configuration of JBoss you want (all, default, ejb3 etc.). Both the all and ejb3 configurations provide EJB3 support. So far, I’ve primarily been looking at Session beans. I’m impressed at the lack of verbose XML that needs to be written to deploy the beans (i.e. there was none!). The lack of boilerplate code required to develop these beens is very impressive, in fact my ant script was by far the most complex thing ...

Swing good, SWT bad?

Swing seems to be en vogue at the moment, whereas not long ago it was SWT that was fashionable. I’ve never developed with SWT before, but I’m finding that there’s less reason to do so now that before. JDK1.5 enhanced the Windows look and feel to make Java apps look more like Windows native apps. If you want to take it a step further, you can use something like the Plastic L&F which will give you excellent results. Taking it one step further again, Romain Guy explains how to get more from the Plastic L&F. I’ve no doubt you can get similar results with SWT, but is it worth it? I’d be interested in other peoples opinions. Do you develop with Swing or SWT?

JDBC Drivers

I’ve just come across this tip over on devx.com listing JDBC drivers and their connection strings for many different database vendors. It may come in handy someday so I’ve bookmarked it here. I was surprised though that it doesn’t contain details of the jTDS driver for SQL Server.

Java GUI Builders

There’s a lot of debate at the moment on the merits of GUI builders, in particular Matisse – the new GUI builder for NetBeans. I’ve heard people suggest that GUI builders shouldn’t be used and all user interfaces should be manually coded. I don’t really subscribe to this line of thought. I can’t imagine that any serious GUI is completely manually coded nowadays – thats the sort of think I used to do in the mid-90s developing Windows 3.1 software. Surely things have moved on a lot since then? When you’re considering GUI builders, I believe you have to think about how the “other side” (i.e. Microsoft) do things. Its impossible to deny that Visual Studio allows users to create fantastic looking GUIs in a fraction of the time that it takes to develop a similar Swing GUI. I’m not saying that you can’t develop professional looking GUIs in Swing (just take a look at IntelliJ IDEA for example), but that they take a lot longer to develop in Swing. I for one, am looking forward to Matisse. I...

NetBeans Server Plugins

NetBeans 4.1 has built in support for Sun App Server and Tomcat 5.5. There is also a Server Plugins project for NB that adds support for JBoss 4, WebLogic 9 and WebSphere 6. The server plugins project is currently classified as experimental. Currently the only way to try these plugins is to build NB and the required plugins – you can only download the source for them at the moment. Downloading and building is a easy process, albeit rather lengthy. Full details are given on the server plugins home page, but basically to download from CVS and build on Windows you need to do the following. rem Create a directory to store and build NB in. mkdir netbeans cd netbeans rem Setup CVS set CVSROOT=:pserver:anoncvs@cvs.netbeans.org:/cvs rem login to CVS - no password required. cvs login rem download NB relase 4.1 source cvs -z 6 co -r release41 -P stable rem download server plugins source cvs -z 6 co -P serverplugins rem build NB cd nbbuild ant rem build JBoss plug...

Spring Connection Pooling with DBCP

Recently I wanted to add a connection pool to my Spring Web Application. I decided to use Commons DBCP to provide the connection pool as I’m using the Spring JDBC wrapper classes. Googling around didn’t find any examples of how to set up DBCP, so I’ve written my findings here. Adding a connection pool to a Spring app is simply a matter of specifying the relevant entries in the Spring servlet configuration file. The XML snippet below shows an example of how a database connection pool can easily be configured. net.sourceforge.jtds.jdbc.Driver jdbc:jtds:sqlserver://localhost:1433/db;prepareSQL=0; SendStringParametersAsUnicode=False; username password 2 5 2

Java Web Start

I’ve just noticed a poll that is currently running on the java.net home page asking if anyone has ever ran a Java Web Start Application. I must say that the results were quite encouraging. At the time of writing, 80% of the respondents have answered “yes” to the question. (You can see the current poll results here ). Being able to run applications without having to install any software (apart from the loader) has got to be one of the most beneficial aspects available to modern computing. I still remeber the old days when IT departments had to manually install software on every workstation. One of my favourite examples of using Web Start is on Santhosh Kumar’s WebLog (which, incidently, I recommend to anyone doing Swing development) where he provides sample Java code and then a Web Start example of the code. If you are one of the 20% that hasn’t run a Web Start application yet, have a look at Sun’s docs .

Adding Subversion Support to NetBeans 4.1

I’ve just installed the NetBeans module that allows me to access my Subversion repositories from within NB 4.1. Installing is a painless process. Browse to the NetBeans Generic VCS Module page and download the relevant module (currently Subversion 1.1.5 and 1.1.6 available). Select “Update Center” from the “Tools” menu in NB. Choose to install a manually downloaded module rather than contact the update center. Select the file you have just downloaded and complete the Wizard. Once you have done this, NetBeans will install the module and you can start using Subversion. (NetBeans 4.0 seems to need a restart at this stage, but 4.1 doesn’t). Once you’ve got support added, click on “Versioning -> Versioning Manager” and add a Subversion working directory to the list noting to specify the correct parameters for the Subversion repository. You should now have support for the SVN commands from within the Projects tab in NB.

Moving to NetBeans 4.1

I’m thinking of starting to use Netbeans 4.1 full time for my Java devlopment. In no particular order, these are the reasons why. It supports JDK 1.5 out of the box. Now that I use JDK 1.5 features, I wouldn’t like to give them up. Typesafe collections, enumerations, annotations. Without these Java would be a much weaker language. Its fast. Even on old machines I’ve tried it on, it works well. I’ve used it regularly on a Linux desktop with 256M of memory and its still responsive. Developing Web Applications is very productive. With the embedded Tomcat, its very quick to start Tomcat up and debug web aps by right clicking on a jsp and selecting “Debug”. Its got a good GUI designer You can design your GUIs within NB easily and then see what they look like. Maybe this isn’t as powerful as the GUI builder in IntelliJ IDEA 4, but its close. However, the upcoming GUI builder, Matisse , looks very promising.

Book Review: Better, Faster, Lighter Java

Better, Faster, Lighter Java I’ve just finished reading this book by Bruce Tate and Justin Gehtland. Its one of the best books I’ve read for a long time and I thoroughly recommend it. The book begins by explaining how Java development has gotten too complex and how often too many “bloated” frameworks are used for solving enterprise Java problems. The authors describe how simplicity is often the best approach to writing applications (quote: “simplicity is the hallmark of a well written application”). There then follow 5 idioms for writing better code with a chapter describing each of these in detail. Next there is a chapter each on the Spring Framework and on Hibernate showing how these 5 idioms have successfully been applied to these popular frameworks and giving an overview of how they can be used. Finally, there are a couple of chapters bringing all this new knowledge together and showing some example code. I thoroughly recommend this book to anyone doing Enterprise J2EE ...

Hibernate 3.0 final released

The latest production version of Hibernate (3.0) was released yesterday. According to the Hibernate web site, this contains minor fixes and some new functionality including two new database dialects. I’ve been using the 3.0RC1 since its release and found it to be stable. The change log to version 3.0 lists the bugs and new features added so I’d recommend people using Hibernate have a look at this and then upgrade.

Command Line Arguments

I’ve recently needed to do some command line parsing. Instead of reinventing the wheel, I looked at the Apache Commons CLI library. This library seemed to do exactly what I wanted and was fairly easy to use. One question though? Why does the standard Java runtime not have classes to deal with CLI arguments?

J2SE New Features – Generics

J2SE 5.0 gives developers a whole load of new features – too many to list here, but a complete list is given at http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html Generics is one of the best new features that has been added to J2SE 5.0 and they are incredibly easy to use! So what is Generics? Well, to put it simply, Generics gives you type safety on collections, so you can create collections that will only hold a specific type. Furthermore, when you get an object out of a collection using Generics, you don’t need to cast it to the relevent type – this is done automatically for you. This is best shown with a small example. // Declare an array list called items that can only hold strings. Collection items = new ArrayList (); // Add a couple of strings to the collection. items.add("String 1"); items.add("String 2"); // Declare a 'String' iterator to loop through the collection. Iterator iter = items.iterator(); while (iter.hasNext())...