Subscribe: Javalobby - The heart of the Java developer community
Added By: Feedage Forager Feedage Grade B rated
Language: English
code  homeservices null  homeservices  java  language  maven  methods  new  null  programming  project  public  service  spring  static  string  web 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Javalobby - The heart of the Java developer community

DZone Java Zone

Recent posts in Java on


A Curious Java Language Feature and How it Produced a Subtle Bug

Sat, 22 Jul 2017 04:01:00 GMT

Java’s visibility rules are tricky at times. Do you know what this will print?

package p;
import static p.A.x;
class A {
    static String x = "A.x";
class B {
    String x = "B.x";
class C {
    String x = "C.x";
    class D extends B {
        void m() {
public class X {
    public static void main(String[] args) {
        new C().new D().m();

Java 9: A Look at Milling Project Coin

Fri, 21 Jul 2017 20:01:01 GMT

In this section, we are going to discuss the new Java 9 enhancements as part of JEP 213: Milling Project Coin. The purpose of JEP 213 is to address some rough edges. Milling Project Coin has five small amendments to the Java programming language.

1. Underscore as an Identifier Name

In Java 8, an underscore ( _ ) is allowed as an identifier name, but the compiler will show a warning that "It will not be supported after Java SE 8." So Java 9 completed the removal of underscore from the set of legal identifier names.

Tools to Power Every Phase of Java Development (Part 1)

Fri, 21 Jul 2017 16:01:00 GMT

Many know Java as one of the simplest, but most powerful (not to mention sought-after) programming languages used by web developers. But there are others who see it in the opposite light, saying that Java is a hard and more complex programming language.

In order to execute your Java coding more effectively, there are a handful of Java tools that web developers can use in different phases of programming/development. Below, we’ve listed 63 of them – the essential tools that every web developer needs in their Java toolkit. They’re listed below in no particular order, but we have categorized them to make it easy for you to find the type of Java tool you’re looking for. 

Sorting Lists in Java

Fri, 21 Jul 2017 10:01:01 GMT

Sorting a list is a very common requirement when programming in Java. Out of the box, Java provides for sorting using a performant algorithm, so there is no need to roll your own algo for the purpose. In this article, we demonstrate how to sort a list in Java.

Sort a List of Strings

The List interface provides a default implementation of a sort() method, which can be used to sort objects by their natural ordering (for a String, this refers to alphabetical ordering). This code is as simple as it gets for ordering a list.

Don’t Overdo the ''Principle of Least Astonishment'' Cargo Cult

Fri, 21 Jul 2017 07:01:00 GMT

As we all agree, GOTO is evil, right? Relevant XKCD.

Or even funnier: New Intern Knows Best.

Java Singletons Using Enum

Fri, 21 Jul 2017 04:01:00 GMT

A singleton is a class that is supposed to have only one instance per JVM. The Same instance of the singleton class is reused by multiple threads. Most often, we use singletons to represent system configurations and window managers, since those instances should be common to all threads and objects within a JVM.

Traditional Methods of Making Singletons

There are several popular methods for making singletons.

Java 9: Streams Improvements

Thu, 20 Jul 2017 20:01:00 GMT

Java 9 has updated the Streams API and a few other features in addition to the Jigsaw modularity project (also known as The Big One). Let's go over some of the changes developers can expect when working with Streams.


Java 8 introduced Streams, which help developers perform aggregate operations from a sequence of objects. Meanwhile, Java 9 introduced a few more utility methods to make developers' work even easier.

Spring @Transactional and Private Methods [Snippets]

Thu, 20 Jul 2017 16:01:00 GMT

As most of you probably know, due to the very nature of the solution, Spring's @Transactional annotation does not work on private methods unless you're using the AspectJ mode (which, in my experience, most of us aren't). In such a case, the only solution to the problem is to access the transactional method through an auto-wired bean, either via self-injection or delegation.

The problem that I have with the first approach is that it screams, "I AM A HACK!" And I obviously don't like when my code screams that. The problem that I have with the second one is not the mere fact of letting another object do the work, but the way we achieve that, i.e. by creating these strange beans with arbitrary names just to get it working.

Immutable Collections in Java 9

Thu, 20 Jul 2017 14:15:29 GMT

The arrival of Java 9 brings many new features to Java’s Collections API, one of which being collection factory methods, which add syntactic sugar for creating small, unmodifiable Collection instances using new convenience factory methods as per JEP 269.

In this article, we will discuss their usage and implementation details.

NPE-Free Code Without Null Checks

Thu, 20 Jul 2017 10:01:01 GMT

Is this how your Java code review starts? NPE is always a nightmare for a Java developer. Let's jump to an unusual code snippet:

public interface Service {  
    public boolean switchOn(int timmer);
    public boolean switchOff(int timmer);
    //Other controls 
public class RefrigeratorService implements Service {
// ...
public class HomeServices {
    private static final int NOW = 0;
    private static HomeServices service;

    public static HomeServices get() {
        //Null Check #1
        if(service == null) {
            service = new HomeServices();
        return service;

    public Service getRefrigertorControl() {
        return new RefrigeratorService();

    public static void main(String[] args) {
        /* Get Home Services handle */
        HomeServices homeServices = HomeServices.get();
        //Null Check #2
        if(homeServices != null) {
            Service refrigertorControl = homeServices.getRefrigertorControl();
            //Null Check #3
            if (refrigertorControl != null) {

Cloud Foundry Application Manifest Using a Kotlin DSL

Thu, 20 Jul 2017 07:01:01 GMT

I had a blast working with and getting my head around the excellent support for creating DSLs in Kotlin Language. This feature is now being used for creating Gradle build files, for defining routes in Spring Webflux, and for creating HTML templates using kotlinx.html library.

Here, I am going to demonstrate how to create a Kotlin based DSL to represent a Cloud Foundry Application Manifest content.

Develop and Deploy Microservices With JHipster

Thu, 20 Jul 2017 04:01:00 GMT

JHipster is one of those open-source projects you stumble upon and immediately think, "Of course!" It combines three very successful frameworks in web development: Bootstrap, Angular, and Spring Boot. Bootstrap was one of the first dominant web-component frameworks. Its largest appeal was that it only required a bit of HTML and it worked! Bootstrap showed many in the Java community how to develop components for the web. It leveled the playing field in HTML/CSS development, much like Apple’s Human Interface Guidelines did for iOS apps.

At its core, JHipster is a Yeoman generator. Yeoman is a code generator that you run with a yo command to generate complete applications or useful pieces of an application. Yeoman generators promote what the Yeoman team calls the "Yeoman workflow" This is an opinionated client-side stack of tools that can help developers quickly build beautiful web applications. It takes care of providing everything needed to get working without the normal pains associated with a manual setup.

Extending Spock: Outputting the Given/When/Then

Wed, 19 Jul 2017 20:01:00 GMT

Spock is a Java testing framework created in 2008 by Peter Niederwieser, a software engineer with GradleWare, which facilitates, amongst other things, BDD. Leveraging this example, a story may be defined as:

Story: Returns go to stock

As a store owner
In order to keep track of stock
I want to add items back to stock when they're returned.

Scenario 1: Refunded items should be returned to stock
Given that a customer previously bought a black sweater from me
And I have three black sweaters in stock.
When he returns the black sweater for a refund
Then I should have four black sweaters in stock.

Scenario 2: Replaced items should be returned to stock
Given that a customer previously bought a blue garment from me
And I have two blue garments in stock
And three black garments in stock.
When he returns the blue garment for a replacement in black
Then I should have three blue garments in stock
And three black garments in stock.

This Week in Spring: Spring 5, Trampoline, and JDK 9 Collections

Wed, 19 Jul 2017 16:01:00 GMT

Hi Spring fans! This week I’m in Crete, Greece, for the epic JCrete un-conference. and then it’s off to Istanbul, Turkey, for next week’s visits with customers and for the Spring meetup. I hope you’ll join me in Istanbul!

As usual, we’ve got a lot to cover so let’s get to it!

Specifying and Handling Exceptions

Wed, 19 Jul 2017 07:01:00 GMT

Errors happen all the time in the software world. It might be an invalid user input or an external system that is not responding, or it’s a simple programming error. In all these situations, the errors occur at runtime and the application needs to handle them. Otherwise, it crashes and can’t process further requests. Java provides a powerful mechanism which allows you to handle the exceptional event where it occurred or in one of the higher methods in the call stack. Before we get into the details of Java’s exception handling, we need to define a few terms.

Java Exception Handling: Common Terminology

Call Stack

The call stack is the ordered list of methods that had been called to get to a specific method. In the context of this post, these are the methods which were called to get to the method in which the error occurred.

Defining Bean Dependencies With Java Config in Spring Framework

Wed, 19 Jul 2017 04:01:00 GMT

I found it hard to choose a topic to describe in my first blog post. I wanted it not to be too trivial, nor too complicated It turned out that there are many basic concepts in Spring Framework that can be confusing. Java-based configuration is one of them. I hear my colleagues asking from time to time about it, and I see numerous questions regarding it on StackOverflow. Nevermind the motivation, below you will find a compact description of how to declare beans with Java Config.

Please note that this post won't cover bean dependencies of different scopes nor discussion on annotations like @Component@Service@Repository, etc., that are often a good alternative to the described approach. Java Config might seem to be overkill in many situations, but I hope you will find the post useful anyway. Let's go!

4 Techniques for Writing Better Java

Tue, 18 Jul 2017 21:23:59 GMT

Day-in and day-out, most of the Java we write uses a small fraction of the capability of the language's full suite of possibilities. Each Stream we instantiate and each @Autowired annotation we prefix to our instance variables suffice to accomplish most of our goals. There are times, however, when we must resort to those sparingly used portions of the language: The hidden parts of the language that serves a specific purpose.

This article explores four techniques that can be used when caught in a bind and be introduced into a code-base to improve both the ease of development and readability. Not all of these techniques will be applicable in every situation, or even most. For example, there may be only a few methods that will lend themselves to covariant return types or only a few generic classes that fit the pattern for using intersectional generic types, while others, such as final methods and classes and try-with-resources blocks, will improve the readability and clearness of intention of most code-bases. In either case, it is important to not only know that these techniques exist, but know when to judiciously apply them.

Java 9 Modular Development (Part 2)

Tue, 18 Jul 2017 20:01:00 GMT

In my previous post, we discussed modularity, module descriptors, and the details about files. This article will help in developing a modular project step by step and packaging them as JARs and JMODs and also describes the steps needed to create runtime images by using jlink.

We will be developing a small modular project that will print, "Hello Welcome to Java 9 Modularity" in the console.

The Maven Way to Add Non-Maven JARs to a Maven Project [Snippets]

Tue, 18 Jul 2017 16:01:01 GMT

Have you ever asked, "How do I add custom (non-maven) JARs as dependencies to maven projects, in a maven way?"

Answer: Easy. Use the maven-install-plugin maven plugin,

Akka Concepts: Testing Actors

Tue, 18 Jul 2017 10:01:01 GMT

With Akka, remember that actors interact only via message passing. In order to check actors' behaviors, you can do it through the messages sent and received to and from them. So, how do you test actors? You send them messages.

To test actors that communicate only with messages, you need to send it a message, get a reply back, and check it.