Good programming practices


Concise Java code

April 22nd, 2012

Here is an example how concise Java code can be. I wrote 2 methods that do the same, but looks different. It checks if an Iterable object has only one object, which is additionally equals to the one passed as the second argument. Both methods use Objects class added in Java 7. The first method use “&&” operator, which evaluates expression on right only when the left one was true. More…

Java code conditional compilation

September 8th, 2011

Java language doesn’t have a preprocessor like C. But compiler optimize the code – if it’s sure, that code can’t be reached, it will not be included in the output byte code. An optional code can be placed inside if statement or by tertiary statement, where condition can be evaluated by compiler. More…

Lazy evaluation in Java

August 11th, 2011

Invoking some methods you may not know if passes arguments will be ever used. In most cases it wouldn’t be a problem. But sometimes evaluating not necessary arguments may cause performance issues. In Java all arguments are evaluated before call of a method. However, there are some circumvent. More…