Annotations in Java

Annotations are one of those features of Java whose working is not much clear to the developers. This post is for self reference for annotations in java. Some example of annotations below - @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface FunctionalInterface { } @Target(ElementType.METHOD) @Retention(RetentionPolicy.SOURCE) public @interface Override { } Any annotation has a retention policy attached to it. There are 3 types of “Retention Policy” SOURCE -> These annotations are in source code only....

March 26, 2021 · 2 min · Vivek Bhadauria

Integer Cache in Java

Before starting with the post, try to find the output for below code snippet: Integer a = 100; Integer b = 100; System.out.println(a == b); Integer c = 1000; Integer d = 1000; System.out.println(c == d); Note the answer somewhere, we will come back to it after looking at some concepts which will help in answering this. Auto-boxing and Auto-unboxing in Java Integer i = 2 doesn’t make sense as i is an object reference and you are assigning it a literal....

June 28, 2020 · 3 min · Vivek Bhadauria
Streams in JAVA

Streams in Java

In this post, we are going to discuss about: what streams are in context of CS their support in Java lazy evaluation in streams how to create finite and infinite streams how streams along with functions help in writing declarative code Stream by definition is a sequence of data which can be finite or infinite. Wikipedia: Stream is a sequence of data elements made available overtime. A Stream can be thought of as items on conveyer belt being processed one at a time rather than in batches....

June 12, 2020 · 7 min · Vivek Bhadauria

Tinkering with Xms in JVM

In this post, I am going to share my observation after playing with Xms parameter in JVM on different Operating Systems. Initially, my understanding of Xms was that Xms is the minimum heap space the JVM should get before starting the Java process, if this much main memory (RAM) isn’t available then program should not start. So I wrote a simple program which just outputs a String. // Simple program that I ran with different Xms values public class Test { public static void main(String[] args) { System....

May 9, 2020 · 3 min · Vivek Bhadauria

Mocking with Mockito

This is going to be a short post about an issue that I faced in my office project. Context: I was working on a project that generates an output file based on the data that is read by some input files. Now the size of the input files can vary and in my case, it went up to 50GB. So when the program was executing on the cloud environment (will call ENV further in post), there wasn’t enough space left in the PVC (Persistant Volume Claim) for this file and the program crashed due to full PVC....

July 19, 2019 · 3 min · Vivek Bhadauria