Java 8 comes with a new Optional type, similar to what is available in other languages. This post will go over how this new type is meant to be used, namely what is it’s main use case. What is the Optional type? Optional is a new container type that wraps a single value, if the value is available. So it’s ...
Read More »Spring 4: @DateTimeFormat with Java 8 Date-Time API
@DateTimeFormat annotation that was introduced in Spring 3.0 as a part of Formatter SPI can be used to to parse and print localized field values in web applications. In Spring 4.0, @DateTimeFormat annotation can be used with Java 8 Date-Time API (java.time) out-of-the-box, without extra effort. In Spring, field formatting can be configured by field type or annotation. To bind ...
Read More »Java 8 StampedLocks vs. ReadWriteLocks and Synchronized
Synchronized sections are kind of like visiting your parents-in-law. You want to be there as little as possible. When it comes to locking the rules are the same – you want to spend the shortest amount of time acquiring the lock and within the critical section, to prevent bottlenecks from forming. The core language idiom for locking has always been ...
Read More »Is it Imperative that you learn Functional Programming with Java 8?
I’ve recently been taking look at Java 8 and have got hold of “Java 8 In Action” published by Manning. The first thing that struck me is how one of Java 8’s unique sales propositions is functional programming; functions are now first class variables, you can pass them around your code as you would an int or a String. This ...
Read More »Parsing a file with Stream API in Java 8
Streams are everywhere in Java 8. Just look around and for sure you will find them. It also applies to java.io.BufferedReader. Parsing a file in Java 8 with Stream API is extremely easy. I have a CSV file that I want to be read. An example below: username;visited jdoe;10 kolorobot;4 A contract for my ...
Read More »Java 8 Friday: Better Exceptions
At Data Geekery, we love Java. And as we’re really into jOOQ’s fluent API and query DSL, we’re absolutely thrilled about what Java 8 will bring to our ecosystem. Java 8 Friday Every Friday, we’re showing you a couple of nice new tutorial-style Java 8 features, which take advantage of lambda expressions, extension methods, and other great stuff. You’ll find ...
Read More »Java 8 default methods can break your (users’) code
At first glance, default methods brought a great new feature to the Java Virtual Machine’s instruction set. Finally, library developers are able to evolve established APIs without introducing incompatibilities to their user’s code. Using default methods, any user class that implements a library interface automatically adopts the default code when a new method is introduced to this interface. And once ...
Read More »Too Fast, Too Megamorphic: what influences method call performance in Java?
Whats this all about then? Let’s start with a short story. A few weeks back I proposed a change on the a Java core libs mailing list to override some methods which are currently final. This stimulated several discussion topics – one of which was the extent to which a performance regression would be introduced by taking a method which ...
Read More »Java 8 Friday: Language Design is Subtle
At Data Geekery, we love Java. And as we’re really into jOOQ’s fluent API and query DSL, we’re absolutely thrilled about what Java 8 will bring to our ecosystem. Java 8 Friday Every Friday, we’re showing you a couple of nice new tutorial-style Java 8 features, which take advantage of lambda expressions, extension methods, and other great stuff. You’ll find ...
Read More »