Home » Java » Core Java (page 5)

Core Java

Adapter Design Pattern In Java

The Adapter design pattern is a structural design pattern that helps us to connect to the legacy or third-party code that exposes a similar functionality through a different interface. A real-world analogy for an adapter is the one we use to connect our USB cable to an ethernet port. While designing an object-oriented application, we might feel the need for an adapter when say our ...

Read More »

Java: ChronicleMap Part 3, Fast Microservices

Standard Java Maps needs to be initialized upon startup. Learn how to leverage ChronicleMaps that is initializable from a file and reduce microservice startup times significantly and how to share Maps between JVMs. The built-in Map implementations, such as HashMap and ConcurrentHashMap are fast but they must be initialized with mappings before they can be used for looking up values. ...

Read More »

Java: ChronicleMap Part 2, Super RAM Maps

The standard Java Maps, such as the ubiquitous HashMap, are ultimately limited by the available RAM. Read this article and learn how you can create Java Maps with virtually unlimited sizes even exceeding the target machine’s RAM size. The built-in Map implementations, such as HashMap and ConcurrentHashMap work fine as long as they are relatively small. In all cases, they ...

Read More »

Java: ChronicleMap Part 1, Go Off-Heap

Filling up a HashMap with millions of objects will quickly lead to problems such as inefficient memory usage, low performance and garbage collection problems. Learn how to use off-heap CronicleMap that can contain billions of objects with little or no heap impact. The built-in Map implementations, such as HashMap and ConcurrentHashMap are excellent tools when we want to work with ...

Read More »

JEP 358: Helpful NullPointerExceptions

In the post “Better Default NullPointerException Messages Coming to Java?“, I summarized background details related to a draft JEP (at that time) regarding making some types of NullPointerException‘s (NPE’s) messages more useful. It was nice to see last week that this JEP is now a candidate JEP (JEP 358: “Helpful NullPointerExceptions”). In this post, I highlight aspects of JEP 358 ...

Read More »

Annotation Handling and JPMS

TLDR; Instead of annotation.getClass().getMethod("value") call annotation.annotationType().getMethod("value"). All Java developers have heard about annotations. Annotations are with us since Java 1.5 (or only 1.6 if you insist). Based on my experience interviewing candidates I feel that most Java developers know how to use annotations. I mean, most developers know that it looks like @Test, or @Override and that they come with ...

Read More »

JDBC – Emulating a sequence

Probably each of us encountered this problem at least once in the programmer’s life – how to emulate a database sequence? Below you may find my variation of this problem’s solution. Suppose that we have an interface defining the desired API for returning a sequence of integer numbers: 1 2 3 4 5 public interface Sequences {       int nextValue(String ...

Read More »

Running a Java class as a subprocess

Running a Java class (not a jar) as a subprocess is something I needed to do this week. More precisely, I wanted to spawn a new process from within a test, instead of running it inside the test directly (in-process). I don’t think this is anything fancy or a complex thing to do. But, this is not something I have ...

Read More »

Save your lambdas for a rainy day – save to file

Introduction A short post describing how a Java lambda can be persisted to a file for re-use in a different process. Serialising Lambdas Lambdas, introduced in Java 8 make functions first class citizens(nearly) in the Java language. They remove the need for a dedicated class to hold the function. But how does this work under the covers? In reality javac ...

Read More »