Java Lobby Announcements

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

Entity Framework: new() vs. DbSet.Create()

Thu, 2017-06-08 09:01

This is one of those "I had to explain this couple times already so next time, I want something I can redirect people to" kind of post.

What I want to write about is the difference in behavior between using new() and DbSet.Create() for instantiating new entities. In order to do this, I've created a very simple model and context:

Categories: Java

How to Shoot Yourself in the Foot Building a Java Agent

Thu, 2017-06-08 06:01

Over the years of building Plumbr, we have encountered many challenging problems. Among others, making the Plumbr Java Agent perform reliably without endangering customers’ applications is a particularly tricky one. Safely gathering all the required telemetry from a live system poses a huge set of problems to tackle. Some of them are quite straightforward while some of them are fiendishly non-obvious.

In this blog post, we would like to share with you several examples demonstrating the complexities encountered in building the support for some seemingly simple aspects our Agents need to cope with. The examples are simplified a bit, but are extracted from real world problems we needed to solve some time ago. In fact, these are just the tip of the iceberg awaiting those who try to use byte code instrumentation or JVMTI.

Categories: Java

Naming Matters

Wed, 2017-06-07 22:01

Everything around us has a name. I mean everything — otherwise, how would we be able to refer to them, particularly in programming? From our project name, directories, variables, and more, a name must be associated with every item, or else we lose their meaning and use.

So when you decide to work on a project, make sure you keep telling yourself that naming matters. There is more to a program than a compiler understanding what you’ve written and running the code. To create software, writing the code is one thing, maintaining the code is another. Sometimes, maintaining existing code is more difficult than creating a new one. We are afraid we may bring the project down. So, below are some tips I gathered from the book “Clean Code” about how to use good namings when writing programs.

Categories: Java

This Week in Spring: Spring Boot and Kotlin, Lombok, and NoSQL

Wed, 2017-06-07 18:01

Welcome to another installment of This Week in Spring! This week, I’m in Malaysia and then Singapore, where I’ll spend time with customers in the financial services world and speak at the Singapore Spring User Group on June 8th. If you’re around, come out or say hi!

Categories: Java

JUnit Testing for Solr 6

Wed, 2017-06-07 12:01

Recently, I wanted to write some JUnit test cases to test Solr queries (these Solr queries were constructed in Solrj — a Java client library to access Solr), which I have written to retrieve data from the Solr index. When I was doing this, I could not find good documentation or tutorials and, therefore, I got to do a bit of trial and error to come up with the following model. I thought to write it down, hoping someone else may find it helpful.

My development environment was Gradle, and the following are the steps I used to set up the environment.

Categories: Java

Enabling Bitbucket Pipelines Build Notifications in HipChat

Wed, 2017-06-07 09:01

Every time you trigger a build in Bitbucket Pipelines, whether by pushing commits or creating a pull request, you have to remain at your desk refreshing email to see if the build has passed. All to avoid wearing the cone of shame for not finding out about a failed build quickly.

Wouldn’t it just be better to get notified ASAP asynchronously?

Categories: Java

Parsing in Java (Part 2): Diving Into CFG Parsers

Wed, 2017-06-07 06:01

In case you missed Part 1, we covered the basics of how parsing works, then dove a bit deeper into the architecture of parsers, considering overviews the different types available, parse trees vs. ASTs, and more. Here in Part 2, we'll touch on parser generators before diving into context-free grammars. Part 3 will then follow up with a look at parsing expression grammars (PEGs).

Parser Generators

The basic workflow of a parser generator tool is quite simple: You write a grammar that defines the language, or document, and you run the tool to generate a parser usable from your Java code.

Categories: Java

jhsdb: A New Tool for JDK 9

Tue, 2017-06-06 22:01

I like to use the command-line tools provided with the JDK in the early steps of analyzing performance and other issues with Java-based applications and have blogged on tools such as jcmd, jps, jstat, jinfo, jhat and jmap, jrunscript, jstack, and jdeps. JDK 9 is bringing new command-line tools with multiple tools specifically related to new JDK 9 features such as modularity (jlink and jmod) and enhanced deprecation (jdeprscan). In this post, I focus on a new command-line tool delivered with JDK 9 for dealing with performance and serviceability issues: jhsdb.

The jhsdb tool is described on its Oracle JDK 9 Documentation Early Access page, "You use the jhsdb tool to attach to a Java process or to launch a postmortem debugger to analyze the content of a core-dump from a crashed Java Virtual Machine (JVM)." The tool comes with several "modes" and several of these modes correspond in name and function with individual command-line tools available in previous JDK distributions. The jhsdb tool not only provides a single tool that encompasses functionality of multiple other tools, but it also provides a single, consistent approach to applying these different functions. For example, the jhsdb command-line syntax for getting help for each of the "modes" is identical.

Categories: Java

The Problems Facing the JPMS' Adoption

Tue, 2017-06-06 18:01

The EC's "No" vote on the Java Platform Module System took plenty of people by surprise last month. Concerns wth the JPMS ranged from its implementation to fears over the perceived impact it would have on the community, as proposed.

Among plenty of onlookers, Reza Rahman of the Java EE Guardians has been keeping an eye on the proceedings as they've developed, both before and after the vote.

Categories: Java

What's Wrong With Hashcode in java.lang.String?

Tue, 2017-06-06 12:01

One of the most significant criteria of every hash function is the tendency for collisions. Hash functions inside the JDK are not the exception. The main idea of a collision attack is finding two different messages, m1 and m2, such that hash(m1) = hash(m2). In this article, I would like to show that this problem is reproducible in every program written in Java and how to get around it.

