Java Lobby Announcements

Subscribe to Java Lobby Announcements feed
Recent posts in Java on
Updated: 13 hours 56 min ago

Synchronous or Asynchronous, and Why Wrestle With Wrappers?

15 hours 55 min ago

Have you ever wondered why you have to wrestle with CompletableFutures instead of “just writing code” like in the old days? Is it only for performance? Or maybe it’s just a fashion? Let’s find out!

Writing synchronous, blocking, procedural code seems simple. The business logic is expressed as a sequence of steps. When there is a need to do I/O, you synchronously call a blocking I/O method and further process the result. Calling a method which adds two numbers looks the same as calling a method which sends an HTTP request.

Categories: Java

CodeTalk: Jakarta EE's Cloud Native Opportunities [Podcast]

Tue, 2018-04-24 21:52

Thanks for tuning in to another episode of DZone's CodeTalk Podcast where hosts Travis Van and Travis Carlson have early conversations with the creators of new developer technologies. For the next few episodes, we'll be stepping outside of our usual coverage to interview a series of folks on Jakarta EE (the platform formerly known as Java EE) to hear from a number of perspectives on what the switch from Oracle governance to Eclipse means for developers.

Check back every Wednesday for a fresh episode, and if you're interested in being involved as a guest or have feedback for our hosts, scroll down to the bottom for contact information. Also be sure to check out the previous episode in our Jakarta series, where Travis and Travis both spoke with Mike Milinkovic, Executive Director of the Eclipse Foundation and Director of the Open Source Initiative, to talk about the Eclipse Foundation and what's in store for Jakarta EE and the specification process behind it.

Categories: Java

Recent Java Developments: Late April 2018

Tue, 2018-04-24 18:01

There have been several recent developments in the Java-sphere this week and I summarize some of them in this post.

The End of JavaOne as We Know It

In the post "JavaOne Event Expands with More Tracks, Languages and Communities - and New Name," Stephen Chin writes, "The JavaOne conference is expanding to create a new, bigger event that's inclusive to more languages, technologies and developer communities." He adds that it has been renamed to "Oracle Code One" and that this year's edition (the "inaugural year of Oracle Code One") will be held in San Francisco's Moscone West in late October (October 22-25, 2018).

Categories: Java

JWTs With Spring Boot and Java 9

Tue, 2018-04-24 12:01

JWT (JSON Web Token) is an open source standard commonly used to transmit data between two services in a compact and secure way. This standard offers a wide range of libraries to generate JWTs and includes libraries for platforms such as .NET, Python, Node.js, Java, JavaScript, Perl, Ruby, Elixir, Golang, Groovy, and Haskell. The code is available on GitHub.

  • Secure. JWTs are signed by using a secret or a public/private key pair.
  • Self-contained: all information is stored inside the JWT token. No need for further database calls.
  • Unmodifiable information, but exposed: Do not put secrets inside JWTs.
  • Compact format: JWTs are really small.
How Does It Work?

Categories: Java

Using Custom Classes as Keys in HashMaps

Tue, 2018-04-24 09:01

Today, we are going to discuss what we need to keep in mind when we want to use our custom class as a key in HashMap.

Here, we are considering an Employee class as a key having Id, Name, DateOfBirth, Salary as the properties.

Categories: Java

Reactive Programming With Spring WebFlux

Tue, 2018-04-24 06:01

Recently, we have been hearing about a new paradigm of coding that is gaining more and more attention, so-called Reactive Programming. Reactive Programming is a model of coding where communication mainly happens through a non-blocking stream of data. This model of programming makes your code "reactive," reacting to change and not being blocked, such as performing operations that read and waiting for responses from a database or file. Hence, in this manner, we enter in a mode where we are reacting to events as data becomes available. Its principles are based on the Reactive Manifesto.


One important concept is the concept of the backpressure. This is a mechanism that must ensure producers don't overwhelm consumers. So, for instance, if a consumer can't handle more than 100 HTTP requests per second, if this eventually occurs, the consumer must slow the flow, or even stop for a moment, until the situation gets normalized again.

Categories: Java

Understanding Java Keytool Keystore Commands

Mon, 2018-04-23 18:01

This guide will help you with the Java Keytool Keystore platform. We will show you which Java Keytool Keystore commands work for which process for certificate management.

This blog is a comprehensive guide on how Java Keytool Keystore commands are used to manage your digital certificate in Keystore. And, ultimately, it becomes a time saver for busy developers.

Categories: Java

DZone Research: The Myriad Uses of Java

Mon, 2018-04-23 12:01

