Feed aggregator

An Intro to Java 8 Default Interfaces

Javalobby Syndicated Feed - Sat, 07-May-16 23:01

In this article we will explore the Java 8 default method’s feature in interfaces. The Java 8 says “Default methods enable new functionality to be added to the interfaces in libraries and ensure binary compatibility with code written for older versions of those interfaces”.

As Java evolved over the years, the interfaces introduced in the Java library require adding new functionality. If you add new methods in the interface without having default methods feature, all the classes that already implemented the interfaces should undergo a change. This results in changing thousands of lines of code. To avoid this, the Java 8 introduced the default method feature. That is, if you want to add any functionality to the existing interface, you can add it by using the default method feature without affecting the implementations.

Categories: Java

A Few Thoughts About Kotlin and Why I Like It So Much

Javalobby Syndicated Feed - Fri, 06-May-16 23:01

It doesn't matter how many languages you have learned, learning yet another one is always a wonderful experience. I have been working for a couple of months with Kotlin. Have got one app to ready for production state and another in the works.

To cut to the chase, I am really impressed by this language. As in really really impressed. And so I decided that I should write a few posts that can help readers get a better idea and learn about this language. So I started writing out the series and am already onto the third post now. But as I was writing it, I realized what I was writing was really about the mechanics of the language. Not so much about its spirit. Because when one gets into the tactical nitty-gritty details, one tends to miss the forest for the trees. So I decided to pen that here before I start that series (next week), and here are my few thoughts about why I really enjoy the language.

Categories: Java

Testing Improvements in Spring Boot 1.4

Javalobby Syndicated Feed - Fri, 06-May-16 21:31

One of the nice things about working for Pivotal is that they have a great agile development division called Pivotal Labs. The teams within Labs are big proponents of Lean and XP software methodologies such as pair programming and test-driven development. Their love of testing has had a particular impact on Spring Boot 1.4 as we’ve started to get great feedback on things that could be improved. This blog post highlights some of the new testing features that have just landed in the latest M2 release.

Testing Without Spring

The easiest way to unit test any Spring @Component is to not involve Spring at all! It’s always best to try and structure your code so that classes can be instantiated and tested directly. Usually that boils down to a few things:

Categories: Java

Iterating Java Map Entries

Javalobby Syndicated Feed - Fri, 06-May-16 05:16
The majority of the time when you’re working with Maps in Java, you’ll be accessing the map values via the key. There are times you need to walk the map like a list. There are a number of ways to do this in Java, and that number has grown over time as the language has evolved.

Let’s take a closer look at walking over Map entries in Java using JUnit. For the series of examples below, I’m going to prepare a map for each test like this:

Map<Integer, String> map;

@Before
public void setup(){
    map = new HashMap<>();
    map.put(1, "Java");
    map.put(2, "Groovy");
    map.put(3, "Scala");
    map.put(4, "Clojure");
    map.put(5, "jRuby");
}

This is a simple HashMap in Java. I’m using generics to say the Map key is an integer, and the Map value is a String. For this example, I’m creating a map with some of the various JVM languages.

Categories: Java

Your First Lagom Service—Getting Started With Java Microservices

Javalobby Syndicated Feed - Fri, 06-May-16 04:31

I've been heads-down in writing my next O'Reilly report and haven't had enough time to blog in a while. Time to catch up here and give you a real quick start into the new microservices framework named Lagom. It is different to what you might know from Java EE or other application frameworks. And this is both a challenge and opportunity for you to learn something new. If you can wait for a couple of more days, register to be notified when my new report will be available and learn everything about the story behind Lagom and how to get started. I will walk you through an example application and introduce the main concepts to you in more detail than I could in a blog post. This post is for the impatient that want to get started today and figure everything out themselves.

Some Background

Microservices are everywhere these days and more and more is unveiled about what it takes to build a complex distributed system with the existing middleware stacks. And there are far better alternatives and concepts to implement an application as a microservices-based architecture. The core concepts of reactive microservices have been introduced by Jonas Bonér in his report Reactive Microservices Architecture which is available for free after registration. Lagom is the implementation of the described concepts. It uses technologies that you might have heard about but probably rarely used before as a Java EE developer: mainly Akka and Play. But for now, let's just forget about them because Lagom provides you with a great abstraction on top and gives you everything you need to get started.

