Shell / awk script to generate getter / setter stubs for .java file

I realize many IDEs do this, but I felt like writing a few lines of script to spit this out instead. This will grab every line marked "private", whether method or member variable and generates a default getter/setter.

Note: it doesn't insert the code for you or even capture to a file. Maybe next I'll do a Javascript version.

	private Date businessDate;
	private String eventTypeCode;
	private String sourceCode;
// becomes the following
	public Date getBusinessDate(){ 
		return businessDate;
	public void setBusinessDate(Date businessDate){ 
		this.businessDate = businessDate;
	public String getEventTypeCode(){ 
		return eventTypeCode;
	public void setEventTypeCode(String eventTypeCode){ 
		this.eventTypeCode = eventTypeCode;
	public String getSourceCode(){ 
		return sourceCode;
	public void setSourceCode(String sourceCode){ 
		this.sourceCode = sourceCode;

Script source:

#!/bin/env sh
# takes a single filename of a .java file and generates a default getter/setter stub for each private variable
cat $1 | grep private | awk '{
	varName=substr($3, 1, length($3) - 1);
	print "	public " $2 " get" toupper(substr(varName,1,1)) substr(varName, 2) "(){ ";
	print "		return " varName ";";
	print "	}"
	print "	public void set" toupper(substr(varName,1,1)) substr(varName, 2) "(" $2 " " varName "){ ";
	print "		this." varName " = " varName ";";
	print "	}"

Test Scores, Profits, and Page Views are Measurements, Not Primary Goals

I'm a little disturbed by at least a couple of news story themes that I've heard recently:  "Can Eliminating [X program] Improve Test Scores?" and "Students to be Moved to Schools to Improve [the school's] Test Scores." The former concept sounds like a fishing expedition to find a way to take money from "non-essential" programs. The latter concept sounds like a bureaucratic shell game.

What if you substituted "Earnings Per Share" or "Page Views" in the place of "Standardized Test Scores" and "public company X" for "school X"?

Measurements are just one instantaneous interpretation of the health of the mission -- whether business or education. In either case, the numbers can be gamed in a given year... shuffling above-average students to underperforming schools, teaching to the standardized test, deferring decisions on actions negative to the bottom line, expediting actions positive to the bottom line, etc...

How does any of this improve the health of the business or the overall education of the student?

When you make your measurement your ultimate goal, you neglect the actual mission the organization was founded on--providing value to your customers. You never take the risk of scrutinizing the measurement to improve it, because doing so might set you back against your goal. In never changing how you measure your organization, you develop an ever-widening blind spot for any trouble that's brewing.

Have you sacrificed a child's long term development--eliminating music, art, and physical education--just so that their test scores this year will be better than last year?

Have you turned away customers for good just to save money on an offshore customer support call center?

Have you made your site the most awful in the world, just so every visitor generates 50 page views instead of just 1?


While it may not seem all that relevant, this thinking around measurements (called "vanity metrics" in the book) were inspired by The Lean Startup (affiliate link). It seems that a lot of energy in many endeavors is wasted in coming up with ways to see "how good we're doing" instead of understanding if we're truly "doing good" at all. I, personally, think it's an eye-opening read that may challenge your habits and the habits of your organization.


Trying to Dig a Little More In-Depth With Maven

I've been reading Maven: The Definitive Guide (affiliate link) as a Kindle eBook and finally got to the point of trying the first example project. The book had mentioned that maven might be installed on Mac OS X already (due to usage with some versions of XCode). Magically, it's there:

So far, I like the book's approach to Maven.  It evangelizes maven as a tool, but puts the purpose of Maven in context, and explains, "Why Maven?" as well as explaining that "Maven or Ant?" is the wrong question.

If you're looking to download the files to complete the example Maven projects, they've moved from the URLs in the Kindle version of the book because Maven: The Definitive Guide has been split into two books, Maven by Example and Maven: The Complete Reference.

All the project examples can still be downloaded from a single zip file from the Maven by Example book. However, the chapter numbers are not the same in the Maven by Example book, and the folders in the examples are named by a chap-{title} convention.

Within the zip file:

  • Chapter 4's project (Simple Weather Application) (originally at or is now available in the zip file under:
    • ch-custom/simple-weather
  • Chapter 5's project (Simple Web Application)
    • ch-simple-web/simple-webapp