Showing posts from January, 2015

Java 8 Optional is not just for replacing a null value

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 is to treat Optional like a Stream with 0 or 1 values. Simple Optional Use Case In the old days of Java 7 you would write something like String text = something(); if (text != null) { Note: Oracle Java 7 will be "End of Public Updates" in April 2015. With Optional you can instead write Optional text = something(); if (text.isPresent()) {     String text2 = text.get(); However, if you are being paranoid you might write. Optional text = something(); if (text != null && text.isPresent()) {     String text2 = text.get(); If you have NullPointerException errors often in your project Optional might help, but


With micro-services, micro-fortnights and more micro-buzz words, I was wondering which micro-buzz words might actually be useful if only to confuse people. micro-day - about 1/12 of a second. micro-fortnight - ~1.2 seconds. micro-year - ~1/2 a minute. micro-decade - ~5 minutes. micro-century - 51.3 minutes. micro-mile - ~1.6 milli-metres. micro-light second - ~300 meters. Now you have some more micro-terms you can use to avoid buzz word bingo. ;) Some more to play with atto-parsec - about 3 cm. femto-parsec - about 30 metres. An IT 5 more minutes - maybe half an hour.

Mixing memory unit messages

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 units "b" means bits "B" means bytes "k" or kilo- is standard prefix meaning 1000 "K" or "Ki", sometimes called kibi- is 1024 "m" or mill-, means 1/1000th "M" or mega-, means 1000^2 "Mi" or mebi-, means 1024^2  Unit       Meaning       In bytes mb     milli-bits 1/8000th of a byte mB     milli-bytes 1/1000th of a byte kb     kilo-bits 125 bytes kB     kilo-bytes 1000 bytes Kb or Kib     kibi-bits 128 bytes KB or KiB     kibi-bytes 1024 bytes Mb     mega-bits 125,000 bytes MB     mega-bytes 1,000,000 bytes Mib     mebi-bits 13

Java Lambdas and Low Latency

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 uses text with fields like JSon or YAML, text with field numbers like FIX, binary with field names like BSON or a Binary form of YAML, binary with fields name, field numbers or no field meta at all.  The values can be fixed length, variables length and/or self describing data types. The idea being that it can handle a variety of schema changes or if you can determine the schema is the same e.g. over a TCP session, you can skip all that and just send the data. Another big idea is using lambdas to support this. What is the problem with Lambdas The main issue is the need to avoid significant garbage in low latencies applications.  Not