Java Lobby Announcements

Subscribe to Java Lobby Announcements feed
Recent posts in Java on
Updated: 2 hours 10 min ago

Spring Cloud Data Flow 1.0.0 M3 Released

2 hours 39 min ago

On behalf of the team, I am pleased to announce the 1.0.0.M3 release of  Spring Cloud Data Flow.

Over the last few months, we have added exciting new features and improvements to the overall orchestration of data microservices on a variety of platforms. We have also made some changes that significantly benefit developers, such as exposing Spring Boot Starters for all of the stream and task applications we publish. Following are some of the highlights from this release:

Categories: Java

Why I Chose Scala Over Java

8 hours 9 min ago

About 2.5 years ago, I made the switch from being a Java EE developer to being a Scala developer. I had worked with many Java EE codes bases from JBoss and Orion “EARs” to many Spring-based Tomcat "WARs" with Hibernate fronting the RDBMS of choice. 

I recently watched a “comment tennis match” between 2 people here on DZone where each was entrenched in their view of the Scala versus Java debate. I very intentionally stayed out of the conversation since it was clear each of them was set in their opinions. That, however, sparked a thought that I should give my reasons to make the switch since I recently did the “cross-over” to Scala after many years on the Java EE side. 

Categories: Java

Java Quiz: Static Members in Java

9 hours 24 min ago
Last Week's Answer

The correct answer is the code writes "[d, a, b, e]" to the standard output.

This Week's QuizPurpose
  1. To demonstrate some behaviors and tricks of static members in Java

Categories: Java

Java 8: Lambda Functions—Usage and Examples

Wed, 2016-05-04 15:16

One of the major new language features in Java 8 is the lambda function. In fact, it is one of the biggest changes since the Java 1 release. Lambdas are widely used in the programming language world, including the languages that compile to the Java platform. For instance, Groovy compiles to the Java platform and has very good support for lambda functions (also known as closures). Oracle decided to bring lambdas to the mainstream language on the JVM—the Java language itself—with Java 8.

Lambda Function Related Changes in Java 8

The introduction of lambdas required coordinated changes in the language, library, and the VM implementation:

Categories: Java

A Warning About Overloading Methods in Java

Wed, 2016-05-04 14:31

Before Java 1.5, primitive types were completely different from reference types. The introduction of the autoboxing feature has made this difference dissapear after Java 1.5. But, it has brought many problems, also.

import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.TreeSet; public class SetAndList{ public static void main(String[] args) { Set<Integer> set = new TreeSet<Integer>(); List<Integer> list = new ArrayList<Integer>(); for (int i = -2; i < 3; i++) { set.add(i); list.add(i); } for (int i = 0; i < 3; i++) { set.remove(i); list.remove(i); } System.out.println(set + " " + list); } }

Many of us might think that the output of the above code would print:

Categories: Java

Understanding the Java Garbage Collection Log

Wed, 2016-05-04 12:31

To diagnose any memory problems, the Garbage Collection log file is the best place to start. It provides several interesting statistics:

  • When the scavenge (or Young generation) GC process ran?
  • When the full GC process ran?
  • How many scavenge GCs and Full GCs ran? Did they run repeatedly? In what interval?
  • After the GC process ran, how much memory was reclaimed in Young, Old, and Permanent generations?
  • How long did the GC run?
  • What was the total allocated memory in each generation?
How to Generate GC Log File?

In order to understand GC log, you first need to generate one. Passing the below-mentioned system properties to your JVM would generate GC logs.

Categories: Java

Simple Everyday Tips for Vaadin Developers (Part 5: Data Grid)

Wed, 2016-05-04 09:01

This is the final part of a five parts series about tips for Vaadin developers. Here are all the series parts:

  1. Migrating From Vaadin 6 to Vaadin 7
  2. UI abstraction and using Vaadin CDI Add-on
  3. Styling Vaadin components and using Add-ons
  4. Data modeling in Vaadin
  5. Simple use case for Vaadin Grid
5. Simple Use Case for Vaadin Grid

So far the checkout button doesn’t do anything. We can toggle the availability of the button depending on items placed in the shopping cart. If it’s empty or cleared then it should be disabled; otherwise it should be enabled. I also designed a simple window that displays the final receipt when clicking on this button.

Categories: Java

Anemic vs. Rich Domain Objects—Finding the Balance

Tue, 2016-05-03 15:16
What prompted another article on this topic?

I just read an old article which, in an attempt to avoid Anemic Objects, the author was showing how to make it possible for a User Entity (Domain Object) to inject a DAO so that the User object can become a Rich Domain Object. I have read similar articles, some pro-Anemic Domain Model, and others pro-Rich Domain Object—the problem is that these are normally on the extreme of the two sides.

Rich Domain Object Extreme

The domain object does everything on its own in hosting JVM memory state, and also the external state of the object, that being database state, local filesystem state, etc.

Categories: Java

Using Dependency Injection with Java EE

Tue, 2016-05-03 14:31

Before Java EE 6, components could be injected in the following ways:

  • Through the @EJB annotation, where your class needs to be an EJB or Servlet.

Categories: Java

Custom SecurityContext in&nbsp;JAX-RS

Tue, 2016-05-03 12:31

And the JAX-RS juggernaut continues ….

This article briefly talks about how to override the default security-related information associated with a JAX-RS request (i.e., how to mess with the SecurityContext).

Categories: Java

