Skip to main content

Posts

G1 Garbage Collector Explained

G1 Garbage Collector Explained G1 Garbage Collector Explained In G1 GC, the heap is divided into equal-sized regions. Each region can belong to one of the following categories: Eden : Where new objects are allocated. Survivor : Where objects that survive an initial garbage collection are moved. Old : Where objects that have survived multiple garbage collections are promoted. Humongous : Where very large objects that do not fit into a standard region are allocated. Key Concepts 1. Region-Based Memory Management : Each region is typically between 1 MB and 32 MB. The number of regions and their size can be controlled via the -XX:G1HeapRegionSize parameter. 2. Young and Old Generation : Unlike traditional generational collectors that have contiguous spaces for young and old generations, G1 has regions that can dynamically change their role. Young Ge...

Software Engineering Principles: DRY, KISS, and YAGNI

Software Engineering Principles: DRY, KISS, and YAGNI Software Engineering Principles: DRY, KISS, and YAGNI DRY (Don't Repeat Yourself) Principle: The DRY principle emphasizes the importance of reducing repetition within code. Repetition can lead to more errors, higher maintenance costs, and inconsistency. When the same piece of code or logic appears in multiple places, it should be abstracted out into a single location that can be reused. Example: Without DRY: public class Calculator { public int add(int a, int b) { return a + b; } public int subtract(int a, int b) { return a - b; } public int multiply(int a, int b) { return a * b; } public double divide(int a, int b) { return a / b; } public int addAndSubtract(int a, int b, int c) { return a + b - c; // repeated addition and subtraction logic } } With DRY: public class Ca...

Understanding C1 and C2 Compilers in Java

Understanding C1 and C2 Compilers in Java Understanding C1 and C2 Compilers in Java In Java, the Just-In-Time (JIT) compiler is a part of the Java Virtual Machine (JVM) that improves the performance of Java applications by compiling bytecode into native machine code at runtime. The JIT compiler includes two different compilers, known as the C1 and C2 compilers, each with distinct optimization strategies and purposes. C1 Compiler (Client Compiler) The C1 compiler, also known as the client compiler, is designed for fast startup times and lower memory consumption. It performs lighter and quicker optimizations, which makes it suitable for applications that require quick startup and responsiveness. Key characteristics of the C1 compiler include: Quick Compilation: Prioritizes fast compilation times over deep optimizations. Low Overhead: Consumes less memory and resources during compilation. Profile-Guided Optimization: Ca...

Understanding -XX:+PrintCompilation Output in Java

Understanding -XX:+PrintCompilation Output in Java Understanding -XX:+PrintCompilation Output in Java The -XX:+PrintCompilation flag in the Java Virtual Machine (JVM) prints information about the methods being compiled by the Just-In-Time (JIT) compiler. When you enable this flag, the JVM will output a log of compilation events to the standard output. Each line of the output provides information about a specific method being compiled. Here, I'll explain the meaning of the different columns and markers, specifically focusing on the n , s , and % markers as seen in your example. Explanation of Output Columns and Markers Here's a breakdown of what each column and marker means: Timestamp : The time (in milliseconds) since the JVM started when the compilation event occurred. Compilation ID : A unique identifier for each compilation task within the JVM's lifecycle. Optimization Level : The lev...

What is and usage of Just-in-time Compilation

What is and usage of Just-in-time Compilation Just-in-time Compilation Explained Just-in-time (JIT) compilation is a feature of many modern runtime environments, including the Java Virtual Machine (JVM), which improves the performance of interpreted code. Here's an explanation of JIT compilation and its use: What is Just-in-time Compilation? Just-in-time (JIT) compilation is a process where the bytecode of an interpreted language (like Java) is compiled into native machine code at runtime, rather than prior to execution. This compiled code is then executed directly by the CPU, which is much faster than interpreting the bytecode line by line. How JIT Compilation Works Bytecode Interpretation : Initially, the JVM interprets the bytecode. Interpretation involves converting bytecode into machine code instruction by instruction, which is relatively slow. Profiling and Hot Spot Detection : ...

what is the value of using Iterable over List in java?

what is the value of using Iterable over List in java? what is the value of using Iterable over List in java? Using Iterable over List in Java can provide several benefits, particularly in terms of flexibility and abstraction. Here are some key points that highlight the value of using Iterable : 1. Decoupling and Abstraction Flexibility in Implementation Iterable is a more general interface compared to List . While List is a specific type of collection that guarantees ordered elements and allows indexed access, Iterable can be implemented by any collection that can be iterated over, including Set , Queue , Map (for its keySet , values , or entrySet ), and custom collection types. Using Iterable allows your code to be more flexible and work with a broader range of collection types, not just List . Code Reusability Methods that accept Iterable can be reused with different types of collections. This makes your APIs more ver...

Are static variables re-initialized and stored multiple times in memory when instance of a class is created?

Are static variables re-initialized and stored multiple times in memory when instance of a class is created? No, static variables are not re-initialized or stored multiple times in memory when instances of a class are created. Here is how static variables work in Java: Characteristics of Static Variables: Single Instance per Class : A static variable is associated with the class itself, rather than with any specific instance of the class. This means that no matter how many instances of the class you create, there will always be only one copy of the static variable. Memory Allocation : Static variables are allocated memory only once, when the class is loaded into memory by the Java Virtual Machine (JVM). This allocation happens in the method area (part of the JVM's memory), which is separate from the memory areas used for instance variables (which are stored in the heap). Initialization : Static variables are initialized once, at th...

Java Increment Operations: `n++` vs `n = n + 1` vs `n += 1`

In Java, incrementing a variable by one can be done in several ways: n++ , n = n + 1 , and n += 1 . While these expressions achieve the same end result, they differ slightly in syntax and use cases. Let's explore each one and discuss their performance. 1. n++ Post-Increment Operator : Increments the value of n by 1 after its current value has been used. Common Usage : Typically used in loops and other contexts where the current value needs to be used before incrementing. int n = 5; n++; // n is now 6 2. n = n + 1 Addition Assignment : Explicitly sets n to its current value plus 1. Readability : Straightforward and clear, though slightly more verbose. int n = 5; n = n + 1; // n is now 6 3. n += 1 Compound Assignment Operator : Equivalent to n = n + 1 , but more concise. Usage : Combines addition and assignment into one step. int n = 5; n += 1; // n is...

Using varargs(Variable -length argument) in Java

Sometimes you might want to write a method that takes a variable number of arguments. In Java, there is a feature called variable-length arguments, or varargs for short, which allows you to do this. Prior to JDK 5, variable-length arguments could be handled in two ways, using overloading using array argument. syntax for varargs public static String format(String pattern, Object... arguments); The three periods after the final parameter's type indicate that the final argument may be passed as an array or as a sequence of arguments.  Varargs can be used only in the final argument position There can be only one variable argument in a method. Vararg Methods can also be overloaded but overloading may lead to ambiguity. Example:  public class Varargs { public static void main(String[] args) { printItems(1,2, "mango", "apple", "orange"); printItems(2,1, "book", "pen", ...

What is L1, L2 and L3 Support Engineering

In this blog article, I'm going to explain about the Software support engineering role with my experience. I was a Level 2 and 3 support Engineer during my career. L1 - Level 1 L2 - Level 2 L3 - Level 3 Ticket - Incident L1 support includes interacting with customers, understand their issue and create tickets against it. The ticket then routed to the relevant L2 support ( Integration support, Server & Storage support, etc ...). L1 support Engineers have basic knowledge of product/service and skill to troubleshoot a very basic issue like password reset, software installation/uninstallation/reinstallation. L2 support manages the tickets which routed to them by L1( L2 support also can create tickets against any issue notice by them). They have more knowledge, more experience in solving related complex issues and can guide/help L1 support folks job in troubleshooting. If the solution not provided at this level then escalate to the L3. L3 is ...

Many to Many mapping in Spring boot

In this blog, I will explain how to use many-to-many mapping in Spring boot Application What you need? JAVA MySql Eclipse IDE ( whatever you like IDE, I'm using Eclipse for this example) Maven ( you can use the Gradle as well) Initial Plan spring boot application will be created using spring initializer web tool and imported as a maven project to the eclipse ide. Scenarios will be post and tags. one post have more than one tags and one tags have more than one posts. Two model classes will be created for Post and Tags. Finally, the command line runner interface will be used to run the application. Below diagram is the database model diagram which we going to install using the spring boot application. Let's Start to Code. You need to configure the application.properties file for database connections. add the following content to the src/main/resources/application.properties spring.datasource.url=jdbc:mysql://localhost:3306/learning spring.dataso...

One to Many Mapping using Spring boot

In this blog, I will explain how to use one-to-many mapping in Spring boot Application What you need? JAVA MySql Eclipse IDE ( whatever you like IDE, I'm using Eclipse for this example) Maven ( you can use the Gradle as well) Initial Plan I will create a spring boot application project using the  Spring Initializer  web tool and import the project as a maven project. after configuring the all necessary setting, I will code for one-to-many mapping. Below diagram is the database model diagram which we going to install using the spring boot application. Let's Start to Code. You need to configure the application.properties file for database connections. add the following content to the src/main/resources/application.properties spring.datasource.url=jdbc:mysql://localhost:3306/learning spring.datasource.username=root spring.datasource.password=root spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect spring.jpa.hib...

One to One Mapping with Spring boot

In this blog, I will explain how to use one-to-one mapping in Spring boot Application What you need? JAVA MySql Eclipse IDE ( whatever you like IDE, I'm using Eclipse for this example) Maven ( you can use the Gradle as well) Initial Plan I will create a spring boot application project using the Spring Initializer web tool and import the project as a maven project. after configuring the all necessary setting, I will code for one-to-one mapping. Below diagram is the database model diagram which we going to install using the spring boot application. Let's Start to Code. You need to configure the application.properties file for database connections. add the following content to the src/main/resources/application.properties spring.datasource.url=jdbc:mysql://localhost:3306/learning spring.datasource.username=root spring.datasource.password=root spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect spring.jpa.hibern...