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
Java Sealed Class -1

Java Sealed Classes: The Ultimate Guide to Secure Code

Hey Tea Lovers! We meet after a long time. Today’s post will be a short and cut-to-the-point post about the latest offering (relatively) by Java 17+. Yes, as you read in the title, it is about sealed classes in java. We will go over some of the basics and will give you some pointers that I think fully describes it. So let’s get to it. Introduction of Java’s Sealed Class The sealed class in Java is a new addition to the core library of java since Java 17. It is an introduction to the new keywords, sealed and non-sealed. The sealed class allows one to describe which class/interface can extend/implement the current class/interface. I will be using class throughout the post but it applies to both classes and interfaces in Java. ...

February 15, 2023 · 5 min · Imran Shaikh
How to Easily use Factory Design Pattern in Java

How to Easily use Factory Design Pattern in Java

Hey, Tea Lovers! Let me continue our design pattern series by adding this post. The Factory Design Pattern or Factory Method Design Pattern. It is one of the widely used and easy-to-understand Design patterns. It’s an effortless yet effective way of hiding object creation complexity. That’s why it is under the creation pattern category. So let’s jump right into it. Prerequisite to knowing Factory Design Pattern Before understanding what a factory design pattern is, you need to understand what superclass and subclass are. I am pretty sure you are aware of this detail, if not, the following section describes it in brief. if you already know it, you can skip to this part ...

August 5, 2022 · 6 min · Imran Shaikh
Java Switch Statement is now more Powerful Java 18

Java Switch Statement is now more Powerful | Java 18

Hey Tea Lovers! Today let me talk about the Plain Old Java Switch Expression, but with a twist. This twist or update has been added to the core library of Java since Java 13. And If you are using Java version 13 or after, you can surely convert that old switch with the new one. I will talk about how it offers certain features in it without breaking existing changes. Of course, the other language users may comment “It was already there in our programming language years ago”. But let’s just smile, and continue coding in Java, shall we? One note, I will be using the " switch expression" and " switch statement" interchangeably in the post, so keep it in mind that I am trying to say the same thing. ...

April 23, 2022 · 5 min · Imran Shaikh
What's new in Java 18 The Latest Java

What's new in Java 18? New Features of New Java 18

Hey Tea Lovers. On 22 March 2022, JDK 18 or Java 18 is released to the public (from Oracle). Java 18 does not contain any major updates that will change how we code, but it does have something very interesting. Few of the updates are in the incubator or preview mode. So for this article, I will be mostly focused on the core library addition. Don’t worry I will add a summary of other updates as well. ...

March 26, 2022 · 5 min · Imran Shaikh
How HashMap Works THumbnail

The Magic Behind HashMap and How it works in Java

Hey! tea lovers! In this post, we will be discussing how HashMap, the key-value-based data structure, works in Java. And it is one of the most asked interview questions as well. It is the core feature we as a developer use daily. Primarily used for easy and faster access to data based on the key. So let us see how it stores, retrieves and updates the data. I will put more articles under the Simply Explained tag. For now, let us get started with HashMap. So make your cup of tea to sip and code. ...

March 20, 2022 · 6 min · Imran Shaikh
Call By Value & Call By Reference in Java

Call By Value & Call By Reference in Java

Hey, Tea Lovers! Today we will take a look at the basic but tricky interview question, Call By Value & Call By Reference in Java. Both beginners and experienced developers get this question in interviews. It’s a technical interviewer’s favorite question. This post is one of the many in the series of Interview Questions, where we don’t just hang you with one line answer, but rather try to explain it so that it gets fits into your head. ...

February 18, 2022 · 6 min · Mahesh More
8 Tech to Learn as Java Developer in 2022

8 Tech to Learn as Java Developer in 2022

Hey, Tea Lovers! The new year is just around the corner, and we all are creating a New Year Resolution List 2022 for ourselves, aren’t we? Among staying healthy, beginning happy, and spending more time with family, we Java developers, or any developers also include some new technologies that we want to learn and grow our career with. Generally, it consists of a new hot topic in the market or something that will be used in a new project or just for a hobby. Beginners always find it confusing what should they do next. So I would like to help you guys to append some technologies into your new year resolution’s “learn new things” section. ...

December 30, 2021 · 8 min · Imran Shaikh
Log4j Issue And The Nightmare of Java Developers

Log4j Issue And The Nightmare of Java Developers

Planning to party Friday Night. Everything was ready. Waiting for your friend’s call to pick you up. The phone rings, and without seeing you pick up the call in excitement, “Hey Bro, Kaha tak pohcha” (Where have you reached so far). “Sorry?”, the person replied, “I am MR XYZ from your company ABCD Tech. We have raised an Incident Ticket of Log4J Issue for a major Log4j Security Vulnerability in Java applications”. ...

December 27, 2021 · 4 min · Imran Shaikh
Getting Started with Spring Boot Rest is Easy

Getting Started with Spring Boot Rest is Easy

Hey, Tea Lovers! Let’s learn about Spring Boot Rest Framework Annotations. It’s so simple and fast. In this post, I will try to explain different annotations for Spring Boot Rest API. These annotations are must need for a REST API in Spring Boot. We are building a Tutorial series on the Spring Boot. I will update this post once we publish the series. Please let me know what would you like to include in the tutorial. ...

December 24, 2021 · 5 min · Imran Shaikh