Java Lobby Announcements

Subscribe to Java Lobby Announcements feed
Recent posts in Java on DZone.com
Updated: 10 hours 8 min ago

Transactional Exception Handling in CDI [Snippet]

Wed, 2018-01-03 10:01
In Java EE, exceptions that are raised during the execution of a transactional business method cause the transaction to roll back. However, this is only the case for system exceptions, that is, runtime exceptions, which are not declared in the method signature.

For application exceptions, that is, checked exceptions, or any exception annotated with @ApplicationException, the transaction is not automatically rolled back. This sometimes causes confusion among enterprise developers.

For EJB business methods, the transactions can be forced to roll back on application exceptions as well by specifying @ApplicationException(rollback = true). However, this annotation is only considered if the managed bean in an EJB.

Categories: Java

Significant Software Development Developments of 2017

Wed, 2018-01-03 07:01

This post is my personal and opinionated assessment of some of the most significant developments related to software development in 2017. This is my eleventh year for this annual post and my previous years' assessments are available for 2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009, 2008, and 2007. As with these previous years' assessments, this assessment of 2017's major developments in software development are obviously biased, opinionated, and limited to my perspective.

I think it important to re-emphasize that although this is an opinion-heavy post, the opinions are not on whether a particular language, framework, or tool is "best" or "worst." Rather, the opinions come in when deciding which of these frameworks, languages, or tools had the biggest developments of the year.

Categories: Java

Spring, Spring Boot, and Component Scan

Tue, 2018-01-02 23:01

This guide will help you understand the most important concept in Spring — Component Scan. Spring Boot does some magic around Component Scan. Let’s understand that in this article.

You Will Learn
  • What is Component Scan?
  • Why is Component Scan important?
  • Which packages does Spring Boot scan automatically?
  • How do you define Component Scan with Spring Boot?
  • How do you resolve problems involving Component Scan?
@ComponentScan

If you understand Component Scan, you understand Spring.

Categories: Java

IntelliJ IDEA 2017.3: Support for Kotlin Multi-Platform Projects

Tue, 2018-01-02 19:01

The Kotlin plugin bundled with IntelliJ IDEA 2017.3 has been updated to Kotlin 1.2. The key new feature of Kotlin 1.2 is its support for multi-platform projects – projects where the same code is compiled to target the JVM or JavaScript. Such projects consist of common modules, containing platform-independent code, and platform-specific modules. To support calling the platform-specific APIs from common code, the common code can specify expected declarations, and then platform-specific modules need to provide the actual declarations. The IDE now supports creating and running multi-platform projects, as well as code editing and navigation assistance for expected and actual declarations.

Template Multi-platform Project

First of all, now it is possible to create a template project to start exploring the new Multi-platform projects feature.

Categories: Java

Caching Method Results With JCache

Tue, 2018-01-02 13:01

In JCache, there is a handy functionality that transparently caches the result of methods. You can annotate methods of managed beans with @CacheResult, and the result of the first call will be returned again without calling the actual method a second time.

import javax.cache.annotation.CacheResult; // ... public class Calculator { @CacheResult public String calculate() { // do some heavy lifting... LockSupport.parkNanos(2_000_000_000L); return "Hi Duke, it's " + Instant.now(); } }


Categories: Java

Creating Strings in JMeter

Tue, 2018-01-02 10:01

Strings, the most commonly used programming tool, are the main carrier of textual information in programs. This information is passed in the form of a sequence of characters. In Apache JMeter, Strings are used to output messages to the JMeter console.

For example, when we send an HTTP request using JMeter, we get a reply in the form of a byte array. In order for this response to become readable, it is converted to strings. When an API is tested and the specific data is cut out from the API response, for example when using the "Regular Expression Extractor", the cut out data will be represented as strings. These two examples are a small part of how widely strings are used, both in programming languages and in JMeter.

Categories: Java

Working With hashcode() and equals()

Tue, 2018-01-02 07:01

By default, the Java super class java.lang.Object provides two important methods for comparing objects: equals() and hashcode(). These methods become very useful when implementing interactions between several classes in large projects. In this article, we will talk about the relationship between these methods, their default implementations, and the circumstances that force developers to provide a custom implementation for each of them.

Method Definition and Default Implementation
  • equals(Object obj): a method provided by java.lang.Object that indicates whether some other object passed as an argument is "equal to" the current instance. The default implementation provided by the JDK is based on memory location — two objects are equal if and only if they are stored in the same memory address.

Categories: Java

Generating and Mocking Data With MockNeat

Mon, 2018-01-01 19:01

MockNeat is a new Java 8+ library that can be used to provision apps with initial sets of data that are valid from a business standpoint.

Data is arbitrarily generated by matching a set of criteria that can be programmatically defined, allowing developers enough flexibility to obtain specific arbitrary results matching their business needs.

Categories: Java

Configuring JMS in IBM WAS Liberty

Mon, 2018-01-01 12:01

Quite recently, we completed a project that needed simple JMS capabilities. A user would initiate an action on our website, get a prompt (e.g. USSD) on his/her mobile, respond to it, and feed this response to the web app. See the sketch below.

The WebSocket server and JMS engine are WAS Liberty servers, the auditing component is a WAS ND service, and the web application a JavaScript SPA.

Categories: Java

A Log Message Is Executable Code and Comment

