recent posts related to java, jdbc, spring, etc.

Law of Demeter - Java examples

Summary: The Law of Demeter is discussed using Java source code examples.

Whenever you talk to a good, experienced programmer, they will tell you that "loosely coupled" classes are very important to good software design.

The Law of Demeter for functions (or methods, in Java) attempts to minimize coupling between classes in any program. In short, the intent of this "law" is to prevent you from reaching into an object to gain access to a third object's methods. The Law of Demeter is often described this way:

Java enum examples/tutorial

Java enum FAQ: Can you share some Java enum examples, such as how to declare a Java enum, and how to use a Java enum in a for loop, if then statement, and Java switch statement?

As described in Sun's Java documentation, a Java enum "is a type whose fields consist of a fixed set of constants ... you should use enum types any time you need to represent a fixed set of constants." Let's take a look at some Java enum examples to see how this works.

Converting a Scala class file to decompiled Java source code

As a Scala newbie, I'm curious about how the process of converting a Scala class back to Java source code works. What I really want to see is how my Scala source code is converted to Java source code. Besides plain old curiosity, I think that understanding more about how Scala works can also be very important to my understanding of Scala (such as the apply() method, and so on).

A simple Java Generics example class

To take a break from a project I was working on yesterday I gave my brain a little exercise to see if I could remember how to create a Java class that used the Java 5 Generics magic. Since I've used Scala a lot recently, I decided to create a Java version of the Scala Tuple class.

The Tuple class simply stores two values, which are often key/value pairs. Beginning with the end in mind, here's how you typically use a Tuple:

Syndicate content