1-n-list-in-java

How to Generate List from 1 to N in Java

There are multiple ways to generate the list from 1 to N or M to N in Java. We will look at 3 with various versions of Java. Using Simple For Loop Just iterate from 1 to N in for a loop and add it to the list. int n = 10; List<Integer> list = new ArrayList<>(n); // 1 to n (inclusive) for (int i = 1; i <= n; i++) { list.add(i); } Using IntStream - Java 8 Using IntStream’s range for end exclusive and rangeClosed for end inclusive. Here is how. ...

October 15, 2023 · 1 min · Imran Shaikh
How to Achieve Greatness in JDBC Performance

How to Achieve Greatness in JDBC Performance

Hey, tea lovers! Today, we will talk about the JDBC, the code which connects Java code to the realm of the databases, and the best practices of JDBC to achieve greatness in the performance of database operations. We will talk about the best practices as we talked about in “ What’s In A Name: Java Naming Conventions” but this time, it is about the JDBC best practices. These are the small tweaks you can do to your code that, not only makes it much faster but also makes your code less horrific. It will be like a list to improve the JDBC or we can say, handle the database like a pro. So let us start the adventure. ...

May 7, 2021 · 6 min · Imran Shaikh
How to Install Latest Java and Set JAVA_HOME on Ubuntu

How to Install Latest Java and Set JAVA_HOME on Ubuntu

Hey, Tea lovers! In this post, we will have a look at how we can easily install the latest Java or JDK on the Ubuntu system. It will be a very quick and small post. Before You Start I will be installing Open JDK, and I will show the installation for JDK 8, JDK 11, and JDK 14 on Ubuntu. For the Windows user, I have already written a post on " Install Latest or Any Java Version in 3 Simple Steps: Windows". ...

March 1, 2021 · 4 min · Imran Shaikh
How to Select Specific Folders or Files As Input in Flink

How to Select Specific Folders or Files As Input in Flink

Hey, tea lovers! Today I will show you how to specifically select the desired folders or files in Flink Batch Job programmatically. We will discuss when given a root path you can decide which file or folder to read in Flink Batch Job. And why suddenly do I pick up this topic you say? Well, I was working on such a task myself where I needed to read the S3 files which are under folders with dates. Those date folders are in a rolling fashion like , 2021_01_13_1, 2021_01_13_2, 2021_01_13_3 and so on. And in these folders, there were multiple files, so based on the given date I needed to read all those files which are in the given date folder (the folder name should contain the date obviously). ...

February 20, 2021 · 7 min · Imran Shaikh
JDBC Connection Pooling Explained with HikariCP (2)

JDBC Connection Pooling Explained with HikariCP

Hey, tea lovers! Have you ever heard about connection pooling in JDBC or HikariCP? If not, no worries at all, that is what this post is all about. We will talk about all the things about the JDBC connection pool and its implementation using HikariCP. HikariCP is one of the fastest connection pooling available in the market for JDBC connections. It makes connection pooling very easy. get ready to learn more about this beast. But before, make your tea to sip and learn. And for the example used in the post, you can find it on GitHub here or the full project here. ...

May 12, 2020 · 9 min · Imran Shaikh
Stream API The Hero Without a Cape

Stream API: The Hero Without a Cape

Hey Tea Lovers! In this post, we will be talking about an unsung hero of the Java world, the Stream API which was added to Java 8 and has changed the way we do programs in java and how! It added neatness as well as made the program more readable. It helps you do functional programming in Java. Without any further ado, let us read more about this jewel. What is Stream API The Stream API, included in Java 8, is utilized for processing collections of objects. It is the flow of Objets on which various methods get applied in the pipeline to have the result. Simply put, it flows through the given Collection<Object> and applies the different methods on the Object to aggregate them into the desired result without affecting the original Object. ...

May 11, 2020 · 9 min · Imran Shaikh