Subscribe: Javalobby - The heart of the Java developer community
http://www.javalobby.org/rss/rssthreads.jsp?forumID=61
Added By: Feedage Forager Feedage Grade A rated
Language: English
Tags:
atomic  creating  data  java  layer  method  options  rest web  rest  service  spring  system  thread  web service  web 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Javalobby - The heart of the Java developer community

DZone Java Zone



Recent posts in Java on DZone.com



 



Saving Data to CSV Files With Java Through JMeter

Mon, 25 Sep 2017 16:01:01 GMT

Creating CSV files with Java through Apache JMeter is a convenient and easy way to form and to update your CSV files. Instead of creating the CSV file separately, you can complete your whole work process in one place — in JMeter. In this blog post, I will show you how to read and write CSV files through JMeter, and how to save data with them. This should be part of a longer test script you have, which uses the data from the CSV file for the load testing scenario.

Let’s get started.




Adding EntityManager.refresh to All Spring Data Repositories

Mon, 25 Sep 2017 10:01:01 GMT

In my previous post, Access the EntityManager from Spring Data JPA, I showed how to extend a single Spring Data JPA repository to access the EntityManager.refresh method. This post demonstrates how to add EntityManager.refresh to all Spring Data repositories.

Source Code

The first step is to define your interface:




Akka HTTP: Another One Validation Direction

Mon, 25 Sep 2017 07:01:02 GMT

The question today is how to validate an HTTP request body using Akka HTTP directives. Of course, we can use the validate directive, but it has one drawback, which I described in my previous post about a model validation in Akka HTTP. You may want to use the require method, but it is not very functional. Today, I want to show another way to validate HTTP request bodies in Akka.

Validation Problem

Let’s assume we have a REST endpoint that works with the following data model:




Java Microservice Communication: Avoiding Problems

Mon, 25 Sep 2017 04:01:01 GMT

In a previous post, I showed you how to build a microservice with Java EE and JBoss Forge. But building one microservice is obviously not enough. The overall idea of this architectural style is to implement an application as a system of services. In the beginning, that seems like an easy task. As long as each service solves only one problem and doesn’t need to call other services, you can keep its complexity low, and it will be easy to understand.

But if you think back to all the applications you’ve built during your career as a software developer, were there any applications that required the implementation of several independent tasks which didn’t interact with each other?




Creating a REST Web Service With Java and Spring (Part 4)

Sun, 24 Sep 2017 09:01:01 GMT

Running and Consuming the Web Service

Since we are using Maven to manage the dependencies and build the lifecycle of our application, and Spring Boot to configure our application, we can build our project and start the HTTP server using the following command (once Maven has been installed):

mvn spring-boot:run

This will host the REST web service on http://localhost:8080. If we look closely at the output, we can see the following statements:




A Guide to Spring Framework Annotations

Sun, 24 Sep 2017 05:01:31 GMT

The Java programming language provided support for annotations from Java 5.0 onward. Leading Java frameworks were quick to adopt annotations, and the Spring Framework started using annotations from the 2.5 release. Due to the way they are defined, annotations provide a lot of context in their declaration.

Prior to annotations, the behavior of the Spring Framework was largely controlled through XML configuration. Today, the use of annotations provide us tremendous capabilities in how we configure the behaviors of the Spring Framework.




Creating a REST Web Service With Java and Spring (Part 3)

Sat, 23 Sep 2017 10:01:00 GMT

Implementing the Presentation Layer

Without the aid of a web application framework, creating a presentation layer would be a daunting task, but after many years, the patterns and conventional designs of RESTful web services have been captured in the Spring Model-View-Controller (MVC) framework. This framework allows us to create RESTful endpoints with much the same ease as we saw during the development of our data source layer, using annotations and helper classes to do most of the heavy lifting for us.

Starting with the class that is the most depended on and requires the least dependencies, we will create the OrderResource first:




Getting the Most Out of the Java Thread Pool

Sat, 23 Sep 2017 05:01:49 GMT

The thread pool is a core concept in multithreaded programming that, simply put, represents a collection of idle threads that can be used to execute tasks.

