java

The Mediator Design Pattern in Java

Summary: The Mediator Design Pattern is demonstrated in a Java example (a Java Mediator Pattern example).

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:

Scala REPL - java.lang.OutOfMemoryError: Java heap space error

I just got a “java.lang.OutOfMemoryError: Java heap space error” when trying to use the Scala REPL to analyze a large XML dataset:

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.

Computer programming languages ranked by "expressiveness"

Computer programming languages ranked by "expressiveness", from http://redmonk.com/dberkholz/2013/03/25/programming-languages-ranked-by-...

Using Scala as a 'better Java'

A lot of people want to sell Scala as a functional programming (FP) language. That's fine, it certainly is, and FP has many benefits. But when I first started working with Scala I was just looking for a "better Java".

Personally, I grew tired of Java's verbosity. Ruby showed us a different way, and I loved it, but ... after a while I felt like many of my unit tests in Ruby wouldn't be necessary if the language had static types. I wished for a concise Ruby-like language with static types.

Scala break and continue examples

Scala FAQ: Can you share some examples of how to implement break and continue functionality in Scala?

Sure. The example Scala code below shows both a break and a continue example. As you can see from the import statement, it uses the code in the Scala util.control.Breaks package.

To understand how this works, let's first look at the code, and then the output. First, here's the code:

Scala currency and money libraries (JVM-based libraries)

I've been trying to find some good Scala currency and money libraries lately, and I just ran across the following list of projects on the Joda Money Github project. That URL contains the following list of Java and JVM-based projects that should all be usable in Scala:

A Java deep clone (deep copy) example

While interviewing for computer programming positions here in the Boulder, Colorado area, I've found that most interviewers ask questions about Java serialization. After being asked about serialization for the third time recently, I suddenly remembered an old Java deep clone hack that takes advantage of serialization.

The basic idea is this:

A Java Factory Pattern example

Java Design Patterns FAQ: Can you provide an example of the Factory Pattern in Java?

Sure. In this article we'll look at a small-but-complete example of the Factory Pattern ("Factory Design Pattern") implemented in Java.

Syndicate content