Categories: Java

This Week in Spring - May 3rd, 2016

Javalobby Syndicated Feed - Fri, 06-May-16 02:31

I can’t even believe it’s May already! STOP THE WORLD I WANT OFF! Well, at least the times are exciting! There’s so much cool stuff to look at this week so let’s get to it!

Categories: Java

Mule: Private Flow vs. VM Transport

Javalobby Syndicated Feed - Thu, 05-May-16 23:01

In this post I will show the differences between chaining flows with a VM transport versus using a flow-ref. When I need to divide my Mule flows into re-usable units, I often break them into smaller flows and then chain them together in a main flow.

Flows can be chained together using flow-refs or using VM connectors; most recent examples use the flow-refs. However, flow-refs are a Mule 3 addition; in Mule 2, VM connectors were used to chain flows.

Categories: Java

How to Migrate to Microservices

Javalobby Syndicated Feed - Thu, 05-May-16 21:01

Today, modern enterprise is rushing head first into an always-on, digital-centric, mobile world. Organizations that fail to modify their approach to technology will be left by the wayside as others incorporate highly flexible and scalable architectures that adapt quickly and efficiently to the demands of the modern marketplace.

The rapid rise in popularity of microservices was driven by these market influences. In just a few short years, companies have implemented various configurations of technologies to offer the best user experience. 

Categories: Java

Understanding the Java Garbage Collection Log

Javalobby Syndicated Feed - Thu, 05-May-16 09:14

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 ran?
  • When the full GC 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/Metaspace generations?
  • How long did the GC run?
  • How long did JVM pause when Full GC run?
  • What was the total allocated memory in each generation?
  • How many objects were promoted to old generation?

How to Generate GC Log File?

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

Categories: Java

Do I Need to Know Java to Learn Hadoop?

Javalobby Syndicated Feed - Thu, 05-May-16 05:16

People frequently ask me if it’s necessary to have Java programming skills in order to enter the exciting world of Hadoop. When I begin to explain, I’m often met with a disappointment and a sense of limitation upon learning that Java and Hadoop do, in fact, go hand-in-hand. Let me start by saying that the answer to the question “Do I need to know Java to learn Hadoop?” is not a simple one. But I digress; the future of Hadoop is bright, and going forward, no requirements should be seen as limitations or roadblocks, but rather as ways to increase your expertise and become more seasoned in your work. As you make your way through this, I hope I will be able to clarify your concerns, and help get you on your way to excellence within Hadoop.

To get to the bottom of this question it’s necessary to look into the history of Hadoop. Hadoop is Apache’s open-source platform; built to store and process huge amounts of data (orders of petabytes). The platform happens to be built in Java. (Personally, I see the language choice as merely accidental.) Hadoop was originally created as a subproject of “Nutch" (an open-source search engine). It was later conceptualized and would go on to become Apache’s highest priority project. At the time this was all happening, the Hadoop developer team was more comfortable with Java than any other language.

Categories: Java

Spring Cloud Data Flow 1.0.0 M3 Released

Javalobby Syndicated Feed - Thu, 05-May-16 04:31

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

Javalobby Syndicated Feed - Wed, 04-May-16 23:01

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

Javalobby Syndicated Feed - Wed, 04-May-16 21:46

Last Week's Answer

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

This Week's Quiz

Purpose

  1. To demonstrate some behaviors and tricks of static members in Java

Categories: Java

Java 8: Lambda Functions—Usage and Examples

Javalobby Syndicated Feed - Wed, 04-May-16 05: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

Javalobby Syndicated Feed - Wed, 04-May-16 04: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

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

Javalobby Syndicated Feed - Tue, 03-May-16 23: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

Javalobby Syndicated Feed - Tue, 03-May-16 05: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

Javalobby Syndicated Feed - Tue, 03-May-16 04: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 JAX-RS

Javalobby Syndicated Feed - Tue, 03-May-16 02: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

Thread Slivers eBook at Amazon

Syndicate content