Feed aggregator

Java Command-Line Interfaces (Part 4): Commandline

Javalobby Syndicated Feed - 2 hours 19 min ago

This fourth part of my series on command-line parsing in Java features Commandline, which is described as "a Java library to parse command line arguments" that "is based on a mapping from the command line arguments onto objects, by using annotations."

Like previously covered args4j and jbock, Commandline employs annotations to provide the "definition" of potential command-line options. However, while args4j does this via annotations on class fields and jbock does this via annotations on the constructor and its parameters, Commandline uses annotations on "set" (mutator) methods. In this post, I use a Main class example as in the previous posts on Java-based command-line processing, but in normal situations, I'd typically prefer to have a special class representing command-line arguments.

Categories: Java

Java 9: Collections Improvement

Javalobby Syndicated Feed - 5 hours 19 min ago

Java 9 has created factory methods for creating immutable Lists, Sets, Maps, and Map.Entry Objects. These utility methods are used to create empty or non-empty collection objects.

In Java 8 and earlier versions, we can use Collections class utility methods like unmodifiableXXX to create Immutable Collection objects for our requirements. If we want to create an Immutable List, then we can use the Collections.unmodifiableList method.

Categories: Java

Concurrency: Java Futures and Kotlin Coroutines

Javalobby Syndicated Feed - 8 hours 19 min ago

This article is featured in the new DZone Guide to Java: Development and Evolution. Get your free copy for more insightful articles, industry statistics, and more!

A long time ago, one had to manually start new threads to run code concurrently in Java. Not only was this hard to write, it also was easy to introduce bugs that were hard to find. Testing, reading, and maintaining such code was no walk in the park, either. Since that time, and with a little incentive coming from multi-core machines, the Java API has evolved to make developing concurrent code easier. Meanwhile, alternative JVM languages also have their opinion about helping developers write such code. In this post, I’ll compare how it’s implemented in Java
and Kotlin.

Categories: Java

This Week in Spring: Dealing With Data, Kotlin, XML, and More!

Javalobby Syndicated Feed - Wed, 28-Jun-17 09:01

Hi, Spring fans, and welcome to another installment of This Week in Spring! This week, I’m in Chicago, New York City, and Denver talking to Pivotal customers. We’ve got a lot of good stuff to look at this week so let’s get to it!

Categories: Java

Vert.x and Fiber: Perfect Synergy!

Javalobby Syndicated Feed - Wed, 28-Jun-17 03:01

Presumably, you have already heard of Vert.x, a toolkit for building Reactive applications on the JVM. Vert.x is completely asynchronous, lightweight, incredibly fast, event-driven, and definitely a very promising project. Some of you may have heard about Fibers — if you're not familiar with them, check here and here. In addition to Vert.x's non-blocking and event-driven toolkit, we can take advantage of Vertx-Sync as a component through which we can easily escape from well-known callback hell while using non-blocking APIs. Vertx-Sync allows you to perform asynchronous operations and receive events in a synchronous way, but without blocking kernel threads. As a result, even if  it’s synchronous, it is negligibly less performant. Vertx-Sync uses Quasar to provide its Fibers.

In this article, I’ll show you how to:

Categories: Java

A SonarQube Plugin for Kotlin: Creating the Plugin

Javalobby Syndicated Feed - Wed, 28-Jun-17 00:01

This is the third post in a series about creating a SonarQube plugin for the Kotlin language:

  • The first post was about creating the parsing code itself.
  • The second post detailed how to use the parsing code to check for two rules.

In this final post, we will be creating the plugin proper using the code of the 2 previous posts.

Categories: Java

Design Patterns in the Age of Microservices and Frameworks

Javalobby Syndicated Feed - Tue, 27-Jun-17 22:01

This article is featured in the new DZone Guide to Java: Development and Evolution. Get your free copy for more insightful articles, industry statistics, and more!

We are in the age of web applications, frameworks, and microservices architectures. We can spin a module of our application within a day from zero to production. Any technical concern other than coding up our business rules has already been taken care of for us. We simply write the business rules, put them in a framework, and it works. What does that mean for design patterns? Do we still need them or we can safely put them in a museum?

Categories: Java

OOP and FP: Avoiding Reductionist Thinking

Javalobby Syndicated Feed - Tue, 27-Jun-17 21:01

Real quote (lightly edited to remove tangential nonsense.):

Recently, I watched a video and it stated that OO is about nouns and functional programming is about the verbs. Also, ... It would be nice to have a blog post which summarized the various mindsets associated w/ the various paradigms.
— Aspect-Oriented Programming with the e Verification Language by David Robinson 


Categories: Java

Enterprise Java Newscast #34: Microprofile and Java EE 8 [Podcast]

Javalobby Syndicated Feed - Tue, 27-Jun-17 13:01

The Enterprise Java Newscast, hosted by Kito D. Mann, Ian Hlavats, and Daniel Hinojosa, is a monthly podcast that covers headlines, trends, and technologies in the world of enterprise software development.

In this episode, Kito and Danno discuss JSF, Polymer, BootsFaces, Java EE 8, microprofile.io, AWS S3 going down, and more.

