Feed aggregator

This Week in Spring: The Java 9 Edition

Javalobby Syndicated Feed - Fri, 29-Sep-17 09:01

Hi, Spring fans! What a crazy wonderful week it’s been! I’m back in San Francisco talking to customers and local partners about all things Pivotal and, also, just enjoying some fun in the San Francisco Sun while playing with Java 9. There’s so much to like in this new release and so much to look forward to and, of course, Spring Framework 5 is Java 9 ready out of the box.

Categories: Java

Java Forum Nord 2017

Javalobby Syndicated Feed - Fri, 29-Sep-17 03:01

This article is dedicated to Java Forum Nord 2017, a non-commercial Java conference that I visited on 12 September 2017 in Hannover, Germany. The spoken language is German, but most of the presentations are written in English. In this article, I will list the links to the presentations I visited along with a small description.

Modularization: Stefan Tilkov

Presentation: https://speakerdeck.com/stilkov/a-question-of-size-modularization-and-microservices

Categories: Java

My Top Java 9 Features

Javalobby Syndicated Feed - Fri, 29-Sep-17 00:01

I was busy last week and didn't have time to write a post on Java 9, so I decided to do one now. The big story with Java 9 is the Java Platform Modularity System (JPMS) platform. It delayed the release of Java 9, but this was a good thing, as a poor implementation of Jigsaw would set Java back in the long run.

But now Java 9 is released, and this post takes a look at my top Java 9 features, which I will expand on in future posts.

Categories: Java

Lightweight JVM Diagnostics Tools and Containers

Javalobby Syndicated Feed - Thu, 28-Sep-17 21:01

If you’re reading this, I hope you’re curious about your options when it comes to running JVM diagnostic tools on containerized applications. Generally, when it comes to containers, you can either shove all your diagnostic tools into the container image, or you can try running them from the host. This short post tries to explain what works, what doesn’t, and what can be done about it. Although it is focused on JVM tools (and HotSpot specifically), a lot of the same obstacles will apply to other runtimes and languages.

Container Isolation

As a very quick reminder, container isolation on Linux works by using namespaces. Containerized processes are placed in a PID namespace that gives them private process ids that aren’t shared with the host (although they also have process ids on the host); in a mount namespace that gives them their own view of mount points, and hence their own view of the filesystem; in a network namespace that gives them their own network interfaces; and so on. A lot of diagnostic tools aren’t namespace-aware and will happily try to open files on the host using container paths, or try to attach to a process by using the container’s PID namespace, or exhibit any number of other failures.

Categories: Java

Taming the Hybrid Swarm: Initializing a Mixed OS Docker Swarm Cluster Running Windows & Linux Native Containers with Vagrant & Ansible

codecentric Blog - Thu, 28-Sep-17 18:03

We successfully scaled our Windows Docker containers running on one Docker host. But what if we change our focus and see our distributed application as a whole, running on multiple hosts using both Windows and Linux native containers? In this case, a multi-node Docker Orchestration tool like Docker Swarm could be a marvelous option!

Running Spring Boot Apps on Windows – Blog series

Part 1: Running Spring Boot Apps on Windows with Ansible
Part 2: Running Spring Boot Apps on Docker Windows Containers with Ansible: A Complete Guide incl Packer, Vagrant & Powershell
Part 3: Scaling Spring Boot Apps on Docker Windows Containers with Ansible: A Complete Guide incl Spring Cloud Netflix and Docker Compose
Part 4: Taming the Hybrid Swarm: Initializing a Mixed OS Docker Swarm Cluster running Windows & Linux Native Containers with Vagrant & Ansible

Lifting our gaze to the application as a whole

We really went far in terms of using native Docker Windows containers to run our apps inside. We built our own Windows Vagrant boxes with Packer, prepared them to run Docker smoothly and provisioned our Apps – both fully automated with Ansible. We also scaled our Windows Docker containers using Docker Compose and Spring Cloud Netflix, not leaving our fully comprehensible setup and our willingness to have everything as code behind.

