Posts Tagged: JDK

The eternal issue about Object.hashCode() in Java

Posted by & filed under , .

Have you heard of hashCode() and equals() in Java and the eternal discussions around this? And you know by now the implications of having a messed up relationship in between hashCode and equals so you make sure every time you implement a class with an equals() you have to make sure hashCode() follows suit right? […]

Little-known yet useful Java annotation: ConstructorProperties

Posted by & filed under , .

I’ve discovered this recently while looking into some issues caused by the Jackson libraries in one of my Java applications. If you use Jackson I’m sure you are by now familiar with some of the annotation they supply — such as @JsonProperty and @JsonCreator — and it was dealing with these that got me to […]

RxJava: Some Usage of Observable.zip

Posted by & filed under , .

Here’s  classic problem when dealing with a web app: you get a HTTP request to your app with a set of parameters. You need to hit a datastore to retrieve some record based on those parameters. You also need to create a (log?) entry somewhere about receiving this call — whether it’s for monitoring purposes […]

Using Optional in Java to check for null

Posted by & filed under , .

I see the need for null in Java still, but since the Optional class was introduced I think some of the usages of null can be eliminated by employing some of the capabilities of the Optional class. I will explain in this post a nice way you can implement checking for null in Java by […]

Dependency overload … or laziness?

Posted by & filed under , .

This is something that started bugging me back in the maven area — when I switched from the likes of Ant as a build tool, which was relying on the user being explicit about a lot of things and doing a lot of the grunt work for it, to the maven world. Now maven was […]

java code

Java Dependency Injection and a Useless Annotation

Posted by & filed under , .

I’ve stepped into the Guice territory rather recently — coming from the Spring framework side of things — and I guess I had so far a similar love/hate experience as with Spring. I rely mostly on the javax.annotation standards anyway so to a certain degree whether it’s Spring or Guice I guess doesn’t make that much […]

Scripting

Java, Map and Optional

Posted by & filed under , .

I do like the Optional class in Java — it is a long awaited elegant replacement for returning null whenever something isn’t there then relying on if( x != null ) checks or using ?: in the format (x == null) ? “foo” : “bar”. It works great also with the new Java stream classes […]

Collection Sorting — Java vs Groovy

Posted by & filed under , .

With the introduction of lambdas in Java (not so) recently, some argue that Groovy lost some of its thunder, as closures are now first class citizens in the JDK. However, as I’m about to show, while lambda’s pushed the Java language a great deal forward, Groovy still makes a lot of things incredibly easy (and […]

Parallel : Groovy and Java Streams

Posted by & filed under .

This is something that every now and then I have to do: check whether either one or all elements of a collection meet a certain criteria. The standard code initially in Java involved a for loop and iterating through the collection explicitly and checking the condition at each step. Then Apache Commons came on with their […]

Goodies in Groovy from DefaultGroovyMethods

Posted by & filed under , .

If you ever programmed in Groovy language, you probably “enjoyed” (maybe without realising) the joys of DefaultGroovyMethods. What you probably don’t realise is that you can override these methods to customize your classes — and occasionally generate some code that’s not that easy to read. (Do you remember the old C++ way of overriding operators […]