Categories: Java

Easy Conversion of HTTP Payloads

Javalobby Syndicated Feed - Tue, 27-Jun-17 09:01

Almost every application needs to handle data in an interchangeable format. In the world of HTTP JSON-based APIs, the task of serializing and deserializing the payloads is something usually delegated to a third party library. Some examples are Jackson, Gson, and the most recent Java EE spec JsonP. What if there was a way where applications can be decoupled from these providers in a similar fashion to how SLF4J does for logging? That's the goal of Payload.


Categories: Java

Java Command-Line Interfaces (Part 3): jbock

Javalobby Syndicated Feed - Tue, 27-Jun-17 03:01

In the first two posts of this series on command-line parsing in Java, I looked at the Apache Commons CLI and args4j libraries. In this third post in the series, I look at jbock, the self-described "curiously simple CLI parser."

My posts on command-line parsing in Java have used examples based on providing a required file name and an optional verbose flag to the Java application. The same approach is used in this post to demonstrate jbock 1.8. The full source code for the example class is available on GitHub, but the code generated by jbock (Main_Parser) is not available, as it can be generated.

Categories: Java

Thoughts on Kotlin’s Future Features Survey

Javalobby Syndicated Feed - Tue, 27-Jun-17 00:01

So, the survey results for Kotlin’s future features are in. Let’s talk about that.

Survey Says…?

First off, I’d like to say that I’m sad that I wasn’t able to participate in this. It’s not that JetBrains stopped me, I just wasn’t able to watch at the time.

Categories: Java

Debug Ansible Playbooks Like A Pro

codecentric Blog - Mon, 26-Jun-17 22:00

With version 2.1 Ansible introduced two features that make it possible to add proper debug logging to your playbooks, and also check and troubleshoot them on the fly, while they are executed.

The Debug Strategy

Strategies change the way Ansible executes your tasks. The default strategy is linear. That is the one you are used to, and that executes all tasks one after another, always waiting until each host finished the current task before continuing with the next one. There is also a free strategy that executes the tasks on each host as fast as it can, without waiting for the other hosts to catch up.

If you set the strategy to debug, the Ansible playbook debugger will kick in whenever a task has failed, and give you the chance to view and change parameters in-flight and re-run just the failed task. Everyone who ever executed a lengthy playbook with lots of registered variables over and over again, just to debug a small task at the end of it, will immediately see the benefit of the debug strategy.

To activate a strategy you can add it to your playbook:

- hosts: localhost
  strategy: debug
      - ...

or, less invasively, change the strategy temporarily with an environment variable:

$ export ANSIBLE_STRATEGY=debug

and unset it when you are done debugging. This avoids adding a line to your playbook that you need to remove anyway before you commit your fix.

Now, when a task fails Ansible will spawn the debugger and present you with a prompt. Let us assume you want to write a file:

- name: Write my file
    dest: /tmp/my
    content: |
      Hello World!
      This is my file.

and that fails for some reason. When using the debug strategy, Ansible will invoke its debugger that you can use to dissect the current variable environment of the task and change values or task parameters:

TASK [Write my file] **********************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "can not use content with a dir as dest"}
Debugger invoked
(debug) task.args
{u'dest': u'/tmp/my', u'content': u'Hello World!\nThis is my file.\n'}

The error message tells me that I tried to write to a destination that is a directory and not a file. My bad, the correct dest parameter value should have been /tmp/my/myfile. Now lets change that parameter on the fly and re-run the task:

(debug) task.args['dest']='/tmp/my/myfile'
(debug) task.args
{u'dest': '/tmp/my/myfile', u'content': u'Hello World!\nThis is my file.\n'}
(debug) redo
changed: [localhost]

The debugger not only lets you change variables and values you can also add and delete them:

(debug) task.args['owner']='myuser'
(debug) task.args
{u'dest': '/tmp/my/myfile', u'content': u'Hello World!\nThis is my file.\n', 'owner': 'myuser'}
(debug) del(task.args['owner'])
(debug) task.args
{u'dest': '/tmp/my/myfile', u'content': u'Hello World!\nThis is my file.\n'}

You can find a full list of the debugger commands here.

The Debug Module

The debug module is well known. It is the Ansible equivalent to a print line in Python code that you add now and then to see some variable values when debugging your scripts. But debug lines are ugly and you want to remove them, or replace them with proper logging, before releasing your code. With version 2.1 Ansible extended the debug module with a verbosity parameter, that transforms it from an ugly print line, that clutters your logs, with debug information on every call, into a more useful logging mechanism with an explicit debug level.

When adding a debug task and setting the the verbosity level to 2:

- name: Write file
    dest: /tmp/my
    content: |
      Hello World!
      This is my file.
    register: write_file_result
- name: Debug write_file_result
      var: write_file_result
      verbosity: 2

it will only be executed if you specify this verbosity (-vv) on the command line:

ansible-playbook debug-demo.yml -vv


