Over a million developers have joined DZone.

The Power of Copy and Paste

DZone's Guide to

The Power of Copy and Paste

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

A reasonably large sized “Enterprise” Java web application ends up being multi-tiered , multi-layered, multi-moduled in that order,  with at least a few million dependencies. The task of putting together such an application from scratch is truly daunting.

So how do you go about creating an application from scratch? I have a few favorite techniques that I have faithfully followed over the years:

  • Copy an existing working application;start trimming it until I get to the point where I have an “archetype” that I can start back from.
  • Start from one of the archetypes provided by maven. Most of the standard maven archetypes (obtained using mvn archetype:generate) are very lightweight, but could be a reasonable starting point.
  • Use Appfuse as a starter application. Appfuse though is starting to get a little bit dated now, with no updates for the last year

All of these approaches follow the common theme of “Copy and Paste” to create an application.

Now, copy and paste helps you kick-start an application, once you have started an application how do you keep adding functionality, after all most of the code structure would look similar – In Java you would add a new entity, a corresponding DAO to manage the persistence of the entity, a service tier, a controller, a view and so on.

The Rails folks did a wonderful job understanding that providing a simple way to kick-start, add functionality and pull in dependencies, is the quickest way to developer nirvana. Well, people who work with Rails are lucky, we Java guys don’t have that option, until now that is (Yes there is Grails, Lift, but these have not been an option in the enterprise shops that I have worked in).

Roo is turning out to be a wonderful alternative. With a few commands , you have a fairly green looking application up and running with all dependencies nicely pulled in. Adding functionality is equally easy; the roundtrip experience from creating an entity, to viewing the entity in a web page almost has the feel of a Rails based development. Well, Roo is still maturing, so it is not an option where I work yet, however that still leaves the “Copy and Paste" as a viable alternative for now!!. A simple way that I follow to add functionality to an application that I am working on is to simply start the Roo console, create the entities in roo, run the push in refactor and then creatively “copy and paste”.

"Copy and Paste" the most under-rated way of expanding code.

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. 


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}