Feed aggregator

Maven, Eclipse, and Java 9

Javalobby Syndicated Feed - Mon, 12-Mar-18 13:01

TL;DR: Eclipse users who use Maven are used to the M2E plugin issue of having your JRE reset on you. But there's an additional gotcha between Java 8 and Java 9. Read on for the details.

Anyone that uses the M2E(maven-to-eclipse) plugin in eclipse knows the issue where you have run a build, then update maven on your project only to have it reset the JRE and throw up a wall of project errors! I noticed the issue in the post I made on running Java EE 8 with Java 9 using Open Liberty

The solution is to ensure the compiler is running the correct version you require, so -

Categories: Java

Modifying Immutable Objects With Chained Methods

Javalobby Syndicated Feed - Mon, 12-Mar-18 09:01

When you are coding with immutable objects, there are many times where you not only need to initially define them, but may want to create derivative versions of an existing instance. You might want to consider using chained methods to make your code more concise or to take advantage of default or optional parameters.

You have probably implemented an immutable class with final fields with values passed into the constructor like this immutable ConnectionProperties class below:

Categories: Java

Spring Boot 2.0 on ACID! Big Data + Spring Boot

Javalobby Syndicated Feed - Mon, 12-Mar-18 03:01

When I first joined Hortonworks, I wrote an article on integrating Apache Hive and Spring Boot — I came from Pivotal and was a huge fan of Spring Boot. It's been almost 1.5 years and Spring Boot is now in 2.0 and Apache Hive is now in LLAP with ACID transactional tables. So it's time for a remix!

The Use Case for this microservice is to query the Hive ACID table:   inception.   This table is built by Apache NiFi and populated with the results of an MXNet Inception analysis of images.    You pass in a query to the microservice and it runs a search against the text descriptions of the image.   It searches the top1, top2, top3, top4 and top5 fields.  These fields contain a few words each describing what Inception thought the image was.   This is a good way to browse the data for topics.   This is also really simple in Spring Boot.   I could have added the Spring Data JPA project to make it easier, we will probably do that in the next article.   We return the data as JSON even though the table is a regular Hive ACID table stored as Apache ORC files.   This JSON is easy to work with and easy to integrate in Apache NiFi.

Categories: Java

Replacing commons-lang ToStringBuilder With Eclipse

Javalobby Syndicated Feed - Mon, 12-Mar-18 00:01

Recently, I was modifying a common library and I wanted to create a toString method with some (but not all) of the fields of the object.

