Topics Search


Home » Java (4033)
  • Page 1 of 202
  • »

Java 8 Stream findFirst() vs. findAny()

Java 8 Stream findFirst() vs. findAny() Icon
The Java 8 Stream API introduced two methods that are often being misunderstood: findAny() and findFirst(). In this quick tutorial, we will be looking at the difference between these two methods and when to use them.

Spring Cloud Sleuth in a Monolith Application

Spring Cloud Sleuth in a Monolith Application Icon
In this article, we’re introducing Spring Cloud Sleuth – a powerful tool for enhancing logs in any application, but especially in a system built up of multiple services. And for this writeup we’re going to focus on using Sleuth in a monolith application, not across microservices. We’ve all had the unfortunate experience of trying to diagnose a problem with a scheduled task, a multi-threaded operation, or a complex web request. Often, even when there is logging, it is hard to tell what actions need to be correlated together to create a single request.

JSON Processing in Java EE 7

JSON Processing in Java EE 7 Icon
This article will show you how to process JSON using only core Java EE, without the use of third-party dependencies like Jersey or Jackson. Pretty much everything we’ll be using is provided by the javax.json package.

A Guide to LinkedHashMap

A Guide to LinkedHashMap Icon
In this article, we are going to explore the internal implementation of LinkedHashMap class. LinkedHashMap is a common implementation of Map interface. This particular implementation is a subclass of HashMap and therefore shares the core building blocks of the HashMap implementation. As a result, it’s highly recommended to brush up on that before proceeding with this article.

Java RMI – Distributed objects example

Java RMI – Distributed objects example Icon
In Java RMI Hello World example we introduced the Java Remote Method Invocation with a very basic String-based communication between Server-Client. In this example we will take it one small step further and introduce Server-Client communication using Distributed Objects.

Swing – Keep dialog window up

Swing – Keep dialog window up Icon
The most common (and simple) way to implement a dialog in our application is the JOptionPane class. In this article we will discuss how to “overwrite” the default behaviour of JOptionPane that closes the dialog window when the user clicks a JOptionPane-created button. What we need to know before we move on to the examples is that when we use a JOptionPane in our application what really runs behind the scenes is a modal JDialog. JOptionPane is a container that automatically creates a JDialog and adds itself to it’s content pane.

Guide to Spring Retry

Guide to Spring Retry Icon
Spring Retry provides an ability to automatically re-invoke a failed operation. This is helpful where the errors may be transient in nature (like a momentary network glitch). Spring Retry provides declarative control of the process and policy-based behavior that is easy to extend and customize. In this article, we’ll see how to use String Retry to implement retry logic in Spring applications. We’ll also configure listeners to receive additional callbacks.

Guide to the Guava BiMap

Guide to the Guava BiMap Icon
In this tutorial, we’ll show how to use the Google Guava’s BiMap interface and its multiple implementations. A BiMap (or “bidirectional map”) is a special kind of a map which maintains an inverse view of the map while ensuring that no duplicate values are present and a value can always be used safely to get the key back. The basic implementation of BiMap is HashBiMap where internally it makes use of two Maps, one for the key to value mapping and the other for the value to key mapping.

How to replace the TABLE identifier generator with SEQUENCE or IDENTITY

How to replace the TABLE identifier generator with SEQUENCE or IDENTITY Icon
As previously explained, the TABLE identifier generator does not scale, so you should avoid id. However, some enterprise applications might need to run on both MySQL (which does not support database sequences), as well as Oracle, PostgreSQL and SQL Server 2012. This is article is going to explain how easily you can achieve this goal using the JPA mapping overriding.

Java Swing – Draw shapes dynamically example

Java Swing – Draw shapes dynamically example Icon
In this article we create an application that randomly puts shapes on a JPanel. The user can choose between the different shapes our application supports as well as the amount that will be drawn. As a design decision our application can make circles and stars. You can download the example at the end of the article and experiment with more shapes, random colours, random sizes etc.

