Reading Java SE 8 for the Really Impatient by Cay S. Horstmann, Addison-Wesley (2014)

Eagerly anticipated by millions of programmers, Java SE 8 is the most important Java update in many years. The addition of lambda expressions (closures) and streams represents the biggest change to Java programming since the introduction of generics and annotations.

Now, with Java SE 8 for the Really Impatient , internationally renowned Java author Cay S. Horstmann concisely introduces Java 8’s most valuable new features (plus a few Java 7 innovations that haven’t gotten the attention they deserve). ...

Implementing "press any key to continue" in Java

Well, strictly speaking, it is "press ENTER to continue".

Reading Java Network Programming by Elliotte Rusty Harold, O'Reilly (2013)

This practical guide provides a complete introduction to developing network programs with Java. You’ll learn how to use Java’s network class library to quickly and easily accomplish common networking tasks such as writing multithreaded servers, encrypting communications, broadcasting to the local network, and posting data to server-side programs. Author Elliotte Rusty Harold provides complete working programs to illustrate the methods and classes he describes. This thoroughly revised fourth edition covers REST, SPDY, asynchronous I/O, ...

Handling arithmetic overflow: an exercise of parsing strings to integers

Let us say we want to parse a string to an integer, where we must throw an exception if the parsed value is too positive or too negative. This boils down to how arithmetic overflow can be detected.

Java reference objects: strong, soft, weak, and phantom

Java reference objects generally provide two ways of interaction with the garbage collector: to control when an object can be garbage collected and to receive a notification when an object is garbage collected. After so long, I find myself not able to clearly describe them again. I would like to take some notes here as my memory was just refreshed, in case I forget later. This is going to be a short note, just enough for distinguishing them by their most prominent characteristics. Please consult the javadoc for more details.

Five tips for defining classes of constants

Classes of constants are usually used in the name of removing duplication. But chances are that such classes are eventually cluttered with unrelated constants, causing unnecessary coupling among components. In fact, a lot of constants are private to specific components, and should not be exposed as public static final fields.

Multiple DefaultCommand in a form using different scopes in PrimeFaces

DefaultCommand in PrimeFaces is for specifying which clickable command in a form to trigger when ENTER key is pressed on an input in the form. It is especially useful when there are multiple commands in the form. Suppose that we have two Dialog in a form, and each has some inputs and a command button. Then two DefaultCommand can be defined so that when ENTER key is pressed on the inputs of either Dialog, the corresponding command button is triggered. If no DefaultCommand were defined, the first button with the type submit would always be triggered in most browsers.

Is a javax.persistence.EntityManager thread safe to be an instance variable?

In a JPA based DAO class, we usually declare an EntityManager as an instance variable annotated with @PersistenceContext, and use it in the methods of the class. This usage seems to work fine and I just accepted it without further thinking. But recently it turned into a question when I was working on some JPA code that, how could an entity manager be thread safe as an instance variable, while an entity manager does not seem to be meant for sharing among multiple threads?

Reading Java Message Service by Mark Richards et al., O'Reilly (2009)

Messaging systems allow you to loosely couple heterogeneous systems together with added reliability. Java Messaging Service (JMS) providers use a system of transactions, to commit or roll back changes atomically. Unlike systems based on a Remote Procedure Call (RPC) pattern, messaging systems primarily use an asynchronous message passing pattern with no tight relationship between requests and responses. Most messaging systems also support a request-response mode but this is not a primary feature of messaging systems.

Breaking a thread coordinating cyclic barrier

A CyclicBarrier is a synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point. Suppose that in a test, there is a Runnable which needs to be executed by multilpe threads at the same time for multiple rounds. Then the beginning and ending for each round can be coordinated by a CyclicBarrier that a manager thread can signal the beginning of a round to all the worker threads, and wait until all the worker threads finish to end the round. The beginning and ending can then happen for more rounds.