Mon, 2018-01-01 07:01

Although there are differences of opinion regarding how many comments one should add to one's code, I think it's safe to say most developers would agree that the comment in the following code snippet is superfluous:

// increment the total total++;


Categories: Java

12 Java YouTube Channels You Should Follow in 2018

Sun, 2017-12-31 08:01

It’s almost the end of 2017. If you’re like me, you might be thinking about what you want to change or improve in 2018.

Maybe you want to learn more about Java and improve your development skills.

Categories: Java

What Is Project Amber in Java?

Sat, 2017-12-30 08:01

In this post, we’re going to delve into some details of the features being targeted in Project Amber, which was introduced in early 2017 by its lead and language architect Brian Goetz. This project aims to add some really cool beans to the Java programming language that improve the developer’s productivity when writing Java code.

As this is still work in progress, other features could be added to the project in the future. Even though these features may seem to have been addressed late in the Java timeline, it’s worth considering that the Java team has historically been rather cautious in introducing new features to evolve the language, as Goetz explains in a talk about the project.

Categories: Java

Partially Applied Functions in Scala

Fri, 2017-12-29 23:01

Scala, like many other functional languages, allows developers to apply functions partially. What this means is that, when applying a function, a developer does not pass in all the arguments defined by the function. But provides only for some of them, leaving remaining parameters to be passed later.

Once you have provided the required initial parameters, what you get back is a new function whose parameter list only contains those parameters from the original function that were left blank.

Categories: Java

Switch Expressions Coming to Java?

Fri, 2017-12-29 19:01

A JEP draft has been created with the title, "Switch Expressions for the Java Language." The current "Summary" states, "Extend the switch statement so that it can be used as either a statement or an expression, and improve how switch handles nulls. These will simplify everyday coding, as well as prepare the way for the use of pattern matching in switch." There are several promising characteristics of the proposed Java switch expression in its own right in addition to its enabling of the exciting Pattern Matching JEP (305).

The Java Tutorial defines a Java statement as a "complete unit of execution" that is "roughly equivalent to sentences in natural languages." It defines a Java expression as "a construct made up of variables, operators, and method invocations ... that evaluates to a single value." The current Java switch is a statement, but this draft JEP proposes that switch be supported as an expression as well.

Categories: Java

Currying Functions in Scala

Fri, 2017-12-29 17:40

Currying is named after Haskell Curry, an American mathematician. He is known for his work in combinatory logic.

Currying is a means of transforming a function that takes more than one argument into a chain of calls to functions, each of which takes a single argument.

Categories: Java

This Year in Spring: 2017

Fri, 2017-12-29 13:01

Hi, Spring fans! Welcome to another, albeit very special, installment of This Week in Spring! This is the last installment before 2018 and so we’ll take the opportunity to review, as we always do in the last installment of the year, this very exciting year in Spring and its ecosystem.

Let me, on behalf of the Spring and larger Pivotal team, be the first to wish you and yours a heartfelt happy and safe New Year! Let’s first look at some of the major trends that defined 2017. We’ve got a lot to cover!

Categories: Java

Start a New MVC Spec Project With MongoDB

Fri, 2017-12-29 13:01

The MVC, from Wikipedia, is a software architectural pattern that divides a given application into three interconnected parts. It is done to separate internal representations of information from the ways information is presented to, and accepted from, the user.

The MVC design pattern decouples these significant components, allowing for efficient code reuse and parallel development. MVC web frameworks can be categorized either as action-based or component-based. For decades, the Java Community was waiting for a specification that is action-based. Of course, the Java EE world already has Java Server Faces as a component-based. Finally, the action-based MVC is coming with Ozark.

Categories: Java

About Dependency Injection

Fri, 2017-12-29 10:01

When I first heard about Dependency Injection at my first workplace, it sounded very fancy to me, and, somehow, a bit scary. And, in combination with Spring, it looked like black magic. But after reading a bit about it, I think this expression "dependency injection is a 25-dollar term for a 5-cent concept" describes it perfectly. I don’t want to say that it is a cheap pattern: It is not! It is extremely helpful and a must-have in software development. But it is simple, and its simplicity makes this pattern simply brilliant.

So What Is It?

Let’s see a simple example to understand better what this means. Let’s build a simple payment service for an online shop. We have a cart with a list of products, and we create a method that iterates all the products and uses a cash payment service to pay for them.

Categories: Java

Server-Side Validators Using Functional Interfaces

Fri, 2017-12-29 07:01

Note: This post is inspired by and is an attempt at creating an extension to this post on Medium. As such, it will use some of the code in that post by Joel Planes.

As a Java developer, the most common task we have to do is to write some server-side validations for our model data so as to validate the incoming objects to our application. Sure there are frameworks like Hibernate Validator that are used to perform these validations, but sometimes, they are just not an option.

Categories: Java

Managing Randomness in Java

Thu, 2017-12-28 13:01

If you already had to manage some degree of randomness on Java, chances are that you've become acquainted with the Math.random() methods. However, the previous method returns a double. Beyond very basic use-cases, another option has to be considered in the form of the java.util.Random class.

Random An instance of this class is used to generate a stream of pseudorandom numbers.
Javadoc

This root class provides basic random-number-generation capabilities, nothing mind-blowing.

Categories: Java

Pages