But if you look into real world projects, there are no single nodes anymore – running Docker or not. Applications today consist of a whole bunch of machines – and they naturally mix Linux and Windows. These projects need a solution to handle these distributed applications – ideally not doing everything with completely new tools. But how is this possible?

Why Docker Swarm?

This post is all about the “new” Docker Swarm mode, requiring Docker 1.12.0 as a minimum. But why did I choose this path? Today everything seems to point to Kubernetes: biggest media share, most google searches, most blog posts and so on. But there are a few things to consider before going with Kubernetes.

The first point is simple: a consultant´s real world project experience. After having in-depth discussions about it, you maybe shifted your project team to Dockerize all the (legacy) applications and finally brought all these containers into production. You should always remember: This is huge! And at least according to my experience not every team member already realized at that point what changes were applied to the team’s applications in detail, maybe also leaving some people unsure about “all this new stuff”. And now imagine you want to do the next step with Kubernetes. This means many of those “new” Docker concepts are again thrown over the pile – because Kubernetes brings in a whole bunch of new building blocks, leaving no stone unturned… And every blog post about Kubernetes and every colleague I talk with has to admit at some point that the learning curve with Kubernetes is really steep.

Second point: Many people at conferences propagate the following precedence: They tell you about “Docker 101” with the simplest steps with Docker and then go straight ahead to Kubernetes as the “next logical step”. Well guys, there´s something in between! It should be common sense that learning is ideally done step by step. The next step after Docker 101 is Docker Compose, adding a new level of abstraction. Coming from Compose, it is easy to continue with Docker Swarm – because it is built right into every Docker engine and could be used with Compose as well. It´s just called “Docker Stack” then.

Categories: Agile, Java, TDD & BDD

Aggregate Millions of Database Rows in a Spring Controller

Javalobby Syndicated Feed - Thu, 28-Sep-17 13:01

The Spring Framework makes it really easy to quickly set up a RESTful API to a relational database using JPA and Spring Web, as long as the API matches the structure of the database. In many APIs, however, the REST-endpoint doesn't correspond to a particular table but rather an aggregate of the fields. In those cases, you still need to write your own REST Controllers, but if the database has millions of rows, then those aggregates might take some time to compute.

In this article, I will show you how to write a very efficient REST Controller representing a JSON aggregate by using the json-stream plugin in Speedment Enterprise to quickly aggregate large JSON sequences without materializing them on the heap. The demo uses the Enterprise Edition of Speedment, for which you can get a free trial using the Initializer on the Speedment Website.

Categories: Java

Spring Tips: Reactive WebSockets With Spring Framework 5 [Video]

Javalobby Syndicated Feed - Thu, 28-Sep-17 09:01

Hi, Spring fans! In this tip, we’ll look at building a Kotlin-language reactive WebSocket-based application with the new web runtime and framework, Spring WebFlux, in Spring Framework 5. In order to keep things interesting, we also connect our WebSocket-backend to a frontend written using an Angular 4 and TypeScript.

Categories: Java

Java Quiz 1: Overriding Methods

Javalobby Syndicated Feed - Thu, 28-Sep-17 06:01

Welcome back to the second series of Java quizzes by me, Sar Maroof! If you haven't seen my first series of quizzes, take a look here. So, let's take a look at our kick-off quiz for this series.

What happens when you try to compile and run the following program?

Categories: Java

Reactive Programming: Using Async Data Streams to Propagate Change

Javalobby Syndicated Feed - Thu, 28-Sep-17 03:01

The concept of reactive programming is not a new one, but it is gaining in prevalence in the current state of web and application design. Everything follows from a simple principle — the need and ability to incorporate asynchronous data streams into a programming framework. But the implementation of reactive programming, and the deeper principles, can be exceedingly complex — even for experienced developers.

Reactive Programming in Practice