To gather insights on the current and future state of the Java ecosystem, we talked to executives from 14 companies. We began by asking, "What are real-world problems being solved by Java today by your organization?" Here's what the respondents told us:

  • Content management, delivery, digital experience. Our platform geared toward a good ROI for web presence and extensibility. Java provides a good foundation to build from. There are a large number of APIs for extensibility.
  • Source code to deploy applications from Git to build, test, deploy a binary package to a Docker image to enable CI/CD.
  • The availability of developers. There are millions of Java developers. The libraries are important. Since the Equifax breach, companies are doing software composition analysis to look for known vulnerabilities. When there’s a known vulnerability, we see widespread attacks within a day. Tooling, manageability, libraries, and frameworks are all strengths of Java.
  • Writing automation tests that test not only how an application functions, but also what an application looks like. This means not just taking the screenshots of the application in various stages of the flow, but also not generating false positives when verifying that it looks the same as it did the last time the test was run successfully.
  • Serverless architecture (FaaS) RIFF from Pivotal. Running serverless on the edge since all of the data is event-driven.
  • Twitter, financial payment systems, automobiles, and artificial intelligence.
  • 1) As a developer of MMOs, Java’s ability to support high-speed concurrent processing is definitely something we take advantage of the most. Today, we can run around 2,000 simultaneous players on a single server which is possible, at least in part, because of Java. For comparison, other languages might only support perhaps 100 people on a server at once. 2) There’s another school of thought that doesn’t leverage concurrent programming and instead uses the database to resolve all concurrent issues. That approach is an order of magnitude slower which in turn makes it an order of magnitude more expensive because databases are really expensive systems. If you look at our datacenter, we spend ten times as much on our database servers than we do on everything else in our datacenter. By taking full advantage of concurrent processing we can reduce our database usage and reduce our overall cost compared to competing, single-threaded solutions.
  • Millions of users. Spring Boot and Spring Cloud integrate with our APIs.
  • One of the things that I am most excited about is using Java with a Function-as-a-Service engine, specifically Apache OpenWhisk.   FaaS will have a notable impact on the way developers build applications moving forward.   FaaS (aka Serverless) should have a bigger impact than the movement to microservices. In addition, some of our most interesting middleware technologies like Apache ActiveMQ Artemis is Java based.  This means Java developers who are leveraging this AMQP (or JMS) focused messaging broker can even run their Java debugger through the broker itself.   I consider that to be a substantial value-add to the average Java developer building their next generation of applications.
  • We enable our customers to keep a full record of what happens. Event sourcing keeps all state changes. Legal proceedings for online gambling, banking, analytics, electronic medical records for research, for compliance framework demands. Automatic tracking. Scalability which is important when you have a large number of transactions. Starting with microservices can be difficult to know where to start. Writing a monolith is hard to scale. Our structured framework goes from monolith to microservices that scale.
  • I'll write a few different use cases since I'm a contractor: 1) automating invoice handling and bookkeeping; 2) building cloud services for connectivity; 3) end-user systems that handle a lot of pressure (load wise)
  • Our product filters profanity from forms and databases for brand and reputation management of retailers, media companies, and data resellers. We also provide ID management for customer identification and access management. Developers are learning not to write this in-house. Passport is a regular security audit solution which scales to millions of customers. Java is particularly good at scaling.
  • Financial services’ feedback and infrastructure is enterprise Java. The preferred frontend UI is .NET and Eclipse. We serve as a very efficient bridge between the front end and the backend. Companies with big Java message services infrastructure want to connect with .NET business logic.

Here’s who we spoke to:

Categories: Java

Introduction to the Scala Type System

Mon, 2018-04-23 09:01

As programmers, we often come across a concept called type inference. To begin with, let me clarify that type inference is not something unique to Scala, there are many other languages like Haskell, Rust, and C# that have this language feature. Going by the bookish definition, “Type inference refers to the automatic detection of the data type of an expression in a programming language.” Speaking in layman's terms, it means the language is intelligent enough to automatically deduce the type of the expression, e.g. String, Int, Decimal, etc.

Having learned what type inference is, the next inevitable question is “Why?” The sole purpose of having type inference is to help the programmer avoid verbose typing but still maintain the compile-time type safety of a statically typed language. So speaking simply, type inference is the amalgamation of the best of static and dynamic typing.

Categories: Java

Switch Expressions: Enhancing Java Switch Statements

Mon, 2018-04-23 06:01

In late December of last year, I posted "Switch Expressions Coming to Java?" Since then, there has been significant discussion, expressed differences of opinion, and now a coalescence of general agreement regarding the future of switch expressions in Java. I have tried to capture some of the major developments related to switch expressions as comments on my December blog post. However, I felt like this week's Brian Goetz message title "[switch] Further unification on switch" on the amber-spec-observers mailing list warranted a new blog post on Java switch expressions.

Goetz opens his message with a reminder that the end game is not Java switch expressions. Instead, Goetz points out that "switch expressions are supposed to just be an uncontroversial waypoint on the way to the real goal, which is a more expressive and flexible switch construct that works in a wider variety of situations, including supporting patterns, being less hostile to null, use as either an expression or a statement, etc."

Categories: Java

JDK 11 and Proxies in a World Past sun.misc.Unsafe

Sun, 2018-04-22 07:01

