Posts

Showing posts with the label java 8

HOW-TO: Java 8 Date & Time with Thymeleaf and Spring Boot

If you happen to work with Spring Boot and Thymeleaf and you need to format Java 8 Date & Time objects in your views you may utilize thymeleaf-extras-java8time - Thymeleaf module for Java 8 Date & Time API.

JUnit: Testing Exceptions with Java 8 and AssertJ 3.0.0

AssertJ 3.0.0 release for Java 8 makes testing exceptions much easier than before. In one of my previous blog post I described how to utilize plain Java 8 to achieve this, but with AssertJ 3.0.0 much of the code I created may be removed. Warning: this blog post contains mostly the code examples.

Spring 4.1 and Java 8: java.util.Optional as a @RequestParam, @RequestHeader and @MatrixVariable in Spring MVC

Image
As of Spring 4.1 Java 8’s java.util.Optional , a container object which may or may not contain a non-null value, is supported with @RequestParam , @RequestHeader and @MatrixVariable . While using Java 8’s java.util.Optional you make sure your parameters are never null .

JUnit: testing exception with Java 8 and Lambda Expressions

Image
In JUnit there are many ways of testing exceptions in test code, including try-catch idiom , JUnit @Rule , with catch-exception library. As of Java 8 we have another way of dealing with exceptions: with lambda expressions. In this short blog post I will demonstrate a simple example how one can utilize the power of Java 8 and lambda expressions to test exceptions in JUnit.

Lambda Expressions and Stream API: basic examples

This blog post contains a list of basic Lambda expressions and Stream API examples I used in a live coding presentation I gave in June 2014 at Java User Group - Politechnica Gedanensis (Technical University of Gdańsk) and at Goyello .

Listing a ZIP file contents with Stream API in Java 8

In Java 8 java.util.zip.ZipFile was equipped with a stream method that allows navigating over a ZIP file entries very easily. In this blog post I will show a bunch of examples showing how quickly we can navigate over ZIP file entries.

Spring 4: @DateTimeFormat with Java 8 Date-Time API

Image
@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.

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.