Home » Tag Archives: Java 8 (page 2)

Tag Archives: Java 8

Java 8 Streams: filter and predicate negation

java-logo

Recently there was an interesting discussion on the use of predicate negation in the .filter method on a stream by members of the LJC mailing list, so I thought it would be worth summarising it in a blog post. The discussion was about ways to use .filter and to negate the predicate. Code for this post is available in my ...

Read More »

From Arrays to Streams and Back with Java 8

java-logo

Not long ago we upgraded some Eclipse plug-in projects to Java 8. And never looked back since. Among many other things, filtering, mapping, and finding elements in collections has become so much easier and more concise with lambdas and the streams API. Nothing new so far for the most of you, I guess. But many existing APIs use arrays in ...

Read More »

The Danger of Subtype Polymorphism Applied to Tuples

java-logo

Java 8 has lambdas and streams, but no tuples, which is a shame. This is why we have implemented tuples in jOOλ – Java 8’s missing parts. Tuples are really boring value type containers. Essentially, they’re just an enumeration of types like these: public class Tuple2<T1, T2> { public final T1 v1; public final T2 v2; public Tuple2(T1 v1, T2 ...

Read More »

Wrap around design pattern in java8

java-logo

Wrap around pattern is not listed in in GOF book but is very useful for problem like below: Loop construct for e.g do while/while/for loop Stopwatch around some code. Wrap checked exception with run time exception Initialization and cleanup for eg Threadpool creation/destruction or file open/close etc Adding context info to threads for eg request context info for logging or ...

Read More »

Java 8 Lambda Expression for Design Patterns – Command Design Pattern

java-logo

In this blog I would illustrate implementing the command pattern in functional programming style using Java 8 Lambda expressions. The intent of command pattern is to encapsulate a request as an object, thereby parameterizing clients with different requests, queue or log requests, and support corresponding operations. The command pattern is a way of writing generic code that sequences and executes ...

Read More »

Comparing Imperative and Functional Algorithms in Java 8

java-logo

Mario Fusco’s popular tweet impressively shows what the main difference between imperative and functional approaches to similar algorithms really is: Imperative vs. Functional – Separation of Concerns pic.twitter.com/G2cC6iBkDJ — Mario Fusco (@mariofusco) March 1, 2015 Both algorithms do the same thing, they’re probably equally fast and reasonable. Yet, one of the algorithms is much easier to write and read than ...

Read More »

Stream Performance

java-logo

When I read Angelika Langer’s Java performance tutorial – How fast are the Java 8 streams? I couldn’t believe that for a specific operation they took about 15 times longer than for loops. Could stream performance really be that bad? I had to find out! Coincidently, I recently watched a cool talk about microbenchmarking Java code and I decided to ...

Read More »

Common SQL Clauses and Their Equivalents in Java 8 Streams

java-logo

Functional programming allows for quasi-declarative programming in a general purpose language. By using powerful fluent APIs like Java 8’s Stream API, or jOOλ’s sequential Stream extension Seq or more sophisticated libraries like javaslang or functionaljava, we can express data transformation algorithms in an extremely concise way. Compare Mario Fusco’s imperative and functional version of the same algorithm: Imperative vs. Functional ...

Read More »

What is the fastest Garbage Collector in Java 8?

java-logo

OpenJDK 8 has several Garbage Collector algorithms, such as Parallel GC, CMS and G1. Which one is the fastest? What will happen if the default GC changes from Parallel GC in Java 8 to G1 in Java 9 (as currently proposed)? Let’s benchmark it. Benchmark methodology Run the same code 6 times with a different VM argument (-XX:+UseSerialGC, -XX:+UseParallelGC, -XX:+UseConcMarkSweepGC, ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Advanced Java Guide
  • Java Design Patterns
  • JMeter Tutorial
  • Java 8 Features Tutorial
  • JUnit Tutorial
  • JSF Programming Cookbook
  • Java Concurrency Essentials