Firstly, let's consider the internals of the hashcode function in java.lang.String:

Categories: Java

Deploying to Tomcat from Octopus Deploy

Tue, 2017-06-06 09:01

Octopus Deploy has a large collection of useful steps (both included and community provided) that can be used to deploy packages to a variety of different destinations and via different methods.

Fortunately, these same deployment steps can be used to deploy Java packages to Java web servers running in Linux out of the box.

Categories: Java

All About the Singleton

Tue, 2017-06-06 06:01

The Singleton design pattern is one of the simplest design patterns: It involves only one class throughout the application that is responsible for instantiating itself to make sure it creates no more than one instance. At the same time, it provides a global point of access to that instance. In this case, the same instance can be used from everywhere, being impossible to directly invoke the constructor each time.

There are various kinds of implementations, and I am going to explain them one by one.

Categories: Java

Running a JVM in a Container Without Getting Killed

Mon, 2017-06-05 22:01

No pun intended.

The JDK 8u131 has backported a nice feature in JDK 9, which is the ability of the JVM to detect how much memory is available when running inside a Docker container.

Categories: Java

Additional Considerations of the Java Ecosystem

Mon, 2017-06-05 18:01

To gather insights on the state of the Java ecosystem today, we spoke to nine executives who are familiar with the ecosystem.

We asked these experienced Java professionals "What have I failed to ask you that you think we need to consider about the Java ecosystem?" Here's what they told us (or asked us in return):

Categories: Java

Spocklight: Indicate Specification as a Pending Feature

Mon, 2017-06-05 12:01

Sometimes, we find ourselves working on a new feature in our code and we want to write a specification for it without yet really implementing the feature. To indicate we know the specification will fail while we are implementing the feature, we can add the @PendingFeature annotation to our specification method. With this annotation, Spock will still execute the test, but it will set the status to ignored if the test fails. But if the test passes, the status is set to failed. So when we have finished the feature, we need to remove the annotation — and Spock will kindly remind us to do so this way.

In the following example specification, we use the @PendingFeature annotation:

Categories: Java

An Intro to AssertJ and Collections

Mon, 2017-06-05 09:01

When programming in Java, you often end up writing methods returning a collection of objects. They certainly have their place in your application, but testing them can be a little tricky. Depending on the implementation of the underlying collection, the order of the elements may be different, the equals on collections is not always obvious, and so on. I have come across multiple examples of such cases in my career, and I decided to pick a couple of them and show a way to tackle them with AssertJ, the assertions library you should definitely be using.

All the recipes follow the same format. I present a short description, followed by the implementation of the test. The test is always successful, to avoid confusion. Each recipe ends with a short remark, like what other situations can this be used for. I’m also using the Guava library to create the collections, as vanilla Java doesn’t really provide a way to do that.

Categories: Java

9 Logging Sins in Your Java Applications

Mon, 2017-06-05 06:01

Logging runtime information in your Java application is critically useful for understanding the behavior of any app, especially in cases when you encounter unexpected scenarios, errors or just need to track certain application events.

In a real-world production environment, you usually don’t have the luxury of debugging. And so, logging files can be the only thing you have to go off of when attempting to diagnose an issue that’s not easy to reproduce.

Categories: Java

Parsing in Java (Part 1): Structures, Trees, and Rules

Sun, 2017-06-04 08:01

If you need to parse a language, or document, from Java there are fundamentally three ways to solve the problem:

  • Use an existing library supporting that specific language: for example a library to parse XML.
  • Building your own custom parser by hand.
  • A tool or library to generate a parser: for example ANTLR, which you can use to build parsers for any language.
Use an Existing Library

The first option is the best for well-known and supported languages, like XML or HTML. A good library usually also includes an API to programmatically build and modify documents in that language. This is typically more of what you get from a basic parser. The problem is that such libraries are not so common and they support only the most common languages. In other cases, you are out of luck.

Categories: Java

20 Leaders' Thoughts on What Makes Great Java Devs

Sat, 2017-06-03 06:01

Java remains one of the most popular programming languages. In our recent deep-dive into the hottest programming languages for 2017, Java landed second among the most-used programming languages and the languages with the most active repositories on GitHub – beat out only by JavaScript in both categories.

Aside from its widespread use, it’s also the most in-demand programming language among employers, with more job listings on Indeed (as of March 2017) seeking developers with Java skills than any other language. So naturally, if you’re one of the employers behind the 36,000+ job listings seeking Java developers or you’re a Java programmer looking for your next gig, the skills and characteristics that set great Java developers apart from the pack is crucial information. And if you’re a Java programmer looking for your next gig, knowing what skills you should level-up and what characteristics to promote to your prospective employers is good-to-know info.

Categories: Java

Using Java Flight Recorder Triggers [Video]

Fri, 2017-06-02 22:01

A good amount has been written and said about Java Flight Recorder, its integration into the Oracle Java SE Java Virtual Machine (JVM) and the very low overhead associated with enabling the framework. It not only makes the notion of collecting detailed runtime information about a Java application in production a possibility — it makes it a reality.

Many opt to place a program in Java Flight Recorder's Continuous Recording Mode. In this state, the Java application will collect runtime data indefinitely, where you can specify (or default to) how much data you want to retain before overwriting. Once in this mode, you can at any time, with many different options, dump the runtime information into a self-contained Flight Recorder file. From there, the Java Mission Control tool can be used to open this file to further diagnose your application's behavior.

Categories: Java