Feed aggregator

Introducing the Maven git commit id Plugin

Javalobby Syndicated Feed - Fri, 23-Feb-18 07:02

Have you ever had the problem of not knowing which version of your application was deployed on, for example, a test environment? Or have you had to manually adapt version information for each release in order to make it available in an About-dialog? Then the Maven git commit id plugin has come to the rescue! In this post, we will build a Spring Boot application with a RESTful web service for retrieving versioning information. The only thing we will have to do is to configure the Maven git commit id plugin and create the web service. After this, versioning information is automatically updated during each build!

Create a Spring Boot Application

First, we create a basic Spring Boot application with a RESTful web service for retrieving manually entered version information. JDK9 and modules are used, so we will encounter some 'problems' along the way. But these will be tackled also!

Categories: Java

Understanding Java Logging Hell: The Basics [Video]

Javalobby Syndicated Feed - Fri, 23-Feb-18 04:01

When it comes down to logging in Java land, there's a ton of different logging libraries available: Log4j V1, Log4j V2, Commons Logging, Java Util Logging, Logback, Slf4j, and many more.

This episode will give you a quick intro on how to get started with logging in the Java world and what happens if you combine all of them in a single project and will also introduce the "Simple Logging Facade" for Java, SLF4j.

Categories: Java

Java Code Style: Operators and New Lines [Snippet]

Javalobby Syndicated Feed - Fri, 23-Feb-18 01:01

Last week, I discovered what helped me decide on what I have struggled with for a long time: whether to place operators such as &&||, or + on the same or next line.

When constructing boolean expressions or concatenating Strings, we might need to break long lines. According to the Google Java Style Guide, the break should come “before the symbol”, therefore:

Categories: Java

JDK 10: FutureTask Gets a toString()

Javalobby Syndicated Feed - Fri, 23-Feb-18 01:01

I've felt for a long time that, for most Java classes that have distinguishing attributes, developers should take the time to override Object.toString(), even if it's just with an IDE-generated implementation or using a library class such as Apache Commons Lang's ToStringBuilder. The overloaded Objects.toString() methods also make this easier than ever if one wants to implement toString by hand. The JDK class FutureTask, introduced with J2SE 5, finally gets its own toString() implementation in JDK 10.

Richard Nichols's 2012 post "How to get the running tasks for a Java Executor..." highlights the omission of a toString() method on the FutureTask class. He wrote:

Categories: Java

Agile, oven-fresh documentation. Part 1: JBake

codecentric Blog - Fri, 23-Feb-18 01:00

In software development, one question that constantly arises is how the current project can be comprehensively documented. The most common way to do this is to use Confluence or some other wiki. But why not use the code itself?
This is why, in the first part of this article series, I will give you an understanding of JBake.
JBake is actually a generator for static websites. Dan Allen, Project Lead of the Asciidoctor project, calls it “Jekyll of the JVM”. Using plugins for Maven and Gradle, JBake can easily be integrated into build pipelines.
I will start off by explaining potential use cases of JBake based on an example. First and foremost, we will build a simple Gradle project to provide a starting point for further steps.

group 'de.codecentric.dk.afgd'
version '1.0-SNAPSHOT'

apply plugin: 'groovy'
apply plugin: 'java'

sourceCompatibility = 1.8

