Feed aggregator

The Most Popular Java Tools for Every Phase of Development

Javalobby Syndicated Feed - Mon, 15-Aug-16 05:31

Just because a tool is the most popular doesn’t mean it’s the “best.” What’s best is always context-dependent in programming. However, popularity is an undeniably important metric when choosing between a handful of similar tools. It’s not the popularity itself that adds to a tool’s value; it’s the greater supply of resources and support from the larger community of a given tool.

Popular tools are easier to learn because so many people can help you use them. And popular open-source tools tend to be less buggy because more eyes are on the code and more people are testing it in a greater number of scenarios.

Categories: Java

New Book — Microservices for Java Developers By Christian Posta

Javalobby Syndicated Feed - Mon, 15-Aug-16 03:31

One of our Camel riders, Christian Posta, recently had his first book published.

Microservices for Java Developers

Categories: Java

Reduce Boilerplate Java Using try-with-resources

Javalobby Syndicated Feed - Mon, 15-Aug-16 00:31

Java 8 has been out for a while, and Java 7 has been out even longer. But even so, many people still unfortunately are not taking advantage of some of the new features, many of which make reading and writing Java code much more pleasant. For example, Java 7 introduced some relatively simple things like strings in switch statements, underscores in numeric literals (e.g. 1_000_000 is easier to read and see the magnitude than just 1000000), and the try-with-resources statement. Java 8 went a lot further and introduced lambda expressions, the streams API, a new date/time API based on the Joda Time library, Optional, and more.

In this blog and in a few subsequent posts, I will take a simple snippet of code from a real project, and show what the code looked like originally and what it looked like after refactoring it to be more readable and maintainable. To start, this blog will actually tackle the try-with-resources statement introduced in Java 7. Many people even in 2016 still seem not to be aware of this statement, which not only makes the code less verbose, but also eliminates an entire class of errors resulting from failure to close I/O or other resources.

Categories: Java

Scala vs Kotlin: Operator Overloading

Javalobby Syndicated Feed - Sun, 14-Aug-16 22:31

Last week, I started my comparison of Scala and Kotlin with the Pimp my library pattern. In the second part of this serie, I’d like to address operator overloading.


Before we dive into the nitty-gritty details, let’s try first to tell what it’s all about.

Categories: Java

The Missing Link of Software Engineering

Javalobby Syndicated Feed - Sun, 14-Aug-16 21:31

One of the major challenges of Software Engineering is the numerous information gaps between different activities around it (requirements, design, algorithm, user interface, testing, bug tracking, documentation, etc). Can we easily check if all requirements are covered by a design? Can we identify if all design points are covered by an implementation or by user interface controls, or all requirement items by testing and documentation? Sometimes restrictions are found during coding and testing, so they should be considered as a part of requirements. Or imagine coverage of all options to generate all possible use-cases for test coverage. Wouldn't it be great if we could control all this and use it with Continuous Integration?

Why can't we fill these gaps today? Well, actually we do but only in our minds. What are the obstacles for doing this at least in semi-automatic mode? The most probable cause is our belief that meaning cannot be extracted from ambiguous natural language and partially it is enchantment by natural language itself. Concerning the first point, we do agree this is a difficult task but why can't we facilitate it by having some interim forms between natural language and formal data (and metadata)? The second point could be more tough but try to accept it: natural language forms are not ideal (though convenient) representation of meaning, it is just one of many others.

Categories: Java

If-Then-Else Is a Code Smell

Javalobby Syndicated Feed - Sun, 14-Aug-16 00:31

In most cases (maybe even in all of them), if-then-else can and must be replaced by a decorator or simply another object. I've been planning to write about this for almost a year but only today found a real case in my own code that perfectly illustrates the problem. So it's time to demonstrate it and explain.

Fargo (1996) by Coen BrothersFargo (1996) by the Coen Brothers

Take a look at the class DyTalk from yegor256/rultor and its method modify(). In a nutshell, it prevents you from saving any data to DynamoDB if there were no modifications of the XML document. It's a valid case, and it has to be validated, but the way it's implemented is simply wrong. This is how it works (an oversimplified example):