It helps first to understand the value of asynchronous data streams and the results that can be achieved with a reactive programming paradigm. Modern forms and applications, with their highly interactive UIs and real-time feedback, are familiar to technology professionals and end-users alike and provide some powerful demonstrations of the power of reactive programming in propagating change and impacting user experience.

Categories: Java

More Guice Please: Re-Learning Google's DI Library (Part 1)

Javalobby Syndicated Feed - Thu, 28-Sep-17 00:01

Google Guice is used as a lightweight dependency injection framework that further assists developers in modularizing their applications. Google shared this very useful library with the development community in 2010 in between the Java SE 6 and Java SE 7 releases. This library is used in some of Java’s (and now Scala’s) most prominent libraries and platforms, such as the Simian Army platform shared by Netflix.

We will begin our discussion of Google Guice with its Module interface. In the Guice developers’ own words, ‘A Guice-based application is ultimately composed of little more than a set of modules and some bootstrapping code.’ We will not be using this interface directly, but it gives us a very good context from which to start. Instead, we will be extending the abstract class that implements it — intuitively named AbstractModule.

Categories: Java

When anti-patterns become a pattern

codecentric Blog - Wed, 27-Sep-17 21:31

There are plenty of learning resources on software best practices. Sprinkled in between all the well-intended advice are warnings about common pitfalls. We could do with a lot more of these warnings and think about why we keep doing the same things wrong. What makes anti-patterns so irresistible?

Stamping out bad habits

Many famous rockstars are self-taught and often received no formal music training at all. Not so in classical music. Any book that claims you can teach yourself to play the violin or become an operatic soprano without the aid of a tutor sells you a false promise. I must have paid my cello and singing teachers slightly more than I ever spent on university tuition fees (granted, these were only 700 euros a year in the Netherlands at the time). None of all this music teaching has brought me any monetary return on investment, whereas my programming hobby has paid out nicely. Sure, I must have consumed hundreds of books, blog posts and tutorials, and of course I wrote many thousands lines of code on hobby projects. However, all of this was largely unsupervised. I learned the most from working alongside more experienced programmers. These people didn’t only teach me new things, but most importantly they weaned me off some ingrained bad habits.

Education is as much about showing how to do things properly as it is about stamping out the bad habits that come natural but are nevertheless wrong. You really need a teacher to do the latter, especially for any pursuit that is more physical than intellectual, like sports and the arts.
Coding isn’t that much different. Yes, if you’re an experienced Java programmer you can teach yourself Kotlin, no problem. But when it comes to more generic principles you mustn’t assume that just knowing the right ways will always keep you on the straight and narrow.

Bad habits are not a popular subject

Here’s why diet books don’t work: they suggest that all it takes is pointing out what healthy foods you should eat. Yet we all know that staying away from the fattening junk is the really hard part. There’s no shortage of books on healthy coding practices. There’s the clean coder, the pragmatic programmer, the humble programmer. Frankly, I’ve heard quite enough success stories. Give me the book “how to avoid being a dysfunctional pedantic twit” or “We wasted everybody’s time, tens of millions of dollars and still have nothing to show for it”.

Code quality is as much an indicator of underlying personal attitudes and team dynamics as it is of developer proficienty. I believe that both good and bad patterns result from only a small number of positive and negative attitudes and behaviours. These are important markers for the success of a software project.

The hall of shame is no laughing matter

You can’t write great code if you’re an inexperienced programmer, but you can certainly always write bad code no matter your experience or IQ. Anti-patterns aren’t always committed by bad programmers but they’re always the result of unconscious bad habits.
The hall of shame is of course the daily WTF, where the most glaring incompetence is exposed to ridicule for the coding community, thankfully anonymous. What bothers me though is the implicit assumptions that we, the readers, know better and have nothing to gain from it but a chuckle. But anti-patterns are no joke. Just because you can avoid beginners mistakes doesn’t mean you’re immune to committing the really major cock-ups. I can warmly recommend Scott Rosenberg’s Dreaming in Code about the ill-fated Chandler project, which comprised some of the best programmers, hand-picked by none other than Mitch Kapor of Lotus fame. Chandler, you ask? Exactly.