TASK [Debug write_file_result] **********************************************
ok: [localhost] => {
    "write_file_result": {
        "changed": true,
        "checksum": "0ded82d0b36ca79392d9bd97debb6fbbb7bb93ef",
        "dest": "/tmp/my/myfile",
        "gid": 20,
        "group": "staff",
        "md5sum": "f52e35e56cd4087de0948890215f7de0",
        "mode": "0644",
        "owner": "myuser",
        "size": 30,
        "src": "/Users/myuser/.ansible/tmp/ansible-tmp-1498165508.64-230947914847899/source",
        "state": "file",
        "uid": 501

When using verbosity level 1 (-v) Ansible will simply skip your debug task:

ansible-playbook debug-demo.yml -v


TASK [Debug write_file_result] ********************************************************************
skipping: [localhost] => {"changed": false, "skipped": true, "skipped_reason": "Verbosity threshold not met."}

Adding debug tasks not only on demand, but as a fixed part of your role will give you the ability to more quickly troubleshoot and debug. Some good points to insert debug logging are:

  1. After any task that registers a variable, or
  2. at the beginning of any included file that is parameterized or looped over.

Another good use case is to add well placed debug tasks and the verbosity level of your choice to your Jenkins build jobs, and have debugging information right in your logs.

The post Debug Ansible Playbooks Like A Pro appeared first on codecentric AG Blog.

Categories: Agile, Java, TDD & BDD

Yes, You Can: Java 9 for the Legacy Developer

Javalobby Syndicated Feed - Mon, 26-Jun-17 21:01

This article is featured in the new DZone Guide to Java: Development and Evolution. Get your free copy for more insightful articles, industry statistics, and more!

Whenever a new version of Java is released, there’s a lot of excited discussion about new language
constructs and APIs, features, and benefits. But the excitement quickly wanes for legacy developers when they remember that they must maintain and enhance existing applications, rather than create new ones. Most applications must be backward compatible with earlier versions of Java, which do not support new features presented by shiny new Java releases. So, legacy developers resign themselves to sit on the sidelines and watch.

Categories: Java

What Designers and Game Devs Need to Know About Git LFS

Javalobby Syndicated Feed - Mon, 26-Jun-17 13:01

Atlassian is dedicated to unleashing the potential in software teams. We want to help you work smarter and faster. This is the reason we keep adding new features to Bitbucket  – branch permissions, merge checks, smart commits, smart mirroring and many more.

Last year, we were working on solving another big problem for our users: tracking large files in a Git repository. Git Large File Storage (LFS) provides the ability to store really big files where they’re needed, not just where they fit. We want to make Git right for everyone and that’s why we decided to collaborate with GitHub on building a standard for large file support.

Categories: Java

Deploying Certificates to WildFly with Octopus Deploy

Javalobby Syndicated Feed - Mon, 26-Jun-17 09:01

A recent feature added to Octopus Deploy is the ability to manage and deploy certificates within your infrastructure. In this blog, post I’ll show you how to export certificates from Octopus into a Java keystore, and then use that keystore to secure a WildFly standalone or domain instance running on Windows.


To run the commands and scripts in this blog post, you will need to install some tools.

Categories: Java

Keeping Java Simple

Javalobby Syndicated Feed - Mon, 26-Jun-17 03:01

Lately, I was hooked on an algorithm challenge from a popular site, and I found it very difficult to provide a decent solution in Java. That solution was not approved, but none of the test cases really did not pass. The solution was not optimized.

But, later, I came up with another solution containing just 3 lines of code! In my first solution, the number of lines in the code was more than 50!

Categories: Java

An Overview of Garbage Collection in Java

Javalobby Syndicated Feed - Mon, 26-Jun-17 00:01

The Java garbage collector poses a great impact on the overall working and performance of an application. As the size of the garbage grows, the runtime of an application decreases. Hence, it is essential that you clear this garbage off of your application every now and then to enhance its productivity and user performance.

Garbage collection can be quite a daunting task. After all, choosing a wrong garbage collector type or settings can hamper the functionality of your app. There are typically seven types of garbage collectors known to us. These are classically bifurcated between the ‘mostly’ and ‘most concurrent’ category. With the ‘mostly’ types, they sometimes do not operate as expected and a fallback mechanism takes place. On the other hand, the ‘most concurrent’ collectors function concurrently with the application’s execution and rarely stop the world.

Categories: Java

Why I Started Learning Kotlin

Javalobby Syndicated Feed - Sun, 25-Jun-17 21:01

If you walk into ObjectStyle's dev office in Minsk, you will easily spot Ruslan's desk by the abundance of Kotlin stickers on his machine. Ruslan has been with ObjectStyle since 2016. When he's not busy turning China-grown gourmet tea into exceptional code, he heads the Belarus Kotlin User Group and talks about the language at various conferences.

We sat down with Ruslan to discuss why he took up Kotlin, why he finds the language fascinating, and how he sees Kotlin's future.

Categories: Java

Generic Programming in Scala With Shapeless

Javalobby Syndicated Feed - Sat, 24-Jun-17 22:01

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

Thread Slivers eBook at Amazon

Syndicate content