Reflection vs Encapsulation

Reflection vs Encapsulation Icon
Historically reflection could be used to break into any code that ran in the same JVM. With Java 9 this is going to change. One of the two main goals of the new module system is strong encapsulation; giving modules a safe space into which no code can intrude. These two techniques are clearly at odds so how can this stand off be resolved? After considerable discussions it looks like the recent proposal of open modules would show a way out.

Using Java Comparator

Using Java Comparator Icon
The Java API library provides interfaces solely to establish a system of ordering on the objects of a class. They can be imposed implicitly as its natural principle of ordering or explicitly appended to customize the order as per requirement. This principle of ordering relies on the meaningful comparison method as implemented by the classes. These interfaces are basically comparators: one provided in the java.lang library, and another in the java.util package called Comparable and Comparator, respectively.

Exceptions in Java 8 Lambda Expressions

Exceptions in Java 8 Lambda Expressions Icon
In Java 8, Lambda Expressions started to facilitate functional programming by providing a concise way to express behavior. However, the Functional Interfaces provided by the JDK don’t deal with exceptions very well – and the code becomes verbose and cumbersome when it comes to handling them. In this article, we’ll explore some ways to deal with exceptions when writing lambda expressions.

Property Based Testing with Javaslang

Property Based Testing with Javaslang Icon
Usual unit testing is based on examples: We define the input for our unit and check for an expected output. Thus, we can ensure that for a specific sample our code works right. However, this does not prove the correctness for all possible inputs. Property based testing, also called property checking, takes another approach by adhering to the scientific theory of Falsifiability: As long as there is no evidence that a proposed property of our code is false, it is assumed to be true. In this article we are using Javaslang‘s API for property based testing to verify a simple FizzBuzz implementation.

Sorting in Java

Sorting in Java Icon
This article will illustrate how to apply sorting to Array, List, Set and Map in Java 7 and Java 8. Let’s start by sorting integer arrays first using Arrays.sort() method. We’ll define the following int arrays in a @Before jUnit method:

Java – Hybrid Cryptography example

Java – Hybrid Cryptography example Icon
Hybrid Cryptography is the silver lining between safe, but slow cryptography over big data (Asymmetric Cryptography) and unsafe but fast cryptography (Symmetric Cryptography). Hybrid Cryptography combines the speed of One-Key encryption and decryption along with the security that the Public-Private Key pair provides and thus considered a highly secure type of encryption.

JPA optimistic lock exception in Java Development

JPA optimistic lock exception in Java Development Icon
This post explains the JPA technology and its use in java development. Experts of java development India are explaining the use case of technologies- JPA and Hibernate, MySql database, Maven. Read this post and know what they want to say.

A Guide To NIO2 File Attribute APIs

A Guide To NIO2 File Attribute APIs Icon
In this article, we are going to explore one of the advanced features of the Java 7 NIO.2 filesystem APIs – specifically file attribute APIs. We have previously covered the File and Path APIs if you want to dig deeper into these foundational pieces first. All the files required to handle filesystem operations are bundled up in the java.nio.file package:

A Guide To NIO2 FileVisitor

A Guide To NIO2 FileVisitor Icon
In this article, we are going to explore an interesting feature of NIO2 – the FileVisitor interface. All operating systems and several third party applications have a file search function where a user defines search criteria. This interface is what we need to implement such a functionality in a Java application. Should you need to search for all .mp3 files, find and delete .class files or find all files that haven’t been accessed in the last month, then this interface is what you need.

Java Thread – Mutex and Semaphore example

Java Thread – Mutex and Semaphore example Icon
Java multi threads example to show you how to use Semaphore and Mutex to limit the number of threads to access resources. Semaphores – Restrict the number of threads that can access a resource. Example, limit max 10 connections to access a file simultaneously...
Home » Java (4033)
  • Page 1 of 202
  • »