My personal top 3 of good habits

Here’s my personal top three attitudes that are most instrumental to building quality software and teams:

  • Pride of collective ownership.
    Without this you will care less for your own quality and that contributed by others. Note that you can be be proud of a particularly clever bit of code, but that doesn’t count if it confuses your colleagues or conflicts with their code. So you need…
  • an attitude of always wanting to help, really the same kind you can often find in family-run hotels or B&Bs, where nobody gives you the feeling that it’s just a job to them.
  • Meanwhile you have to stay firm about quality and professional standards, Most software is written for the long term. Others will probably be working on it after you leave. You have to display good stewardship, which having an eye for the long term.

Especially points 2 and 3 can be at odds: it means having to say no more often. It means standing your ground ocassionally and insist that some things are non-negotiable.

Self-centred indifference

I confess that all this is hard. Just put the above list of saintlike qualities in the negative and you get a sense of what we’re battling with on a daily basis. Unclear management commitment to a product’s roadmap kills the sense of collective ownership. This lack of commitment leads to indifference about quality, and there’s nothing more contagious than indifference. Code quality will suffer, and poor quality is a slippery slope. There’s just no fun if the best you can do is make things slightly less bad.

Self-centred attitudes on the other hand lead to a host of toxic effects within a team: it’s being overly confident about your own abilities, bragging, tunnel vision and envy. It’s a cliche that programmers are on average more communicatively inept, socially awkward, pedantic and self-centred, but it wouldn’t have become a cliche if there wasn’t a grain of truth nonetheless. Several grains actually. Maybe even enough to bake a small loaf.

The dangerous short term

The upside about these two team-killing attitudes is that they stand out to the good observer and you can act upon them. There is another category of bad habits that seem less destructive on the surface because they don’t do as much harm to team morale, but can be equally damaging to long-term product quality. I’m talking about being too focused on short term result and not looking back at lessons learned. We tend to do it because code is written today, to be shipped next week. We don’t exactly please our stakeholders if we delay the release to upgrade a few old libraries. So this never happens until these libraries are ancient, unsupported and a security vulnerability.

There’s a host of anti-patterns that come from bad housekeeping and not looking back: the boat anchor, the dead end, the Lava Flow, Continuous obsolescence. And what else but pride and tunnel vision could lay at the root of the Golden Hammer and intellectual violence?

Vegetables and raw nuts

If clean code is vegetables and raw nuts, anti-patterns are hamburgers with coke and ice-cream. Their appeal is much like junk food: we’re drawn to it naturally. Sometimes we feel the need to impress others and sometimes some private concerns outweigh any code you’re working on at the moment so you just want it to work quickly and go home. The occasional anti-pattern becomes a problem if you’re unwilling to learn from your mistakes or ashamed to admit to them. I’ve made tons of mistakes. There aren’t many pieces of code I’ve written at any stage in my career that couldn’t have been improved at a later glance.

There are always people who are deliberately vicious and manipulative about taking the maximum amount of credit for the least amount of work. Rest assured: they tend to work in the financial industry and don’t wear a t-shirt to work.

The post When anti-patterns become a pattern appeared first on codecentric AG Blog.

Categories: Agile, Java, TDD & BDD

GC Explained: Times

Javalobby Syndicated Feed - Wed, 27-Sep-17 21:01

Have you ever wondered what user, sys , and real times in a GC log mean? Well, I have, a couple of times at least. Let’s say that we have the following line after Full GC entry:

[Times: user=4.21 sys=0.03, real=0.75 secs]

Categories: Java

Preparing for Java 8 Certification

Javalobby Syndicated Feed - Wed, 27-Sep-17 13:01

If you are confident that your Java 8 skills are pretty good, then your next move is to get certified. Why? Well, certification is proof that you know what you’re doing. It makes you more desirable to employers and has the added benefit of giving you personal satisfaction and confidence in your own Java 8 expertise. 

