I don't write much in the way of business application code any more, but if I did, I would generate Java code like crazy.
Think about it, whenever you write database-driven applications, one common denominator is that every database driven project has the database design completed before you start coding. And then, once you start coding, I'll bet 80% of the code is related to what I call CRUD ("create, read, update, delete") functionality.
And you know what -- you can generate this Java database code, either statically, or more powerfully, dynamically.
What kind of Java database code am I talking about? Simple, all the boilerplate (template) stuff, like these Java components:
- Java Beans
- Data Access Objects (i.e., the select, update, and delete SQL-based code)
That's where I first started. But then, as I learned more about the approach (I started to create an application that can generate Java code, in particular, Java database code), I realized there were many other components that could also be generated from the database with templates, including:
- Java controllers
- Java user interface components, like:
- JSP's, including "list", "edit", and "delete" components
- Tables, like JTables and HTML tables
- All forms of Java configuration files.
This "code generation" technique simply uses templates for all your boilerplate code, including JSP forms, JTable, and Struts, JSF, and Hibernate configuration files.
Whether you use Struts, Spring, JSP's, servlets, JFC/Swing, Hibernate, or anything else, you can create all the CRUD code you need by generating it from the database.
(Note: I originally wrote this article before Ruby on Rails came onto the scene, but they have certainly demonstrated the "code generation" techniques I described in this article.)