Java Lobby Announcements

Subscribe to Java Lobby Announcements feed
Recent posts in Java on
Updated: 5 hours 7 min ago

Generic Programming in Scala With Shapeless

7 hours 6 min ago

In my last post about evolutionary computing, I mentioned I started building the project partly just so I could have a play with Shapeless. Shapeless is a generic programming library for Scala, which is growing in popularity — but can be fairly complicated to get started with.

I had used Shapeless from a distance up until this point,  using libraries like Circe or Spray-Json-Shapeless that use Shapeless under the hood to do stuff like JSON de/serialisation without boilerplate overhead of having to define all the different case classes/sealed traits that we want to serialise.

Categories: Java

Java Command-Line Interfaces (Part 2): args4j

Sat, 2017-06-24 07:01

In my previous post, I looked at parsing command-line arguments in Java applications using Apache Commons CLI. In this post, I look at doing the same using a different library: args4j.

args4j takes a different approach to specifying which command-line arguments the Java application should expect than that used by Commons CLI. While Commons CLI expects objects representing the options to be individually and explicitly instantiated, args4j uses custom annotations to facilitate this "definition" stage of command-line arguments processing. Command-line options are expected to be instance-level fields on the class and are annotated with the @org.kohsuke.args4j.Option annotation. The characteristics of each command-line argument are included as attributes of this @Option annotation.

Categories: Java

Object-Oriented Declarative Input/Output in Cactoos

Fri, 2017-06-23 16:01

Cactoos is a library of object-oriented Java primitives we started to work on just a few weeks ago. The intent was to propose a clean and more declarative alternative to JDK, Guava, Apache Commons, and others. Instead of calling static we want to use , the way they are supposed to be used. Let's see how input/output works in a pure  fashion.

Let's say you want to read a file. This is how you would do it with the static method readAllBytes() from the  Files in JDK7:

Categories: Java

Deploying Certificates to Tomcat With Octopus Deploy

Fri, 2017-06-23 11:01

In a previous post, I showed you how to export a certificate managed by Octopus Deploy into a Java keystore, and then configure WildFly to make use of the keystore to provide HTTPS access to web applications and management ports.

In this post, I am going to show you how to do the same for Tomcat in Windows.

Categories: Java

Lightbend Podcast: Goodbye Activator, Hello Tech Hub, and Meet Lightbend's New Tooling Team

Fri, 2017-06-23 07:01

In a recent blog post, we announced the EOL for Activator and described a new direction for getting started with Lightbend Tech Hub. Including a Rapid Project Starter and a growing list of technical guides, this new, online experience makes it simpler for developers to understand what is possible with our Reactive Platform technologies Akka, Lagom, Play, Scala and Lightbend Enterprise Suite.

In this podcast, we sit down with Eugene Yokota, team lead for Lightbend’s Tooling Team, to discuss the new Tech Hub, the decision to say goodbye to Activator, and the new roadmap for the long-awaited sbt 1.0. 

Categories: Java

IntelliJ IDEA 2017.2 Public Preview

Thu, 2017-06-22 20:01

The last couple of months have been a lot of fun as we’ve been working on IntelliJ IDEA 2017.2, which is due out this summer. We appreciate the contributions from all EAP participants and the feedback they’ve shared on the new features. We reached a feature-freeze two weeks ago, and today, with roughly a month before the release, we’re happy to give you a detailed glimpse of what’s noteworthy in the upcoming IntelliJ IDEA 2017.2.

If you can’t wait, download the public preview build right away and try it on your own. Otherwise, read on and learn about the major changes.

Categories: Java

How to Implement a New Realm in Tomcat

Thu, 2017-06-22 16:01

Tomcat by default ships with a couple of Realm implementations likeJDBCRealm, DataSourceRealm, and JNDIRealm, etc. But sometimes, it is not sufficient for your organization’s requirements and you are required to apply your own implementations.

How to Implement a Custom Realm in Tomcat

You can create your own realm by extending RealmBase class; here, I am going to show an example of implementing a new Realm in Tomcat.

Categories: Java

Using JMS in Spring Boot

Thu, 2017-06-22 13:01

JMS (Java Message Service) is a Java Message Oriented Middleware used to send messages between clients and works by sending messages to a message queue which are then taken when possible to execute a transaction. This post will focus on implementing JMS with Spring Boot, which doesn’t take long at all to setup.

JMS and message queues, in general, bring some certain advantages over using RESTful services such as:

Categories: Java

Java Command-Line Interfaces (Part 1): Apache Commons CLI

Thu, 2017-06-22 11:01

Although I typically use Groovy to write JVM-hosted scripts to be run from the command-line, there are times when I need to parse command-line parameters in Java applications and there are a plethora of libraries available for Java developers to use to parse command-line parameters. In this post, I look at one of the best known of these Java command line parsing libraries: Apache Commons CLI.

I have blogged on Apache Commons CLI before, but that post is over eight years old and describes Apache Commons CLI 1.1. Two classes that I demonstrated in that post, GnuParser and PosixParser, have since been deprecated. The examples in this current post are based on Apache Commons CLI 1.4 and use the newer DefaultParser that was introduced with CLI 1.3 to replace GnuParser and PosixParser.

Categories: Java

Learning Git With GitKraken: How to Squash Commits [Video]

