<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Java on Abdelbaki Ben Elhaj Slimene</title><link>https://bakic.github.io/tags/java/</link><description>Recent content in Java on Abdelbaki Ben Elhaj Slimene</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Mon, 26 Feb 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://bakic.github.io/tags/java/index.xml" rel="self" type="application/rss+xml"/><item><title>Custom Bean Instantiation Using @ConditionalOnProperty Annotation in Spring Boot</title><link>https://bakic.github.io/posts/conditionalonproperty-custom-beans-spring-boot/</link><pubDate>Mon, 26 Feb 2024 00:00:00 +0000</pubDate><guid>https://bakic.github.io/posts/conditionalonproperty-custom-beans-spring-boot/</guid><description>&lt;p&gt;Spring boot is a widely used framework to bootstrap standalone web applications. Its flexibility and capabilities in beans management make the life of the developer much easier compared to the manual handling of these components.&lt;/p&gt;&#10;&lt;p&gt;&lt;img src="image-1.jpg" alt=""&gt;&lt;/p&gt;&#10;&lt;p&gt;In this blog post, I will describe a use case where I needed the help of Spring Boot to create beans based on a configuration set in my &lt;code&gt;application.yml&lt;/code&gt; file.&lt;/p&gt;&#10;&lt;h2 id="problem-description"&gt;Problem Description&lt;/h2&gt;&#10;&lt;p&gt;I was working on a notification service where depending on events received and the configuration set up, notifications of different types were sent to users. These notifications were emails, SMS messages and push notifications for mobile applications.&lt;/p&gt;</description></item><item><title>Optimizing Java Application Performance with Asynchronous Logging in Logback</title><link>https://bakic.github.io/posts/asynchronous-logging-logback/</link><pubDate>Sun, 19 Nov 2023 00:00:00 +0000</pubDate><guid>https://bakic.github.io/posts/asynchronous-logging-logback/</guid><description>&lt;p&gt;Logging is an essential component of successful debugging, accurate monitoring, and comprehensive auditing in the evolving world of Java application development. However, as applications get more complex and manage higher loads, the influence of traditional logging systems on overall performance cannot be ignored. Asynchronous logging appears as a game changer in this context, providing a seamless combination of rich logging features without sacrificing application speed. This game-changing technology has changed the way developers handle logging in scalable, high-performance systems. In this article we will explore the world of asynchronous logging, learn about its importance and use in current Java development.&lt;/p&gt;</description></item><item><title>A Closer Look at Annotations in Java</title><link>https://bakic.github.io/posts/a-closer-look-at-annotations-in-java/</link><pubDate>Mon, 06 Nov 2023 00:00:00 +0000</pubDate><guid>https://bakic.github.io/posts/a-closer-look-at-annotations-in-java/</guid><description>&lt;p&gt;Annotations are a form of meta-data that provides additional information about code elements, such as classes, methods, fields, and more. They were introduced in Java 5 and have become an integral part of the language. Annotations are identified by the &lt;code&gt;@&lt;/code&gt; symbol and can be used for various purposes. In this article, we are going to take a deep dive on annotations where we are going to see how they are build and how to use them through an example.&lt;/p&gt;</description></item><item><title>Switch Statement in Java: From Basic to Pattern Matching</title><link>https://bakic.github.io/posts/switch-statement-in-java-pattern-matching/</link><pubDate>Tue, 29 Aug 2023 00:00:00 +0000</pubDate><guid>https://bakic.github.io/posts/switch-statement-in-java-pattern-matching/</guid><description>&lt;p&gt;The switch statement is a fundamental control structure in Java, allowing developers to execute different code blocks based on the value of an expression. Before the introduction of advanced features like pattern matching and switch expressions, Java&amp;rsquo;s switch statement underwent several stages of evolution. In this blog post, we&amp;rsquo;ll take a journey through the evolution of the switch statement, exploring its various stages and providing detailed examples and explanations along the way.&lt;/p&gt;</description></item><item><title>The Most Used Stream Operations in Java With Examples</title><link>https://bakic.github.io/posts/the-most-used-stream-operations-in-java-with-examples/</link><pubDate>Sat, 12 Aug 2023 00:00:00 +0000</pubDate><guid>https://bakic.github.io/posts/the-most-used-stream-operations-in-java-with-examples/</guid><description>&lt;p&gt;Stream operations were introduced in Java 8 and they allow you to manipulate collections of data in a concise and functional way. A stream can be seen as a sequence of elements that you can perform various operations on, such as filtering, mapping, or reducing.&lt;/p&gt;&#10;&lt;p&gt;This article serves as a comprehensive guide to the most commonly used stream operations, with clear explanations and practical examples.&lt;/p&gt;&#10;&lt;h2 id="setting-up-and-creating-streams"&gt;Setting up and Creating Streams&lt;/h2&gt;&#10;&lt;p&gt;To work with stream operations, you need to create a stream first. Streams can be created from various data sources, including collections, arrays, or input/output channels. For example, to create a stream from a list, you can use the &lt;code&gt;stream()&lt;/code&gt; method:&lt;/p&gt;</description></item><item><title>A Deep Dive into the flatMap Operation of the Stream API in Java with Examples</title><link>https://bakic.github.io/posts/flatmap-stream-api-java/</link><pubDate>Thu, 10 Aug 2023 00:00:00 +0000</pubDate><guid>https://bakic.github.io/posts/flatmap-stream-api-java/</guid><description>&lt;p&gt;The &lt;code&gt;flatMap&lt;/code&gt; operation is an intermediate operation provided by the Stream API, which allows you to transform each element of a stream into zero or more elements and then flatten the resulting elements into a single stream. It&amp;rsquo;s useful to use with nested data structures, such as lists within lists and effectively &amp;ldquo;flattening&amp;rdquo; them into a more manageable format.&lt;/p&gt;&#10;&lt;p&gt;In this article we are going to explain how this operation works internally and give some examples.&lt;/p&gt;</description></item><item><title>Sealed Classes in Java</title><link>https://bakic.github.io/posts/sealed-classes-in-java/</link><pubDate>Mon, 07 Aug 2023 00:00:00 +0000</pubDate><guid>https://bakic.github.io/posts/sealed-classes-in-java/</guid><description>&lt;p&gt;Sealed classes, a new addition to the Java programming language starting from Java 15, provide developers with a powerful tool for defining restricted class hierarchies. By explicitly specifying which classes can extend or implement them, sealed classes offer enhanced control over inheritance and extensibility.&lt;/p&gt;&#10;&lt;p&gt;This article explores the concept of sealed classes in Java, their syntax and declaration, as well as their purpose, benefits, and limitations.&lt;/p&gt;&#10;&lt;h2 id="what-are-sealed-classes"&gt;What are Sealed Classes?&lt;/h2&gt;&#10;&lt;p&gt;Sealed classes in Java are a new feature introduced in Java 15 that allows developers to restrict the inheritance hierarchy of a class. By marking a class as sealed, you can control which other classes can extend it. This adds an extra layer of control and encapsulation to your code.&lt;/p&gt;</description></item><item><title>Spring Boot Profiles Best Practices</title><link>https://bakic.github.io/posts/spring-boot-profiles-best-practices/</link><pubDate>Sat, 05 Aug 2023 00:00:00 +0000</pubDate><guid>https://bakic.github.io/posts/spring-boot-profiles-best-practices/</guid><description>&lt;p&gt;Spring Boot profiles provide a powerful way to manage application configurations for different environments or scenarios. By using profiles, developers can easily customize the behavior of their applications based on the target environment, such as development, testing, production, or specific customer requirements.&lt;/p&gt;&#10;&lt;p&gt;This article explores the best practices for utilizing Spring Boot profiles, including defining and activating profiles, organizing configuration files, managing profile-specific dependencies, testing and debugging, and addressing common pitfalls. Understanding and implementing these best practices will help developers harness the full potential of Spring Boot profiles and enhance the flexibility, maintainability, and scalability of their applications.&lt;/p&gt;</description></item><item><title>Records in Java</title><link>https://bakic.github.io/posts/records-in-java/</link><pubDate>Sat, 02 Oct 2021 00:00:00 +0000</pubDate><guid>https://bakic.github.io/posts/records-in-java/</guid><description>&lt;p&gt;&lt;img src="image-1.jpg" alt="Photo by AltumCode on Unsplash"&gt;&lt;/p&gt;&#10;&lt;p&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@altumcode?utm_source=medium&amp;amp;utm_medium=referral"&gt;AltumCode&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;&#10;&lt;p&gt;After being a preview feature in Java 14 and Java 15, Java records are now part of the Java language starting from Java 16.&lt;/p&gt;&#10;&lt;p&gt;In this article, we are going to take a deep dive into Java records and look at what this feature provides and how can we use it.&lt;/p&gt;&#10;&lt;h2 id="records"&gt;Records&lt;/h2&gt;&#10;&lt;p&gt;As per the &lt;a href="https://openjdk.java.net/jeps/395"&gt;JEP 395&lt;/a&gt;, records are described as &lt;code&gt;classes that act as transparent carriers for immutable data&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Comparison between the different ways of dependency injection in Spring</title><link>https://bakic.github.io/posts/dependency-injection-ways-in-spring/</link><pubDate>Fri, 05 Mar 2021 00:00:00 +0000</pubDate><guid>https://bakic.github.io/posts/dependency-injection-ways-in-spring/</guid><description>&lt;p&gt;&lt;img src="image-1.jpg" alt="Photo by Fazly Shah on Unsplash"&gt;&lt;/p&gt;&#10;&lt;p&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@fazlyshah?utm_source=medium&amp;amp;utm_medium=referral"&gt;Fazly Shah&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;&#10;&lt;p&gt;Dependency injection is a core feature of the Spring framework. It is used by Spring to set the bean’s dependencies while initializing the application context. We usually use &lt;code&gt;@Autowired&lt;/code&gt; annotation to get a reference to a bean in the Spring context.&lt;/p&gt;&#10;&lt;p&gt;Dependency injection in Spring can be done in three different ways: fields, setter, and constructor. In this article, we will explain each one and give their pros and cons.&lt;/p&gt;</description></item><item><title>Difference between Map and FlatMap in Java</title><link>https://bakic.github.io/posts/difference-between-map-and-flatmap-in-java/</link><pubDate>Thu, 18 Feb 2021 00:00:00 +0000</pubDate><guid>https://bakic.github.io/posts/difference-between-map-and-flatmap-in-java/</guid><description>&lt;p&gt;&lt;img src="image-1.jpg" alt="Photo by Clément Hélardot on Unsplash"&gt;&lt;/p&gt;&#10;&lt;p&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@clemhlrdt?utm_source=medium&amp;amp;utm_medium=referral"&gt;Clément Hélardot&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;&#10;&lt;p&gt;The Stream API of Java 8 provides two intermediate stream operations used to perform actions on stream elements and return a stream as an output: &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt;. In this article, we are going to take a look at these two methods and explain the difference between them with examples.&lt;/p&gt;&#10;&lt;h2 id="map-function"&gt;Map function&lt;/h2&gt;&#10;&lt;p&gt;The &lt;code&gt;map&lt;/code&gt; function takes a &lt;code&gt;Function&lt;/code&gt; as a parameter and applies it to all the elements of the stream. The result will be a stream of the result of the function applied to each element of the initial stream. There is a &lt;strong&gt;one-to-one&lt;/strong&gt; mapping between the input and the output elements.&lt;/p&gt;</description></item></channel></rss>