Java certification is a highly desirable skill for software development roles. You’ll find Java 8 certification comes up a lot when you’re trawling those job boards. It goes without saying, then, that having Java certification puts you head and shoulders above other applicants for roles that require Java.

Categories: Java

Java Persistence API Introduction (Part 2)

Javalobby Syndicated Feed - Wed, 27-Sep-17 09:01

This is the second part of a two-part article introduces the Java Persistence API. In part one, I talked about how to annotate a POJO with appropriate annotations in order to make the POJO into a persistable entity.

The Persistence Provider

The persistence provider can be configured to automatically create, update and remove a database schema based on the annotated entities. Entities are managed by the entity manager, which is represented by an EntityManager instance and defines the methods that are used to interact with the persistence context.

Categories: Java

Don't Protect Your Domain From Legacy Systems at All Costs

Javalobby Syndicated Feed - Wed, 27-Sep-17 03:01

For the past 9 months, I have been working on a project related to proper VAT tax handling at my company, Zooplus. If I were to name a single biggest lesson learned during the course of this project, there's a big chance that it'd be about taking a more legacy-friendly approach to domain modeling.

Our Approach

I wasn't working on the project from the very beginning, so I don't know whether that was planned, but our approach to handling the "legacy" stuff effectively turned out to be like this:

Categories: Java

A Declarative Java ORM Speaks Fluent SQL

Javalobby Syndicated Feed - Wed, 27-Sep-17 00:01

As a developer, you do not want to be micromanaged with detailed lists of instructions. So when you ask your ORM to give you data, why do you have to supply the database query to be executed?

Clearly, that has historical reasons, and an ORM that is free to create queries by itself needs to have an API that declaratively describes the expected result as a combination of data retrieval and modification operations. Java 8 streams provided the needed language support for that. The time had come for a declarative ORM.

Categories: Java

The Stack Walking API in Java 9

Javalobby Syndicated Feed - Tue, 26-Sep-17 21:01

Status Quo

Imagine you're going to find the caller of the currently executing method. To make it even more interesting, imagine you're going to get current thread's stack frames one by one and filter them to extract or expose some meaningful information. How would you do that?

Before Java 9, there were three different approaches that we could use to solve those mentioned problems:

Categories: Java

Convenience Factory Methods for Collections in Java 9

Javalobby Syndicated Feed - Tue, 26-Sep-17 13:35

Java 9 doesn't bring as many dramatic changes to our way of coding as its predecessor did, but surely we will have some fancy features — one of which I would like to present to you in this article. When I started coding in Groovy about 5 years ago, I was amazed by the collections support there — especially when it came to initializing an immutable list. I could do it in one simple line:

def band = ["Bruce", "Steve", "Adrian", "Dave", "Janic", "Nicko"].asImmutable()


This year, I also started coding in Scala, and here we have some fancy tricks like:

Categories: Java

Java Command-Line Interfaces (Part 16): JArgp

Javalobby Syndicated Feed - Tue, 26-Sep-17 13:01

The Java-based command line argument processing library covered in this post was the featured library of an IBM DeveloperWorks article Java programming dynamics, Part 3, Applied reflection (this 2003 article was "archived" in 2016, but is still available for PDF download). The library, called JArgp (Java Command Line Argument Processing Library), is defined on its main web page as "a library for processing command line arguments in Java." This page adds, "Unlike most other libraries of this type, JArgp uses reflection to store actual values directly to fields in the target application object." JArgp 1.0 is featured in this post.

JArgp is a minimalistic library as shown by the small number of classes in the JArgp JAR.

Categories: Java

Will Your Applications Run Faster With Java 9?

Javalobby Syndicated Feed - Tue, 26-Sep-17 09:01

Java 9 comes with several enhancements on how Strings are being handled, promising to improve the performance of your applications.

Storing Strings

If you examine the memory being used by your Java application, you will most likely notice that a significant amount of the heap is allocated by String objects.

Categories: Java

Thread Slivers eBook at Amazon

Syndicate content