First, let’s outline a frame of reference for multithreading and why we may need to use a thread pool.




Using Atomic Methods to Write Thread-Safe Classes

Fri, 22 Sep 2017 20:01:01 GMT

The classes in the package java.util.concurrent use atomic methods to update their internal state in a thread-safe way. In this article, you will see how to write and use such atomic methods to create thread-safe classes.

Atomic Methods

A method is atomic if it is "all or nothing." If a thread reads the data, the thread can only see the state before or after the execution of the atomic method — no intermediate state. After the atomic method was executed successfully, the changes are visible to all threads. The atomic method only modifies data of its own object without side effects. Here are some examples of atomic methods.




Java 9: It's Heeeere

Fri, 22 Sep 2017 17:16:54 GMT

After months of delays, waiting, and rework, JDK 9 arrived yesterday!

Whether you're in it for the JPMS, JShell, convenience factory methods, and/or any of the myriad other features introduced, chances are that you're over the moon. So, instead of rehashing the long, storied journey of Project Jigsaw or touching on what REPL means for Java, let's cut to the chase and get the tools you want into your hands, then take a look around the web to see what's going on.




Java 9 and IntelliJ IDEA

Fri, 22 Sep 2017 16:01:01 GMT

Java 9 was just released, so let’s do a quick recap of the Java 9 support in IntelliJ IDEA and have a peek at some of the upcoming features in IntelliJ IDEA 2017.3 for Java 9.

Jigsaw and the JPMS

The big feature for Java 9 is, of course, the Java Platform Module System (JPMS), which comes under the umbrella Project Jigsaw. Jigsaw itself is a much bigger undertaking and includes things like the modularisation of the JDK itself, what’s interesting to us as developers is the JPMS.




Supporting Kojo

Fri, 22 Sep 2017 10:01:01 GMT

Back in May 2017, we launched our annual charity survey that looked into the rapidly evolving Fast Data, Streaming, and IoT ecosystem. We're thrilled that we received over 2400 responses, reaching our $5,000 donation goal for the Kogics Foundation, a public charitable trust in India run by Lalit Pant that provides free education to underprivileged children (including programming in Scala via Kojo), financial and in-kind help to the poor, and even medical assistance to those in need.

To learn more about Kojo and the Kogics Foundation plans for the future, we prepared this interview with Lalit. Enjoy!




A Clarified String Formatting Cheatsheet

Fri, 22 Sep 2017 07:01:03 GMT

The Java documentation of String formatting is not the easiest to read and understand if you are not familiar with String formatting or just want a quick solution. Although it is complete, it is not very user-friendly, so I thought I would try and write a clearer version. This article is as much for you as it is an aide memoir for myself.

The Format Methods

There are two methods that provide String formatting behavior: format() and printf(). The format() method is a static method of the String.class, and the printf() method is a method of the static System.out.class. They both behave exactly the same way and have the same signature.




Creating a REST Web Service With Java and Spring (Part 2)

Fri, 22 Sep 2017 05:01:30 GMT

Implementing the Web Service

Finding where to start can be difficult, but we will take a systematic approach to creating our web service. Start with the layer that depends on the fewest other layers and is depended on by the greatest number of layers. Thus, we will first implement the domain layer, which does not depend on the other two layers but is depended on by both. Then we will implement the data source layer, which depends on the domain layer and is likewise depended on by the presentation layer. Lastly, we will implement the presentation layer, which is not depended on by any other layer but depends on both the data source and domain layers.

Implementing the Domain Layer

The first step in creating our RESTful web service is creating the domain layer. While our domain layer is very simple, we will soon see that it requires some very specific details to be accounted for in order to be properly used by the rest of our system. The first of these details is identity.




Three Productive Go Patterns to Put on Your Radar

Fri, 22 Sep 2017 04:01:00 GMT

By most definitions, with just 26 keywords, a terse spec, and a commitment to orthogonal features, Go is a simple language. Go programmers are expected to use the basic building blocks offered by the language to compose more complex abstractions. Over time, best-in-class solutions to frequently encountered problems tend to be discovered, shared, and replicated. These design patterns draw heritage from other languages, but often look and feel distinct in Go. I'd like to cast a spotlight on three patterns I use over and over again.