With JDK 11, the first methods of sun.misc.Unsafe are being retired. Among them, the defineClass method was removed. This method has been commonly used by code generation frameworks to define new classes in existing class loaders. While this method was convenient to use, its existence also rendered the JVM inherently unsafe, just as the name of its defining class suggests. By allowing a class to be defined in any class loader and package, it became possible to gain package-scoped access to any package by defining a class within it, thus breaching the boundaries of an otherwise encapsulated package or module.

With the goal of removing sun.misc.Unsafe, the OpenJDK started offering an alternative for defining classes at runtime. Since version 9, the MethodHandles.Lookup class offers a method defineClass similar to the unsafe version. However, the class definition is only permitted for a class that resides in the same package as the lookup's hosting class. As a module can only resolve lookups for packages that are owned by a module or that are opened to it, classes can no longer be injected into packages that did not intend to give such access.

Categories: Java

SOLID Design Principles Explained: Interface Segregation

Sat, 2018-04-21 06:01

The Interface Segregation Principle is one of Robert C. Martin’s SOLID design principles. Even though these principles are several years old, they are still as important as they were when he published them for the first time. You might even argue that the microservices architectural style increased their importance because you can apply these principles also to microservices.

Robert C. Martin defined the following five design principles with the goal to build robust and maintainable software:

Categories: Java

Mastering Java 8 Streams (Part 4) [Video]

Fri, 2018-04-20 22:01

One of the more advanced (but incredibly useful) streams methods is the reduce method. What does it do? When would you use it? What does reduce have to do with Donald Trump and his wives and children? 

Find out in the next episode of the Master Java 8 streams series!

Categories: Java

Waiting for Tasks With Phaser

Fri, 2018-04-20 18:01

The class Phaser lets you wait for a flexible number of tasks executed in other threads. Use the method register to add a task you want to wait for. Call arrive to signal that a registered task is finished. And call awaitAdvance to wait until all registered tasks are finished. We will see how to use it by looking at a real-life example. But first, how does it work?

How Does Phaser Work?

The class Phaser works in phases. You register tasks for all phases by calling the method register. You signal that a task is finished for this phase by calling arrive. When all registered tasks have arrived for this phase, the Phaser starts a new phase and you can start over again. The following shows this for the first phase, phase zero:

Categories: Java

How to Read and Write a CSV File Using Core Java [Snippet]

Fri, 2018-04-20 12:01

A CSV is a comma-separated values file that allows data to be saved in a table-structured format.

Let's try to read a CSV file using Java and filter out the required rows and create a new CSV, as per our own requirements.

Categories: Java

Get to Know JSON Binding (Part 2)

Fri, 2018-04-20 09:01

The Java API for JSON Binding (JSON-B) 1.0 strengthens the Java EE platform's overall support for the JSON data interchange format. Already, the Java API for JSON Processing (JSON-P) 1.1 has proved popular, and together, they form the perfect partners that fill a long-standing shortcoming in Java EE's JSON capacity.

The next article in this series covers the customization of JSON Binding operations.

Categories: Java

Spring Boot Actuator in Spring Boot 2.0

Fri, 2018-04-20 06:01

In this post, we will take a closer look at Spring Actuator and highlight some changes in Spring Boot 2.0. We will discuss some of the endpoints and will create a custom endpoint to our application. The sources can be found at GitHub.

What Is Spring Boot Actuator?

Spring Boot Actuator supplies several endpoints in order to monitor and interact with your application. It does so by providing built-in endpoints, but you are also able to build your own endpoints. In the next sections, we will create a dummy application, enable the Actuator endpoints, provide the version and build information to it, add security to the endpoint, and customize an endpoint to our needs.

Categories: Java

OSGL Tool (Part 2): Extending the Power of Image Processing

Thu, 2018-04-19 22:01

In the previous article, OSGL Tool: The Art of Image Processing, we introduced how to uset he OSGL Img utility to process images, including:

  • Cutting
  • Resizing
  • Watermarking
  • Flipping
  • Blurring
  • Concatenation
  • Using a pipeline to process images

In this article, we will talk about how to extend OSGL Img with a customized image processor.

Categories: Java

Java 8: ConcurrentHashMap Atomic Updates

Thu, 2018-04-19 18:01

Whilst doing some refactoring on updates to ConcurrentHashMap values, I came across these great articles ...

... and was inspired to try to develop the theme a bit further.

Categories: Java

Software Design Principles DRY and KISS

Thu, 2018-04-19 12:01

In this article, I am going to explore software design principles and their benefits, why design principles are useful for us, and how to implement them in our daily programming. We will explore the DRY and KISS software design principles.

The DRY Principle: Don't Repeat Yourself

DRY stand for "Don't Repeat Yourself," a basic principle of software development aimed at reducing repetition of information. The DRY principle is stated as, "Every piece of knowledge or logic must have a single, unambiguous representation within a system."

Categories: Java