This can be easily done using the Apache commons-lang ToStringBuilder class. A quick way to generate a toString() method is using the reflectionToString method (though it will include all the object's fields in the result):

Categories: Java

OpenWhisk Functions With Kotlin in IntelliJ

Javalobby Syndicated Feed - Sun, 11-Mar-18 21:01

I’ve implemented some code that shows how Apache OpenWhisk functions can be developed with Kotlin. The Java code is built via Gradle and put into a Docker image, which can be deployed to OpenWhisk cloud providers like the IBM Cloud.

Get the code from GitHub.

Categories: Java

A Guide to Streams: In-Depth Tutorial With Examples

Javalobby Syndicated Feed - Sat, 10-Mar-18 22:01

The addition of the Stream is one of the major new functionality in Java 8. This in-depth tutorial is an introduction to the many functionalities supported by streams, with a focus on simple, practical examples.

To understand this material, you need to have a basic, working knowledge of Java 8 (lambda expressions, method references).

Categories: Java

Immutability in Java

Javalobby Syndicated Feed - Fri, 09-Mar-18 23:01

This post isn’t a tutorial on how to design immutable objects in Java. It’s more of a lament, or perhaps an extended whine. Why is it that Java applications seem to suffer the effects of mutability more than those written in other languages, when it’s no more difficult to design immutable objects in Java than in any other language?

So What?

The first question, I guess, is “So what?” Who cares about immutability, anyway?

Categories: Java

Getting Jaeger’s Java Client Internal Metrics Into Prometheus

Javalobby Syndicated Feed - Fri, 09-Mar-18 10:01

We recently integrated Micrometer into the internal metrics collection mechanism for the Jaeger Java Client, making it easier to get them into Prometheus.

Prometheus showing the internal metrics from the Jaeger Java Client

Categories: Java

Cheatsheet: Java Functional Interfaces

Javalobby Syndicated Feed - Fri, 09-Mar-18 04:01

Looking at the alphabetical list of 43 functional interfaces in java.util.function is a bit overwhelming. Trying to learn and remember them all is going to be a challenge!

Luckily Joshua Bloch came to the rescue in his 3rd edition of Effective Java.

Categories: Java

Java Annotated Monthly: March 2018

Javalobby Syndicated Feed - Fri, 09-Mar-18 01:01

It’s time to share a quick update on what’s been going on in the JVM community over the last month. Before we delve into the news, rumors, and interesting articles, I’d like to share some exciting news… Trisha is returning as the host of this digest, so today’s issue is probably my last one before I turn it back over to her. It has been an honor, enjoy!


As always, we start with the official Java release news. The main topic on everybody’s lips is, of course, Java 10, which is going to be released on the 20th of March. To help you prepare yourself for the new release, Simon Ritter has made an exhaustive list of all changes in this release (including major features, minor changes to the APIs. changes in the specification, etc).

Categories: Java

Spring Webflux: Getting started

Javalobby Syndicated Feed - Thu, 08-Mar-18 22:01

This post will be about how I got started with Spring Webflux. A few weeks ago, I started to read in detail about Spring Webflux, Reactive Streams, etc. Looking back at my journey, I did things in the wrong order. In this post, I have tried to structure the information in order to give you a plan for getting started with Spring Webflux. The examples can be found on GitHub.

Reactive Manifesto

The basis for Reactive Streams can be found in the Reactive Manifesto. It is advised to read this manifesto, it is only 2 pages long, so it won't take long to read it.

Categories: Java

Testing Your Code With Spock

Javalobby Syndicated Feed - Thu, 08-Mar-18 10:01

Spock is a testing and specification framework for Java and Groovy applications. Spock is:

  • Extremely expressive
  • Facilitates the Given/When/Then syntax for your tests
  • Compatible with most IDEs and CI Servers.

Sounds interesting? Well, you can start playing with Spock very quickly by paying a quick visit to the Spock web console. When you have a little test you like, you can publish it like I did for this little Hello World test.

Categories: Java

Implementing Values With Immutable Classes

Javalobby Syndicated Feed - Thu, 08-Mar-18 08:25

Classes representing values should have the same properties as primitive types. Primitive types represent basic values like int or char in Java. Primitive types have no identity and are immutable.

In the following, we will see that those two properties are also useful for classes representing properties.

Categories: Java

GIT for the Scared Java Dev: Trusting Your IDE [Video]

Javalobby Syndicated Feed - Thu, 08-Mar-18 04:01

One of the main issues some developers have when it comes to Git is trusting their IDE integration because... who knows what the IDE is doing? So better rely on a good old command line window and execute the GIT commands yourself.

But isn't there a better way? Doesn't using IDEs have its advantages?

Categories: Java

NullableJ: Handling Null in Java

Javalobby Syndicated Feed - Thu, 08-Mar-18 01:01
"I call it my billion-dollar mistake." — C.A.R Hoare on "Null reference"

"nullis a long-standing problem in programming. Even with Java 8's Optional, we still didn't get thea natural way to handle null we deserved (IMHO, it does a decent job, but we need better). So, I wrote some code to deal with those ... scattered throughout my projects. NullableJ gathers those up into one place. This article discusses features in the NullableJ library for dealing with null. Dig in, I sincerely believe that you will find some of these useful.

Dealing With null

There are generally four ways to handle null.

Categories: Java

Compile- and Run-Time Dependency

Javalobby Syndicated Feed - Wed, 07-Mar-18 22:01

Here is the scenario we have:

You can think of all the code below as being created by you, meaning you are the owner and you already locked the files in the Configuration Management System so that others cannot alter it without you knowing. But you have grown tired of random change requests asking to use different sorting algorithms for the sort function.

Categories: Java

When Functional Programming Isn't

Javalobby Syndicated Feed - Wed, 07-Mar-18 14:01

When functional programming started to become a “thing” in the software industry, I had a lot of difficulty understanding the fundamentals. I’ve always worked primarily in business application software and in system administration. The mathematical orientation of functional programming languages represented an unfamiliar paradigm for me.

I mentioned this to a colleague, and he told me that he fully grokked FP after learning to use lambda expressions in C#. His reply puzzled me, as I had been using lambda expressions in Java, Ruby, and JavaScript for some time, and I knew that similar features were present in other languages, like Python, SmallTalk, and Lisp. I had also done the usual tutorials for languages that had some FP features, like Scala and Clojure. Could it be that FP was really nothing more than this, decorated with arcane buzzwords?

Categories: Java

Using Enums in Java [Snippets]

Javalobby Syndicated Feed - Wed, 07-Mar-18 10:01

In this article, we provide several examples of the usage of Enums in Java.

Enum Overview

Enum is a Java type/class that holds a fixed set of related constants. It is a replacement for the traditional definition of multiple static final variables in Java. It is mostly recommended when you define a method that accepts a constant argument. This way you force the method callers to commit to the predefined constants and prevent them from passing random constant values.

Categories: Java

Population Count in Java

Javalobby Syndicated Feed - Wed, 07-Mar-18 04:01

How do you count the bits in a 32-bit integer? Since this is possible in a single instruction, popcntd, which is exposed in Java and several other languages, this is a completely academic question. Nevertheless, however futile, deriving an efficient expression is instructive.

A naive approach would be to check each of the 32 bits in sequence. This can be written in Java as follows:

Categories: Java

Java 10's JEP 286: Local-Variable Type Inference

Javalobby Syndicated Feed - Wed, 07-Mar-18 01:01

Editor's note: The code snippets in this article have been updated.

Java 10 is around the corner, with the RC Build available here. The features targetted for this release can be found here. Of all the JEPs targeted for Java 10, the one that is the most interesting and talked about by the developer community is 286: Local-Variable Type Inference.

Categories: Java

Thread Slivers eBook at Amazon

Syndicate content