Categories: Java

Five Ways to Update Fields in a Thread Safe Way: Part 2

Javalobby Syndicated Feed - Sat, 13-Aug-16 22:31

In part one, we looked at the first 3 ways to update a field in a threadsafe way in Java. Here are the 4th and 5th! 

CompareAndSet-Based Atomic Update

When to Use?

Use compareAndSet when the lock in the solution described in part one becomes a bottleneck. Or use it if there exists a ready-made solution, for example, the AtomicInteger as shown below.

Categories: Java

Five Ways to Update Fields in a Thread Safe Way: Part 1

Javalobby Syndicated Feed - Sat, 13-Aug-16 00:31

There are five ways to update a field in Java in a thread safe way. But before we start, what do you have to look at? If you access a field from many threads, you must make sure that:

  1. Changes are made visible to all threads
  2. The value is not changed during the update by the other threads
  3. Threads that are reading do not see the inconsistent intermediate state

You can achieve this by one of the following 5 ways:

Categories: Java

Build a Custom ODBC Driver in C/C++, Java, or C#

Javalobby Syndicated Feed - Fri, 12-Aug-16 21:38

In today’s tech world, your success is directly proportional to your ability to integrate with other technologies and make more informed decisions. Well, everyone seems to know that, so how do you differentiate? You differentiate yourself by choosing the smartest way to integrate technologies—using standards based drivers. 

Can't find a driver for your application? You might be one of the following:

Categories: Java

Using JUnit 5 in IntelliJ IDEA

Javalobby Syndicated Feed - Fri, 12-Aug-16 05:31

One of the new features in IntelliJ IDEA 2016.2 is support for the new JUnit 5 testing framework. Almost all Java developers will have used JUnit at some point, so it’s pretty exciting to find the newest version has evolved with the times and provides a number of new features, some of which may be familiar to those who have used other frameworks.

IntelliJ IDEA supports the ability to actually run tests written for JUnit 5 – there’s no need to use the additional libraries (like the Gradle or Maven plugins for example), all you need is to include the JUnit 5 dependency. Here we’re using Gradle to include the dependency to the M2 version:

Categories: Java

Useful Scala Compiler Options for Better Scala Development

Javalobby Syndicated Feed - Fri, 12-Aug-16 03:31

At Threat Stack, we like to leverage our tools to the fullest. Since we use Scala, it only makes sense for us to always be looking into ways of getting the most out of the Scala Compiler to enhance our productivity. And, as it turns out, the Scala Compiler offers a number of features that makes our lives way better! 

