Jan 6 2020

POJOs Made Easy with Project Lombok

Every Java application has some sort of bean or Plain Old Java Object (POJO) to hold and manage state. Because of good Object Oriented Programming (OOP) principles we encapsulate field access with getter and setter methods. Most modern IDEs allow you to quickly create getters and getters. You can often find a Generate option under the Code menu from your favorite IDE. But generating getters and setters produces a lot of unnecessary boilerplate code.

With Project Lombok, you can reduce all that boilerplate getter and setter code with a few annotations.

The following bit of code will produce a Java class with the necessary getters and setters to access all the defined fields.

package com.juixe.core.pojo;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@ToString @EqualsAndHashCode
@Getter @Setter
public class Person {
   private Long id;
   private String firstName;
   private String lastName;
}

Given the Person class above, you can start coding the following.

   Person p = new Person();
   p.setFirstName("Boingo");
   p.setLastName("API");
   p.setId(1000l);

The getter and setter methods are added to the bytecode for the Person class by Project Lombok through the annotations. If you remove one of the annotations, like the @Setter annotation, then the setters methods will be deleted.

We just saw how a few annotation can generate getters, setters, equals, hashCode, and toString methods for simple Java classes. If you want all these methods generated for you, automatically, you can just use the @Data annotation like the following.

package com.juixe.core.pojo;

import lombok.Data;

@Data
public class Person {
   private Long id;
   private String firstName;
   private String lastName;
}

There is also a @Value annotation that is similar to @Data except that it is intended for immutable objects, so it doesn’t generate any setter methods.


Nov 28 2011

Retweet October 2011

From time to time I just blast tweets about software development, project planning, team dynamics, or whatever else comes to mind. Here is a synopsis of recent tweets and rants. If you want to follow the conversation follow me at techknow and/or juixe.

Software Development

  • To checkin or not to checkin a large changelist five minutes before you go home, that is the question?
  • A test like a good movie, has three parts: the setup, the car chase, and the test of the results.
  • Testing is like a tax, you have to pay 5-10% to have a good running infrastructure or system.
  • Testing takes time, make sure you make the time, because it will save you time in the long run.
  • All programmers have a black belt in hubris.
  • One bytecode to rule them all.

Thought Leadership

  • Your miles may vary, but it often depends on your attitude.
  • Passion + Perseverance = Possibilities
  • Sometimes you can’t afford to lose a client, but there are other times you can’t afford keep your client.
  • Just like there should be no hard coded strings there should be no unwritten rules, or assumptions, or specifications.
  • The dumbest people I’ve ever encountered are those that think that the rest of the 99.99% of people are a bunch of idiots.
  • If you are unique no one can compete with you.
  • Team meetings should not feel like an AA meeting, “Hi, I’m bob and I work here.”

Product Placement

  • I’ve used the iPhone apps for Google Voice and G+ and I have to say, Google does not know how to make a good iOS app.
  • I’m not liking the new Google Reader look. I would not be surprised if the next version of Google design has ribbons.
  • Leave no smart phone behind. Google won’t upgrade the Nexus One to Android 4.0.
  • Google is set to update its motto to “Do no evil if you ain’t getting paid for such evil.”
  • Android is to Google what Internet Explorer was to Microsoft in the Browser Wars. MS gave IE for free just to take out Netscape.
  • Siri is to Apple what Kinect is to XBox what Facebook Connect is to Facebook what Circles are to Google Plus…
  • Every time I upgrade a MS product an angel loses his wings.
  • Is Amazon also adopting social networking features? I just noticed that Amazon has a like button on its product pages.
  • Facebook should update its mission “to trick people to over share and make the world more open, connected, and trackable.”
  • Google should update its mission “to organize the world’s information about our users and make it accessible and useful to our advertisers.”
  • @att has two options in terms of text messages. Pay as you use for $0.20 or unlimited for $20. What about a third option, disable texting altogether?
  • Why does it cost half of the price of a stamp to send or receive a text? It’s endemic of an industry that has no competition or innovation.
  • The Kindle Fire tablet is a modern day physical shopping cart for Amazon’s virtual online store.
  • History is being made every day, yet @historychannel airs reruns of Ancient Alien.

Quotes

  • OH WOW. OH WOW. OH WOW. – Steve Jobs’ Last Words
  • I’m so embarrassed. I wish everybody else was dead. – Bender Bending Rodriguez
  • Goodbye monobrains – Bender Bending Rodriguez
  • There is no recession for great companies… – Jason Calacanis
  • Software is like sex: it’s better when it’s free. – Linus Torvalds
  • Coming together is the beginning; keeping together is a process; working together is success. – Henry Ford
  • When all men think alike, no one thinks very much. – Walter Lippmann

Randumb

  • On Monday mornings we are all zombies.
  • Why am I listening to old school British punk rock? #GodSpankTheQueen
  • The truth is that truth is absolutely relative.
  • And then God said, “Let there be bacon,” and there was bacon. God saw that the bacon was delicious.
  • You’re so vain, you probably think this tweet is about you.
  • Fist pump for peace.
  • Anybody that gets lost in a corn maze is an absolute moron.
  • I hate Lifetime movies!
  • Business is legitimate thievery.
  • Some of the most common elements on earth idiotum and dumbtonium.
  • meta-disrupt: Disrupt those disrupting disruption.
  • I am, therefore I meme.

Thought Equations

  • Meaning > money
  • problem = opportunity
  • means != ends
  • Success > Perfection
  • Experience != Information
  • Thinking > Knowing
  • Do > try
  • Platform > product
  • Creation > criticism
  • Passion + Perseverance = Possibilities

Million Dollar Ideas

  • Million Dollar Idea: Online Speed Dating Site
  • Million dollar idea: a news channel with nothing but news tickers…
  • Million Dollar Idea: self cleaning floors.