Home » Java » Core Java

Core Java

Smaller Try-Blocks Are Better

It often happens, especially in Java, that a few places in the method are potential exception originators. Usually, we make a large method-size try block with a single catch at the bottom. We catch all the exceptions, usually even using grouping. This helps us minimize the noise, which is the exception catching. However, such large try blocks jeopardize maintainability: we ...

Read More »

Chaos Engineering – Metaspace OutOfMemoryError

JVM memory has following regions:  a. Young Generation b. Old Generation c. Metaspace d. Others region When you encounter ‘java.lang.OutOfMemoryError: Metaspace’ it indicates that the Metaspace region in the JVM memory is getting saturated. Metaspace is the region where metadata details that are required to execute your application are stored. In nutshell they contain Class definitions and method definitions of ...

Read More »

Inspect the contents of the Java Metaspace region

JVM Memory has following regions: a. Young Generation b. Old Generation c. Metaspace d. Others region To see what objects are stored in what region, you may refer to this video clip. Sometimes your application might run into ‘java.lang.OutOfMemoryError: Metaspace’ as discussed in this post. In such circumstances you might want to see what are the Contents loaded in the ...

Read More »

Java String intern(): Performance impact

java.lang.String#intern() is an interesting function in Java. When used at the right place, it has potential to reduce overall memory consumption of your application by eliminating duplicate strings in your application. To learn how intern() function works, you may refer to this blog. In this post let’s discuss the performance impact of using java.lang.String#intern() function in your application. intern() function ...

Read More »

In which region intern strings are stored?

intern() is an interesting function in java.lang.String object. intern() function eliminates duplicate string objects from the application and has potential to reduce overall memory consumption of your application. To understand how string intern() function works you may refer to this interesting blog. Intern strings are stored in a string pool in the JVM memory. JVM Memory has following regions: a. ...

Read More »

Garbage Collection CPU Statistics

When a Garbage Collection event runs, it spends a predominant amount of its time in the Java application layer. It also spends a certain portion of its time in the Operating System/Kernel layer.  ‘User’ Time: Amount of time Garbage Collector spends in the Java application layer is reported as ‘User’ time in the GCeasy report. Here are the reasons for ...

Read More »

Declarative and Immutable Pipeline of Transformations

A few months ago I made a small Java library, which is worth explaining since the design of its classes and interfaces is pretty unusual. It’s very much object-oriented for a pretty imperative task: building a pipeline of document transformations. The goal was to do this in a declarative and immutable way, and in Java. Well, as much as it’s ...

Read More »

The Case Against Logging

The one thing that all enterprise applications have in common, regardless of their framework, language, or communication protocols is that they produce logs, logs that are allegedly human-readable lines of strings that aim to help us to debug, trace, or otherwise inspect what’s going on. The question is, how useful are these logs and do they help us solve problems ...

Read More »

Reflection Means Hidden Coupling

Reflective programming (or reflection) happens when your code changes itself on the fly. For example, a method of a class, when we call it, among other things adds a new method to the class (also known as monkey patching). Java, Python, PHP, JavaScript, you name it—they all have this “powerful” feature. What’s wrong with it? Well, it’s slow, dangerous, and ...

Read More »