repositories { 

dependencies {
   compile 'org.codehaus.groovy:groovy-all:2.3.11'
   testCompile group: 'junit', name: 'junit',version: '4.12'

Now we extend the build file by the plugin jbake-gradle-plugin.

plugins {
     id 'org.jbake.site' version '1.0.0'

This gives us another “bake” task that allows us to “bake” the documentation. For this, we also need a JBake basic installation within the sources. Under MacOS, this can be easily done with SDKMAN

$ sdk install jbake

or Homebrew

$ brew install jbake

By default, the Gradle plugin expects the documentation sources to be located in src/jbake. By using parameters in the build file, the source and destination can be adjusted. The target, however, is always located in the build folder. For our example, we use the following values:

jbake {
     srcDirName = 'src/documentation'
     destDirName = 'documentation'

Since JBake is now installed, we can run the command

jbake -i

in the folder


The resulting structure can now be extended and adapted as desired. Content can be saved in the content folder in the form of HTML, Asciidoctor, or Markdown files. For this blog article, we will replace the existing file about.html with about.adoc and adjust the content accordingly.

= Project documentation
Daniel Kocot
:jbake-type: page
:jbake-tags: documentation, manual
:jbake-status: published

Within the Asciidoctor document, it is possible to save JBake metadata such as page type, tags, and the status of each page. The latter controls the visibility of the pages after the “baking process”. If you do not like the standard template, you can customize it according to your own preferences using the template languages Freemaker, Groovy Simple, Groovy Markup, Thymeleaf, and Jade.
Now, looking back at the build process, we can connect the build task with the bake task to complete this first part.

build.dependsOn bake

If we now execute the build task, the documentation will be generated as well. In the second part, we will add more ingredients to our agile, freshly baked documentation.

Check out the demo in my Git Repository: agile-fresh-baked-docs.

The post Agile, oven-fresh documentation. Part 1: JBake appeared first on codecentric AG Blog.

Categories: Agile, Java, TDD & BDD

Reproducible Builds in Java

Javalobby Syndicated Feed - Thu, 22-Feb-18 22:01

When it comes to software, we look at source code to learn what an application will do when executed. However, the source code we read is not what will actually be executed by our computers. In the Java world, it is the Java bytecode that is produced by our compilers that eventually gets executed, normally after having been packaged into an archive. So when we are given code that has already been compiled and packaged, how can we verify that it is indeed the product of the source code we think produced it?

The answer to this is reproducible builds! A reproducible build is a deterministic function that, given our source code as input, will produce an executable artifact that is the same, byte for byte, every time it is run on the same input.

Categories: Java

Selenium With Java: Google Search

Javalobby Syndicated Feed - Thu, 22-Feb-18 14:01

In this tutorial, we will be exploring the basics of how to use Selenium with Java. We will use Selenium to open Google, search, and click a URL.

The code is available on GitHub.

Categories: Java

The State of Java in 2018: Faster Updates and New Features

Javalobby Syndicated Feed - Thu, 22-Feb-18 10:01

<!-- Google Tag Manager (noscript) --> <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-PDSRGWC" height="0" width="0" style="display:none;visibility:hidden"></iframe>

2017 was a turbulent year in the Java world. The long-awaited release of Java 9 brought a lot of changes and interesting new features, and Oracle announced a new release schedule for the JDK.

Categories: Java

Rust for Java Devs – Creating Functions

Javalobby Syndicated Feed - Thu, 22-Feb-18 07:02

In this post of Rust for Java Devs, we will look at creating functions in Rust. Functions in Rust do not differ that much from Java methods, but there are a few little differences. There is also the topic of Rust’s lifetimes compared to Java’s garbage collection that one could argue separates the two from each other a bit more, but for this post, I will focus on the structure of writing a function in Rust. Due to the similarities between the two, I believe most Java developers will have no problem in figuring out what arguments a Rust function takes, what it outputs, and where the output is returned from.

Let's start with a simple method in Java to get us warmed up.

Categories: Java

JDK 10: Accessing a Java App's Process ID From Java

Javalobby Syndicated Feed - Thu, 22-Feb-18 04:01

A popular question on StackOverflow.com is, "How can a Java program get its own process ID?" There are several answers associated with that question that include parsing the String returned by ManagementFactory.getRuntimeMXBean().getName() [but that can provide an "arbitrary string"], using ProcessHandle.getPid() [JEP 102], using Java Native Access (JNA), using System Information Gatherer And Reporter (SIGAR), using JavaSysMon, using Java Native Runtime — POSIX, parsing the results of jps (or jcmd) via invocation of Runtime.getRuntime().exec(String), and other approaches. JDK 10 introduces perhaps the easiest approach of all for obtaining a JVM process's PID via a new method on the RuntimeMXBean.

JDK-8189091 ("MBean access to the PID") introduces the RuntimeMXBean method getPid() as a default interface method with JDK 10. That issue states the "Problem" as: "The platform MBean does not provide any API to get the process ID of a running JVM. Some JMX tools rely on the hotspot implementation of RuntimeMXBean::getName which returns < pid >@< hostname >." The issue also provides the "Solution": "Introduced new API java.lang.management.RuntimeMXBean.getPid, so that JMX tools can directly get process ID instead of relying on the implementation detail, RuntimeMXBean#getName().split("@")[0]."

Categories: Java

5 Things You Need to Know About Java 9

Javalobby Syndicated Feed - Thu, 22-Feb-18 01:01

In the month of September 2017, Java announced the latest version of Java. It was released after more than 3 years after the release of Java 8, putting a major Java finally in the hands of developers.

Java 9 is a turning point in the release cycle for Java. Here in this post, we will discuss new developer features in Java 9. From an operational point of view, there are changes and enhancements to performance and security. Here,after developing with Java 9 for months at ValueCoders we will talk about five of the most exciting features in Java 9 to encourage you in adopting it.

Categories: Java

Yet 4 More Techniques for Writing Better Java

Javalobby Syndicated Feed - Wed, 21-Feb-18 22:01

Programming skills are like many other skills in life and require constant improvement: If we are not going forward, we are going backward. Standing still is not an option. In this third installation of the 4 Techniques for Writing Better Java series, we cover four important topics: (1) Validating arguments using methods provided by the standard Java library, (2) understanding the important Object class, (3) experimenting and learning by playing with jshell, and (4) finding and reading the most well-written code we can, in both books and in the source code of Java itself.

Some of these techniques are purely programming techniques that can help in a specific pinch while others focus on the tools and environment surrounding the Java ecosystem. Regardless of the individual nature of each technique, when applied with diligence and sound judgment, each can help improve the Java code written by developers, both novice and expert.

Categories: Java

This Week in Spring: Spring Framework Updates and Dockerizing

Javalobby Syndicated Feed - Wed, 21-Feb-18 10:01

Hi, Spring fans! Welcome to another installment of This Week in Spring! This week, I’m speaking at the San Diego JUG with Mario Gray on testing with Spring. Then, I’m off to the IBM Index conference here in San Francisco where I’ll be talking about building reactive microservices, and then it’s off to Devnexus in Atlanta, GA, where I’ll be talking about Kotlin and testing. I hope you’ll join me and say hi if you’re nearby.

Categories: Java

What Can Reactive Streams Offer EE4J?

Javalobby Syndicated Feed - Wed, 21-Feb-18 07:01

In my current role at Lightbend, I’m investigating and pursuing opportunities where Reactive Streams can make the lives of EE4J (the new Java EE) developers better. In this blog post, I’m going to share some of the ideas that we’ve had for Reactive Streams in EE4J, and how these ideas will benefit developers.

Reactive Streams was adopted by the JDK in the form of the java.util.concurrent.Flow API. It allows two different libraries that support asynchronous streaming to connect to each other, with well-specified semantics about how each should behave, so that backpressure, completion, cancellation and error handling is predictably propagated between the two libraries. There is a rich ecosystem of open source libraries that support Reactive Streams, and since its inclusion in JDK9, there are a few in development implementations that are targetting the JDK, including the incubating JDK9 HTTP Client, and the Asynchronous Database Adapter (ADBA) effort that have also adopted it.

Categories: Java

JDK 10's Summary Javadoc Tag

Javalobby Syndicated Feed - Wed, 21-Feb-18 04:01

JDK 10 introduces a Javadoc tag {@summary} via issue JDK-8173425 ("Javadoc needs a new tag to specify the summary."). This new tag allows the developer to explicitly specify what portion of the Javadoc comment appears in the "summary" rather than relying on Javadoc's default treatment looking for a period and space to demarcate the end of the summary portion of the comment. JDK-8173425 states, "Currently in javadoc the summary (firstsentence) of an element is deciphered by a dot-space rule, or if required using BreakIterator." It adds that it can be confusing to know what that implicitly selected summary sentence will be.

The easiest way to see {@summary} in action may be through Javadoc examples. The next code listing shows four methods with similar Javadoc comments, two using explicit {@summary} tags and two relying on implicit Javadoc summary construction.

Categories: Java

Spring DI Patterns: The Good, The Bad, and The Ugly

Javalobby Syndicated Feed - Wed, 21-Feb-18 01:01

Spring developers will be familiar with its powerful Dependency Injection API. It allows you to declare @Beans that Spring then instantiates and manages. Any dependencies between these beans are then resolved by Spring and injected automagically.

Three Annotation-Based Injection Patterns

There are three ways Spring lets you declare the dependencies of your class using annotations:

Categories: Java

5 Hidden Secrets in Java

Javalobby Syndicated Feed - Tue, 20-Feb-18 22:01

As programming languages grow, it is inevitable that hidden features begin to appear and constructs that were never intended by the founders begin to creep into common usage. Some of these features rear their head as idioms and become accepted parlance in the language, while others become anti-patterns and are relegated to the dark corners of the language community. In this article, we will take a look at five Java secrets that are often overlooked by the large population of Java developers (some for good reason). With each description, we will look at the use cases and rationale that brought each feature into the existence and look at some examples when it may be appropriate to use these features.

The reader should note that not all these features are not truly hidden in the language, but are often unused in daily programming. While some may be very useful at appropriate times, others are almost always a poor idea and are shown in this article to peek the interest of the reader (and possibly give him or her a good laugh). The reader should use his or her judgment when deciding when to use the features described in this article: Just because it can be done does not mean it should.

Categories: Java

Kotlin’s java.util.Optional API Equivalents

Javalobby Syndicated Feed - Tue, 20-Feb-18 14:01

Kotlin truly shines when it comes to avoiding excessive bureaucracy of classical Type-Driven approaches to optionality.

Let’s see how its native approach to null-safety compares to java.util.Optional.

Categories: Java

Is String#repeat Coming to Java?

Javalobby Syndicated Feed - Tue, 20-Feb-18 10:01

JDK-8197594 ("String#repeat") includes the following it its "Description": "A String method for repeating sequences of characters has been long requested with no follow through." Evidence of this interest in a method on the String class for repeating sequences of characters can be found in JDK-8197594's "Issue Links" that include JDK-8055862 ["Provide a String repeat method"] and JDK-6984084 ["(str) n times repetition of character constructor for java.lang.String"]. Both of these linked issues describe motivations for having such a method in the String class. Further evidence includes online questions such as Simple way to repeat a String in Java, How to repeat string “n” times in Java?, What is the simple way to repeat a string in Java?, and How do you repeat a string n number of times in Java programming?

Guava provides this desired behavior via its Strings.repeat(String, int) method and Apache Commons Lang provides this functionality via its StringUtils.repeat(String, int). It's also likely that this functionality has been implemented hundreds of times or more in individual projects. The availability of a standard java.lang.String.repeat(String, int) method could replace all of these.

Categories: Java

An Intro to Spring 5's Webflux Framework [Video]

Javalobby Syndicated Feed - Tue, 20-Feb-18 04:01

For those who aren't aware, Spring 5 got a new reactive web framework called Spring Webflux. But what is reactive programming? What are non-blocking applications? How can you get started with it?

In this practical screencast, you will learn how to get started with Spring 5 Webflux, which means you'll learn the perfect project setup, what libraries you need, and then get to write a simple REST Controller that serves as a base for more advanced reactive concepts.

Categories: Java

Thread Slivers eBook at Amazon

Syndicate content