Home » Author Archives: Peter Lawrey

Author Archives: Peter Lawrey

How and Why to Serialize Lambdas

java-logo

Overview Serializing lambdas can be useful in a number of use cases such as persisting configuration, or as a visitor pattern to remote resources. Remote Visitors For example, so I want to access a resource on a remote Map, I can use get/put, but say I just want to return a field from the value of a Map, I can ...

Read More »

Puzzler: nested computeIfAbsent

java-logo

Overview The Java 8 libraries have a new method on map, computeIfAbsent. This is very useful way to turn your Map into a cache of objects associated with a key. However, there is a combination you might not have considered; what happens if you call computeIfAbsent inside itself. map.computeIfAbsent(Key.Hello, s -> { map.computeIfAbsent(Key.Hello, t -> 1); return 2; }); enum ...

Read More »

What are the bad features of Java

java-logo

Overview When you first learn to develop you see overly broad statements about different features to be bad, for design, performance, clarity, maintainability, it feels like a hack, or they just don’t like it. This might be backed by real world experience where removing the use of the feature improved the code. Sometimes this is because the developers didn’t know ...

Read More »

Inconsistent operation widen rules in Java

java-logo

Overview When you perform a unary or binary operation in Java the standard behaviour is to use the widest operand (or a wider one for byte, short and char).  This is simple to understand but can be confusing if you consider what the optimal type is likely to be. Multiplication When you perform multiplication, you often get a much large ...

Read More »

Java 8 Optional is not just for replacing a null value

java-logo

Overview In Java 8, you can return an Optional instead of return null; as you might do in Java 7. This may or may not make a big difference depending on whether you tend to forget to check for null or whether you use static code analysis to check to nullalbe references. However, there is a more compelling case which ...

Read More »

Mixing memory unit messages

software-development-2-logo

One of my pet hates is developers messing up units of memory.  In general, the difference doesn’t matter much, or you can work out what they meant to say, but it does annoy me when developers who should know better appear to be confused about what they are trying to say. From Wikipedia’s Byte page, here is a cheat sheet of ...

Read More »

Java Lambdas and Low Latency

java-logo

Overview The main question around the use of Lambdas in Java and Low Latency is; Does they produce garbage and is there anything you can do about it? Background I am working on a library which supports different wire protocols. The idea being that you can describe the data you want to write/read and the wire protocol determines if it ...

Read More »

How and Why is Unsafe used in Java?

java-logo

Overview sun.misc.Unsafe has been in Java from at least as far back as Java 1.4 (2004). In Java 9, Unsafe will be hidden along with many other, for-internal-use classes. to improve the maintainability of the JVM. While it is still unclear exactly what will replace Unsafe, and I suspect it will be more than one thing which replaces it, it raises the ...

Read More »

On heap vs off heap memory usage

java-logo

Overview I was recently asked about the benefits and wisdom of using off heap memory in Java. The answers may be of interest to others facing the same choices. Off heap memory is nothing special. The thread stacks, application code, NIO buffers are all off heap.  In fact in C and C++, you only have unmanaged memory as it does not have ...

Read More »

Chronicle Map and Yahoo Cloud Service Benchmark

java-logo

Overview Yahoo Cloud Service Benchmark is a reasonably widely used benchmarking tool for testing key value stores for a significant number of key e.g 100 million, and a modest number of clients i.e. served from one machine. In this article I look at how a test of 100 million * 1 KB key/values performed using Chronicle Map on a single ...

Read More »
Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.