Home » Java » Core Java » Page 10

Core Java

JEP 355 Text Blocks in JDK 13

JDK 13 went GA on September 17th, 2019 and the prominent new features are listed here. One of the new features is “text blocks”. This allows writing multiline strings easily without the need for concatenation while splitting into different lines. Lets quickly look at the different ways of creating multiline strings: String aBlock = """ SELECT id, first_name, last_name, dob FROM ...

Read More »

Is your JVM leaking file descriptors – like mine?

Foreword: The two issues described here, were discovered and fixed more than a year ago. This article only serves as historical proof, and a beginners’ guide on tackling file descriptor leaks in Java. In Ultra ESB we use an in-memory RAM disk file cache for fast and garbage-free payload handling. Some time back, we faced an issue on our shared ...

Read More »

The Structural Bug

A team member was having a bit of trouble with the following code: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 void extractData(String targetUri) {     Path tempFile = createTempFilePath();     extractDataToPathAndUpload(tempFile, targetUri);     cleanUp(tempFile); }   void extractDataToPathAndUpload(Path tempFile, String targetUri) {    try (FileOutputStream stream = createOutput(tempFile)) {       // extract from db to file stream ...

Read More »

Date/Time Printing Can Be Elegant Too

I owe my pretty high StackOverflow reputation to this question in particular, which I asked a few years ago: How do you print an ISO 8601 date in Java? It managed to collect a lot of upvotes since then and 20+ answers, including my own one. Seriously, why didn’t Java, such a rich ecosystem, have a built-in out-of-the-box simple solution ...

Read More »

Handling repeated code automatically

In this article I will describe how you can use Java::Geci generator Repeated to overcome the Java language shortage that generics cannot be primitive. The example is a suggested extension of the Apache Commons Lang library. Introduction When you copy-paste code you do something wrong. At least that is the perception. You have to create your code structure more generalized ...

Read More »

Pub/Sub local emulator

Pub/Sub is a nice tool provided by GCP.  It is really handy and can help you with the messaging challenges you application might face. Actually if you work with GCP it is the managed messaging solution that you can use. As expected working with the actual Pub/Sub solution comes with some quota, so for development it is essential to use ...

Read More »

Can/Should I use parallel streams in a transaction context?

Introduction To make a long story short, you should not use transactions within a parallel stream. This is because each thread in the parallel stream has its own name thus it does participate in the transaction. The Streams API is designed to work correctly under certain guidelines. In practice, to benefit from parallelism, each operation is not allowed to change ...

Read More »

Double Check Locking in Java

In this post, we’ll be taking a look at some techniques of creating a Singleton object in RxJava. Most importantly, we’ll be learning about double check locking in java. Singleton pattern in java is a creational pattern. Over time there have been concerns about the usage and implementation of Singleton pattern. This results from some very fundamental problems with the ...

Read More »

Identifying Code Smells In Java

As a software developer, it’s our responsibility to not only write code that works but rather write code that’s maintainable. Martin Fowler in his book Refactoring: Improving the design of existing code defines a code smell as: A surface indication that usually corresponds to a deeper problem in the system Refactoring is a process of improving the internal structure of ...

Read More »