Tag Archives: Hibernate

Java web development with Spring

imagesA few months ago, if someone mentioned writing Java applications for the web, I would have had horrible flashbacks to kitschy Java applets from the late ’90s web that would take forever to load.

But for the last two months, I’ve been helping write a web application based entirely in Java. We chose Java because developers on staff were already trained in the area of Java Server Pages. I had only really worked on web apps in PHP before, but I’m starting to favor Java style web development for a few reasons:

  • Early on we chose to go with a popular Java framework called Spring.  Spring maintains a sub-project called Spring MVC, which uses the popular Model-View-Controller pattern to separate architecture components. Spring also relies on other great design paradigms, like Dependency Injection (DI), where class dependencies are “injected” at run-time, making components more modular.  You can even add DI using Java annotations with the @Autowire keyword.  Here’s an example of a Spring controller that takes an item id and uses a dependency-injected MyService to fetch and add the object to the JSP view:
  • Java development is easy in Eclipse, and Spring offers their own Eclipse-based IDE with Maven built-in.  Maven is a build automation tool that greatly simplifies project dependencies and external libraries.  Need to add log4j logging? Just copy and paste the Maven dependency to your pom.xml file.  No copying JARs around!
  • You can debug your web application using Eclipse, which is much easier than debugging PHP code without an IDE.
  • Maintaining Java classes is much easier than maintaining PHP code interwoven in HTML files.
  • Java’s object oriented nature seems more natural than PHP.  Java objects became really important when we started using Hibernate for our Object Relational Mapping (ORM). Basically database tables become classes, and records from those tables are instances of the class.  This behavior is second-nature to Java.

I realize there are probably frameworks for PHP that can do everything above, and I know there are some that claim to be faster/easier/prettier/more aerodynamic/better husband material/etc., but at least for our team, Java seems like it was the right way to go.