Thu, 2017-06-22 07:01

We created a series of Git tutorial videos that were really well received by developers wanting to learn Git. However, we got a lot of feedback that you (the viewer) wanted to see how those Git concepts could be applied in GitKraken. So, voila! We created the Learning Git with GitKraken video series.

Our latest video in this series is about squashing commits. In 90 seconds, you’ll learn what it means to squash commits, and you’ll see how easy it is to squash commits in GitKraken.

Categories: Java

The ABCs of RegEx

Wed, 2017-06-21 22:01

Teacher: Today we will learn RegEx and how to use it in Java.

Jonny and Alice scream with fear, then say: That's so confusing! It makes our lives miserable!

Categories: Java

This Week in Spring: Spring Framework 5.0 RC2 and Spring Security 5.0

Wed, 2017-06-21 18:01

Hi Spring fans and welcome to another installment of This Week in Spring! This week I’m in Krakow, Poland for the epic Devoxx PL event and then it’s off to Luxembourg for the VoxxedDays Luxembourg event! If you’re around, don’t hesitate to say hi.

Categories: Java

Migrating to Java 9

Wed, 2017-06-21 12:01

Java 9, after many delays and failed votes, looks to be finally arriving this September.

Java 9 will bring several new features: enhancements to Streams, a REPL, improvements to Collections, among others. But by far the biggest and most controversial change is Jigsaw. Jigsaw is introducing modularity to the JDK, a long topic in and of itself, but it is one of the major reasons upgrading to Java 9 will be more difficult than previous major releases of Java.

Categories: Java

Do We Care About Our Privacy?

Wed, 2017-06-21 09:01

We all are using private methods in our classes. There are two different ways to use them - one is good and valid while the second one is a hint that something can be wrong with our design.

First of all, we should consider why we are using these private methods. The main reason is breaking our code on smaller problems. We want to create more readable code - from our complicated method, we can create two smaller and consistent private methods. So instead of doing all the work in one method, we break up our code:

Categories: Java

What Are Kotlin Progressions and Why Should You Care?

Wed, 2017-06-21 06:01
Life Is Great

One of the first things that you notice when you start learning Kotlin is the "nice" for loop syntax that it has:

for (i in 1..5) { // mm, so fancy! println(i) }

Categories: Java

Comparing Unsorted (Unordered) Whitespace in Different XML Files

Tue, 2017-06-20 22:01

Many developers struggle to compare XML files. There are a number of reasons for that, including:

  • Whitespace differences

Categories: Java

A SonarQube Plugin for Kotlin (Part 2): Analyzing With ANTLR

Tue, 2017-06-20 15:35

Last week, we used ANTLR to generate a library to be able to analyze Kotlin code. It’s time to use the generated API to check for specific patterns.

API Overview

Let’s start by having a look at the generated API:

Categories: Java

50 Common Java Errors and How to Avoid Them (Part 2)

Tue, 2017-06-20 15:35

In the last post, we covered 20 common compiler errors and what you could do to avoid them. Now, our focus is shifting to, though not exclusively focusing on, runtime exceptions and what leads to them. Follow along as we talk about 30 common exceptions and errors and where to look in your code to solve them.

21. “ArrayIndexOutOfBoundsException”

This is a runtime error message that occurs when the code attempts to access an array index that is not within the values. The following code would trigger this exception:

Categories: Java

A Look at Spring Boot Admin

Tue, 2017-06-20 15:35

As part of microservices development, many of us are using Spring Boot along with Spring Cloud features. In the microservices world, we will have many Spring Boot applications running on both the same and different hosts. If we add Spring Actuator to the Spring Boot applications, we will get many out-of-the-box endpoints to monitor and interact with Spring Boot applications. The list is given below.

ID Description Sensitive Default actuator Provides a hypermedia-based “discovery page” for the other endpoints. Requires Spring HATEOAS to be on the classpath. true auditevents Exposes audit events information for the current application. true autoconfig Displays an auto-configuration report showing all auto-configuration candidates and the reason why they ‘were’ or ‘were not’ applied. true beans Displays a complete list of all the Spring beans in your application. true configprops Displays a collated list of all @ConfigurationProperties. true dump Performs a thread dump. true env Exposes properties from Spring’s ConfigurableEnvironment. true flyway Shows any Flyway database migrations that have been applied. true health Shows application health information (when the application is secure, a simple ‘status’ when accessed over an unauthenticated connection or full message details when authenticated). false info Displays arbitrary application info. false loggers Shows and modifies the configuration of loggers in the application. true liquibase Shows any Liquibase database migrations that have been applied. true metrics Shows ‘metrics’ information for the current application. true mappings Displays a collated list of all @RequestMapping paths. true shutdown Allows the application to be gracefully shutdown (not enabled by default). true trace Displays trace information (by default the last 100 HTTP requests). true

Categories: Java

All About 'Finals'

Tue, 2017-06-20 15:35
A variable can be declared final. A final variable may only be assigned to once. It is a compile-time error if a final variable is assigned to unless it is definitely unassigned immediately prior to the assignment.

After the assignment of any final variable, it can never be altered. If the variable refers to any instance of any object, it will continue to refer to the same object instance, however, the internal state of the object can be modified.

Effectively Final

A variable can also be considered as effectively final if and only if:

Categories: Java