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

Generic Segment Tree

In this post, we are going to create a Generic Segment Tree. Before creating a Generic Segment Tree, we will try to solve a basic segment tree problem and try to find what part of our code is problem specific and abstract it out i.e there are some things which are common in any segment tree problem like creating the tree, querying the tree, etc. We will try to identify the piece of logic which is specific to our problem....

February 20, 2021 · 3 min · Vivek Bhadauria

git rebasing - rewrite history

In this post, I am going to discuss a scenario where I had to use “git rebasing” for something other than squashing commits. Lets build up from the starting, I am going to use a short form “CR” for code review. When I have to work on a feature, I generally cut a branch from the mainline and start development on it. git checkout -b feature-branch-101 The above command will create a branch named “feature-branch-101” and make it the current branch....

January 8, 2021 · 4 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

Add BasicAuth in SparkJava Webapp

In this post, I am going to show you how to add Basic Authentication to your SparkJava webapp in Kotlin. Spark Java : Its a micro-framework for creating web applications in Kotlin and Java 8 with minimal effort. Basic Authentication : Its simply an Authorization header whose value is Basic base64encode(usename:password) So if username and password is admin and admin. Base64 encoding of admin:admin is YWRtaW46YWRtaW4= Value of header will be...

September 25, 2019 · 2 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

Use Psiphon on Mac OS And Linux

Psiphon is a tool that gives you uncensored access to internet content. Currently Psiphon is available for Android, iOS and Windows. This post will take you through steps to get uncensored access to internet content on you Mac and Linux machines. NOTE : You need an Android Device as we will be routing traffic from MAC and Linux machines to the Android device. Download Psiphon App on your Android Device Go to Play Store and install Psiphon app....

November 18, 2018 · 4 min · Vivek Bhadauria

Using iText To Edit PDF In Android

In this article, we are going to learn how to integrate and use iText library to edit PDFs in Android. You app idea might require you to create or edit PDF as an intermediate or final step. iText is the best library to create or edit PDFs. Integrate iText in your Project Adding iText is similar to adding any other library/dependency in your android project. Add statement below in you app....

August 13, 2018 · 3 min · Vivek Bhadauria