Category: Java
-
Java 11 HttpClient, Gson, Gradle, and Modularization
This post describes a simple system that uses the new HttpClient class that comes with Java 11 to access a RESTful web service. After demonstrating basic functionality, changes are made to parse the results using Gson, and even modularize the code and have it work with Gradle. The goal is to provide an example for…
-
Java 8 Constructor Refs (In All Their Glory)
[Note: my last post announced my new book, Modern Java Recipes, is now available from O’Reilly publishers in Early Release form. As a sample, I included a discussion of the Predicate interface, one of the new functional interfaces in the the java.util.function package. In this post, I highlight constructor references, which are discussed in another…
-
Modern Java Recipes now in Early Release
My latest book, Modern Java Recipes, is now available in Early Release form! If you have a Safari account (the online book repository from O’Reilly), you can add it to your bookshelf at any time. Otherwise, you can get it directly from http://shop.oreilly.com or even at Amazon.com. There are only three chapters in the Early…
-
Days Between Dates in Java 8
I would like to address a problem that is quite topical at the moment: calculating the number of days between two events. The new Date-Time API in Java 8 makes this process much simpler than it used to be. The Date-Time API includes the interface java.time.temporal.TemporalUnit, which is implemented by the enum ChronoUnit in the…
-
Making Java 8 Groovier: A few annotated examples
In a couple of weeks, I’m giving two talks at talk at the 2016 JavaOne conference in San Francisco. One of them is called “Groovy and Java 8: Making Java Better“. I’m building examples in preparation for the conference, and as the Groovy community is good about correcting my errors in a friendly way, I…
-
Fun with Time Zones in Java 8
[Note: Revised based on suggestions in the comments.] They say that one way to identify a software developer is to whisper the word “timezone” in their ear and see if they shudder. That’s certainly true for me, though my reaction is based more on travel and trying to arrange conference calls across time zones than…