Home » Author Archives: Tomasz Nurkiewicz (page 4)

Author Archives: Tomasz Nurkiewicz

Java EE developer, Scala enthusiast. Enjoying data analysis and visualization. Strongly believes in the power of testing and automation.

Automated bug finding with git bisect and mvn test

git-logo

Do you know the feeling when you discover a bug in a functionality that was working couple of weeks (or versions) ago? Too bad we didn’t have any automated tests and what used to be fine, now is broken. Let’s take this simple repository as an example:   Write test first We noticed that some particular functionality was OK in ...

Read More »

Simplifying ReadWriteLock with Java 8 and lambdas

java-logo

Considering legacy Java code, no matter where you look, Java 8 with lambda expressions can definitely improve quality and readability. Today let us look at ReadWriteLock and how we can make using it simpler. Suppose we have a class called Buffer that remembers last couple of messages in a queue, counting and discarding old ones. The implementation is quite straightforward: ...

Read More »

Custom Spring namespaces made easier with JAXB

spring-interview-questions-answers

First of all, let me tell this out loud: Spring is no longer XML-heavy. As a matter of fact you can write Spring applications these days with minimal or no XML at all, using plenty of annotations, Java configuration and Spring Boot. Seriously stop ranting about Spring and XML, it’s the thing the of the past. That being said you ...

Read More »

Three flavours of request-response pattern in Akka

akka-logo

Imagine a simple Akka actor system consisting of two parties: MonitoringActor and NetworkActor. Whenever someone (client) sends CheckHealth to the former one it asks the latter by sending Ping. NetworkActor is obligated to reply with Pong as soon as possible (scenario [A]). Once MonitoringActor receives such a reply it immediately replies to the client with Up status message. However MonitoringActor ...

Read More »

Turning Twitter4J into RxJava’s Observable

java-logo

aTwitter4J is a Java wrapper around Twitter API. While Twitter supports simple request-response interactions in this article we will explore streaming APIs. In contrary to request-response model which is always initiated by the client, streaming API pushes data from Twitter server to the clients as soon as they are available. Of course in case of Twitter we are talking about ...

Read More »

Proxies done right with Guava’s AbstractInvocationHandler

java-interview-questions-answers

Not too often but sometimes we are forced to write custom dynamic proxy class using java.lang.reflect.Proxy. There is really no magic in this mechanism and it’s worth knowing even you will never really use it – because Java proxies are ubiquitous in various frameworks and libraries. The idea is quite simple: dynamically create an object that implements one or more ...

Read More »

Playing with futures

scala-logo

During job interviews we often give Scala developers a simple design task: to model a binary tree. The simplest but not necessarily best implementation involves Option idiom:                 case class Tree[+T](value: T, left: Option[Tree[T]], right: Option[Tree[T]]) Bonus points for immutability, using case class and covariance. Much better but more complex implementation involves two ...

Read More »

instanceof operator and Visitor pattern replacement in Java 8

java-logo

I had a dream where instanceof operator and downcasting were no longer needed but without clumsiness and verbosity of visitor pattern. So I came up with the following DSL syntax:                 Object msg = //... whenTypeOf(msg). is(Date.class). then(date -> println(date.getTime())). is(String.class). then(str -> println(str.length())). is(Number.class). then(num -> println(num.intValue())). orElse(obj -> println("Unknown " + ...

Read More »

Optional in Java 8 cheat sheet

java-logo

java.util.Optional<T> in Java 8 is a poor cousin of scala.Option[T] and Data.Maybe in Haskell. But this doesn’t mean it’s not useful. If this concept is new to you, imagine Optional as a container that may or may not contain some value. Just like all references in Java can point to some object or be null, Option may enclose some (non-null!) ...

Read More »

Asynchronous retry pattern

java-logo

When you have a piece of code that often fails and must be retried, this Java 7/8 library provides rich and unobtrusive API with fast and scalable solution to this problem:                   ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); RetryExecutor executor = new AsyncRetryExecutor(scheduler). retryOn(SocketException.class). withExponentialBackoff(500, 2). //500ms times 2 after each retry withMaxDelay(10_000). //10 ...

Read More »
Do you want to know how to develop your skillset and become a ...

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!
Get ready to Rock!
To download the books, please verify your email address by following the instructions found on the email we just sent you.

THANK YOU!

Close