A couple of resources make great recommendations about what options you should pass to the Scala Compiler. (Rob Norris' Blog comes to mind.) However, most of the resources don't really explain why you want to enable these options. In this series, I'll cover a number of Scala Compiler options that ease development. I'll discuss ones that we use at Threat Stack as well as other common options that we have opted not to use. Where applicable, I’ll show examples of issues in code that will be caught by the compiler once the correct options have been enabled.

Categories: Java

Does My Method Look Big in This?

Javalobby Syndicated Feed - Fri, 12-Aug-16 00:31

How big is the following Java method?

public Collection getDescription() {
    SystemLibrary systemLib = registry.get(SystemLibrary.class);
    Analysis analysis = systemLib.getCurrentAnalysis(registry);
    return getDescription(analysis);

This humble method locates some sort of system library, retrieves an Analysis, and returns a description of that Analysis.

Categories: Java

Remembering to Reset Thread Context Class Loader

Javalobby Syndicated Feed - Thu, 11-Aug-16 22:31

I'm having a difficult time thinking of anything I like less about working with Java than working with class loaders. This is particularly true when working with application servers or OSGi where the use of multiple class loaders is prevalent and the ability to use class loaders transparently is reduced. I agree with the OSGI Alliance Blog post What You Should Know about Class Loaders that "in a modular environment, class loader code wreaks havoc."

Neil Bartlett has written the blog post The Dreaded Thread Context Class Loader in which he describes why the thread context class loader was introduced and why its use is not "OSGi-friendly." Bartlett states that there are rare cases in which "a library only consults the TCCL," but that in those rare cases "we are somewhat stuck" and "will have to explicitly set the TCCL from our own code before calling into the library."

Categories: Java

Connascence of Meaning in Java

Javalobby Syndicated Feed - Thu, 11-Aug-16 12:19

Connascence is a term used to describe the relationship and taxonomy of dependency between two software components. Connascence was used Meilir Page-Jones in the 90's in the book What Every Programmer Should Know About Object Oriented Design (later updated to use UML instead of Page-Jones's own modelling language in Fundamentals of Object-oriented Design in UML (Object Technology Series)) but has not seen widespread popularity in the development community outside of specific areas such as this talk by Jim Weirich and a series of blog posts and a talk by Kevin Rutherford.

Connascence provides a taxonomy for dependency and coupling, allowing developers to reason about the quality of their code. There are two broad categories of connascence, and 9 different types or levels. 

Categories: Java

The Single Level of Abstraction Principle

Javalobby Syndicated Feed - Thu, 11-Aug-16 05:36

It’s virtuous to separate out different perspectives in code because it helps make code more testable, extendable, and understandable. We want to use entities at the same level of perspective so that code is easier to read and understand code.

The same thing is true within entities where we want to do tasks at the same level of abstraction.

Categories: Java

Creating an Editor with Syntax Highlighting Using ANTLR and Kotlin

Javalobby Syndicated Feed - Thu, 11-Aug-16 05:31

In this post we are going to see how to build a standalone editor with syntax highlighting for our language. The syntax highlighting feature will be based on the ANTLR lexer we have built in the first post. The code will be in Kotlin, however it should be easily convertible to Java. The editor will be named Kanvas.

Previous Posts

This post is part of a series on how to create a useful language and all the supporting tools.

Categories: Java

This Week in Spring: SpringOne Platform Wrapup

Javalobby Syndicated Feed - Thu, 11-Aug-16 03:31

Welcome to another installment of This Week in Spring! This week I’m recovering from a crazy awesome week at SpringOne Platform while visiting customers here in summer-time London.

We’ve got a lot to cover so let’s get to it!

Categories: Java

Guide to Time and Date in Java (Part 3)

Javalobby Syndicated Feed - Wed, 10-Aug-16 23:01

In part three of this post, we'll discuss how to express local time and date without reference to any specific time zone and discussed ways of testing dates. I recommend reading parts one and two if you haven't already.

This post continues to cover the basics of handling time and date in Java, but the scope of this article does not extend to cover every possible situation... this is just a start. 

Categories: Java

Easy Publishing to Central Repository – 8 Part Video Series

Javalobby Syndicated Feed - Wed, 10-Aug-16 05:31

The Central Repository is the biggest repository for Java components by far. It hosts components for large organizations like the Apache Software Foundation and thousands of small open source project hosted on GitHub and other places. There are close to 1.5 million different artifacts now. And everyone is downloading their components from it. Last year there were over 31 billion (!!!)  downloads

Everyone can publish their components and we we have extensive documentation for you. And now we also created an 8 part video series, Easy Publishing to Central Repository. I recorded this series to take all the guess work out of publishing your project and explain things in nice and short, easily consumed videos. Nexus Community members have immediate access to the entire series. If you’re not a member, it takes less than 15 seconds to join.

Categories: Java

Java 8 Performance Optimization — DZone Refcard Update

Javalobby Syndicated Feed - Wed, 10-Aug-16 03:31

I am happy to inform you that I published recently an update to the existing refcard on Java Performance Optimization which is now available from DZone. The updated material now better reflects the Java 8 features and provides a dedicated section and guidelines about the JVM Metaspace.

I recommend that you download your FREE copy today.


Categories: Java

Thread Slivers eBook at Amazon

Syndicate content