The Dependency Injection Pattern

(image)

Dependency injection (DI) is actually an umbrella term that can mean vastly different things depending on context. The core idea is this: Give or inject dependencies to a component, rather than have the component take dependencies from the environment. Beyond that, things can get a little complicated. Some people use DI to refer to dependency injection frameworks, typically a package or object into which you register dependencies and later inject them into components that use them, usually by some key schema. But this style of DI isn't a good match for Go, primarily because Go lacks the dynamic typing required to serve a literate API. Most DI frameworks in Go resort to stringly typed keys (meaning variables are often typed as strings), and rely on reflection to reify the dependencies to concrete types or interfaces, which is always a red flag.




Enum: Using the Name() and toString() Methods Correctly

Thu, 21 Sep 2017 20:01:01 GMT

The Java Enum has two methods that retrieve that value of an enum constant, name() and toString(). The toString() method calls the name() method, which returns the string representation of the enum constant. In listing 1, the value returned by calling the name() and toString() on an Animal.DOG constant method is DOG.

Listing 1: Animal Enum:




Java Command-Line Interfaces (Part 14): google-options

Thu, 21 Sep 2017 16:01:02 GMT

The GitHub page for google-options states that google-options is a "command line argument parsing library from the folks at Google (Java)." The page goes on to say, "This is the command-line arguments parser from the Bazel Project. The com.google.devtools.common.options package has been split out into a separate jar for general utility." This blog post demonstrates applying google-options to processing command line options from Java code.

The example used in this post to demonstrate google-options is similar to the examples used in the earlier thirteen posts in this series on processing command line options in Java. This example supports two options: a required file path/name option expecting a String argument with that path and name and a verbosity option with no argument (its existence enables verbosity). Only the most relevant portions of the code will be shown in this post, but the full code is available on GitHub.




Testing Time-Based Reactor Core Streams With Virtual Time

Thu, 21 Sep 2017 10:01:01 GMT

Reactor Core implements the Reactive Streams specification and deals with handling a (potentially unlimited) stream of data. If it interests you, do check out the excellent documentation it offers. Here I am assuming some basic familiarity with the Reactor Core libraries Flux and Mono types and will cover how Reactor Core provides an abstraction to time itself to enable the testing of functions that depend on passage of time.

For certain operators of Reactor Core, time is an important consideration — for example, a variation of an "interval" function that emits an increasing number every 5 seconds after an initial "delay" of 10 seconds:




Creating a REST Web Service With Java and Spring (Part 1)

Thu, 21 Sep 2017 09:01:38 GMT

In the modern world of interconnected software, web applications have become an indispensable asset. Foremost among these web applications is the Representational State Transfer (REST) web service, with Java becoming one of the most popular implementation languages. Within the Java REST ecosystem, there are two popular contenders: Java Enterprise Edition (JavaEE) and Spring. While both have their strengths and weaknesses, this article will focus on Spring and create a simple order management RESTful web application using Spring 4. Although this management system will be simple compared to the large-scale RESTful services found today, it will nonetheless demonstrate the basic thought process, design decisions, and implementation tests required to create a Level 3 (hypermedia-driven) Spring REST web service.

By the end of this article, we will have created a fully functional Spring REST order management system. While the source code illustrated in this article covers the essential aspects of the order management system, there are other components and code (such as test cases) that support the main service that are not shown. All of the source code, including these supporting aspects, can be found in the following GitHub repository:




Project Comprehension: Understanding Java Projects Efficiently

Thu, 21 Sep 2017 07:01:01 GMT

Let's start with a bit of theory.

A modern Java application is a complex system that frequently operates as a node in a larger enterprise network. By the time a new developer joins the team, the project will likely have been in development for a couple of years and contain code contributions from dozens of developers, most of whom left the project long ago. Documentation is not always up-to-date and accurate, and only a few team members may have a comprehensive picture of the project (whom you'll have to catch for short Q&As in between meetings, code reviews, and emergency deployments).