Simple Everyday Tips for Vaadin Developers (Part 4: Data Modeling)

Tue, 2016-05-03 09:01

This is the fourth part of a five parts series about tips for Vaadin developers. Here are all the series parts:

  1. Migrating From Vaadin 6 to Vaadin 7
  2. UI abstraction and using Vaadin CDI Add-on
  3. Styling Vaadin components and using Add-ons
  4. Data modeling in Vaadin
  5. Simple use case for Vaadin Grid
4. Data Modeling in Vaadin

Categories: Java

What's in a Clojure Namespace?

Mon, 2016-05-02 12:59

Every well-behaved clojure source file starts with a namespace declaration. The ns macro, as we all know, is responsible for declaring the namespace to which the definitions in the rest of the file belong, and generally also includes some requirements and imports and whatnot. But today (at Clojure/West, shoutout!) Stuart Sierra made a passing reference to the internals of nsduring his talk that got me interested.

But what is a namespace really?

Categories: Java

Solid: Liskov Substitution Principle

Mon, 2016-05-02 11:55

This is the third in the series of posts on SOLID Software Principles. We previously covered the Single Responsibility Principle and the Open-Close Principle. In this post, I will take you through the L in SOLID, the Liskov Substitution Principle.

The primary idea behind the Open-Closed principle is achieved using inheritance i.e. introduce new classes for new functionality and keep the classes related to existing functionality untouched. But what differentiates a good inheritance structure from a bad one? That is where the Liskov Substitution Principle comes into play.

Categories: Java

Most Popular Java EE Servers: 2016 Edition

Mon, 2016-05-02 10:51

This is now fourth year when we publish statistics about the Java landscape. Every year, during springtime, we dig into the data that we have gathered from the JVMs Plumbr Agents have monitored, and find out about:

  • which Java versions are used (Java 6 vs Java 7 vs Java 8);
  • which JVMs are used (Oracle Hotspot vs OpenJDK vs Rest Of The World);
  • Which application servers are most frequently deployed in the infrastructure;
  • how the landscape has changed over time.

Last week we exposed the data about Java versions and vendors. This week we are exposing the state in the application server market.

Categories: Java

Spring Annotation Processing: How It Works

Mon, 2016-05-02 08:48

One of the things I emphasize when I teach Java classes is the fact that annotations are inert. In other words, they are just markers, potentially with some properties, but with no behavior of their own. So whenever you see an annotation on a piece of Java code, it means that there must be some other Java code somewhere that looks for that annotation and contains the real intelligence to do something useful with it.

Unfortunately, the issue with this line of reasoning is that it can be pretty difficult to identify exactly which piece of code is processing the annotation, particularly if it is inside a library. And code that processes annotations can be confusing, as it uses reflection and has to be written in a very generic way. So I thought it would be worthwhile to look at an example that's done well to see how it works.

Categories: Java

Random Ideas About Code Style

Sun, 2016-05-01 11:03

Some of the sentences of this article are ironic. Others are to be taken serious. It is up to the reader to separate them. Start with these sentences.

How long should a method be in Java?

Categories: Java

Would We Still Criticize Checked Exceptions, If Java Had a Better Try-Catch Syntax?

Sun, 2016-05-01 09:01

In the context of a previous blog post about JUnit 5, Maaartinus, one of our readers, has brought up a very interesting idea:

The only problem with try-catch is its verbosity, which is something I can live with (IMHO a lone catch would do better, the implicit try would apply to all preceding code in the block; just syntactic sugar)

Categories: Java

Java Annotations Are a Big Mistake

Sun, 2016-05-01 08:01

Annotations were introduced in Java 6 in 2006, and we all got excited. Such a great instrument to make code shorter! No more Hibernate/Spring XML configuration files! Just annotations, right there in the code where we need them. No more marker interfaces, just a runtime-retained reflection-discoverable annotation! I was excited too. Moreover, I've made a few open source libraries which use annotations heavily. Take jcabi-aspects, for example. However, I'm not excited any more. Moreover, I believe that annotations are a big mistake in Java design.

Long story short, there is one big problem with annotations — they encourage us to implement object functionality outside of an object, which is against the very principle of encapsulation. The object is not solid any more, since its behavior is not defined entirely by its own methods — some of its functionality stays elsewhere. Why is it bad? Let's see in a few examples.

Categories: Java

Closure-Based State Explained

Sat, 2016-04-30 12:12

We want to preserve “information hiding” and avoid exposing details of how and where internal state is being held.


Reflection libraries can bypass “private” and other access controls. This is a good thing in a number of ways, but Reflection libraries also offer opportunities to completely undo the benefit of access controls.

Categories: Java

Simple Everyday Tips for Vaadin Developers — Part 3: Styling Components

Sat, 2016-04-30 12:10

This is the third part of a five parts series about tips for Vaadin developers. Here are all the series parts:

  1. Migrating From Vaadin 6 to Vaadin 7
  2. UI abstraction and using Vaadin CDI Add-on
  3. Styling Vaadin components and using Add-ons
  4. Data modeling in Vaadin
  5. Simple use case for Vaadin Grid
3. Styling Vaadin Components and Using Add-Ons

Vaadin has a good set of styles that help boosting the UX with few lines of code, this includes the built in Saas based Valo theme engine, icons, and styles. Since I want to avoid any non-java code, let’s explore how we can style some components without any line of CSS.

Categories: Java