Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

commons-lang just made it easier

I got some advice from Max Anderson (via hibernate-devel mailing list) for implementing the following methods in a BaseObject class for my hibernate objects (or any objects FTM):

public boolean equals(Object o) {
  return EqualsBuilder.reflectionEquals(this, o);
}

public String toString() {
  return ToStringBuilder.reflectionToString(this);
}

public int hashCode(Object o) {
  return HashCodeBuilder.reflectionHashCode(this);
}

Boy, that sure makes things easier, huh? Especially when you compare the toString() method to my old one:

public String toString() {
    StringBuffer results = new StringBuffer();
    Class clazz = getClass();

    results.append(getClass().getName() + "\n");

    Field[] fields = clazz.getDeclaredFields();

    try {
        AccessibleObject.setAccessible(fields, true);

        for (int i = 0; i < fields.length; i++) {
            results.append("\t" + fields[i].getName() + "=" +
                           fields[i].get(this) + "\n");
        }
    } catch (Exception e) {
        // ignored!
    }

    return results.toString();
}

They both use reflection, but my old one might catch security excaptions. The Javadocs for HashCodeBuilder warn us about this problem:

Alternatively, there is a method that uses reflection to determine the fields to test. Because these fields are usually private, the method, reflectionHashCode, uses Field.setAccessible to change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions are set. It is also slower than testing explicitly.

I'll be using these on Tomcat and I'll let you know if I run into any problems.

Posted in Java at Dec 29 2002, 09:19:52 AM MST Add a Comment
Comments:

Post a Comment:
  • HTML Syntax: Allowed