<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: MAYUR KUMBHAR</title>
    <description>The latest articles on DEV Community by MAYUR KUMBHAR (@themayurkumbhar).</description>
    <link>https://dev.to/themayurkumbhar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F166294%2F1b4168e5-657d-4d60-aa48-de2c3195159c.jpeg</url>
      <title>DEV Community: MAYUR KUMBHAR</title>
      <link>https://dev.to/themayurkumbhar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/themayurkumbhar"/>
    <language>en</language>
    <item>
      <title>Rust Language Essentials: Variables, Constants, and Mutability Explained for Beginners</title>
      <dc:creator>MAYUR KUMBHAR</dc:creator>
      <pubDate>Fri, 23 May 2025 15:26:55 +0000</pubDate>
      <link>https://dev.to/themayurkumbhar/rust-language-essentials-variables-constants-and-mutability-explained-for-beginners-5ce6</link>
      <guid>https://dev.to/themayurkumbhar/rust-language-essentials-variables-constants-and-mutability-explained-for-beginners-5ce6</guid>
      <description>&lt;p&gt;Continuing to our last post on the rust language fundamentals, today we will discuss on language foundations. What are variables, constants and Mutability works in Rust.&lt;/p&gt;

&lt;p&gt;Understanding how to store and manage data is fundamental. Rust has specific rules around the variables and mutability that are key to its safety guarantees.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Variables with &lt;code&gt;let&lt;/code&gt; :
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Variables are declared using the &lt;code&gt;let&lt;/code&gt; keyword:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;variable_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_var&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Immutability by Default:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;By default, variables in Rust are &lt;strong&gt;immutable&lt;/strong&gt;. Once a value is assigned with &lt;code&gt;let&lt;/code&gt; , it can not be changed.&lt;/li&gt;
&lt;li&gt;This default behaviour helps prevent the accidental data modification and makes code easier to reason about.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Mutability with &lt;code&gt;mut&lt;/code&gt; :
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;To allow a variable'd value to change, you must explicitly use the &lt;code&gt;mut&lt;/code&gt; keyword:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;variable_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;my_var&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;my_var&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;345&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Constants wit &lt;code&gt;const&lt;/code&gt; :
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Declared using the &lt;code&gt;const&lt;/code&gt; keyword:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Always immutable&lt;/strong&gt;, can not use &lt;code&gt;mut&lt;/code&gt; with constants.&lt;/li&gt;
&lt;li&gt;Must have their &lt;strong&gt;type annotated&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Can only be set to a &lt;strong&gt;constant expression&lt;/strong&gt; which is computable at compile time.&lt;/li&gt;
&lt;li&gt;Often used for hardcoded values and conventionally named in &lt;code&gt;UPPER_SNAKE_CASE&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Shadowing:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Declaring a &lt;em&gt;new&lt;/em&gt; variable with the same name as previous one using &lt;code&gt;let&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second &lt;code&gt;x&lt;/code&gt; is a new variable shadowing the first.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Key difference from &lt;code&gt;mut&lt;/code&gt;&lt;/strong&gt;: Shadowing creates a &lt;em&gt;new&lt;/em&gt; variable, allowing you to change the &lt;em&gt;type&lt;/em&gt; of the bound to the name. &lt;code&gt;mut&lt;/code&gt; changes the value in place but not the type.&lt;/li&gt;
&lt;li&gt;Useful for transforming a value while reusing the variable name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Variables in Rust store data, which can be of various &lt;strong&gt;basic data types&lt;/strong&gt; like integers, floats, booleans, and characters ( we will cover this in more details in coming articles).&lt;/p&gt;

&lt;p&gt;Rust's emphasis on immutability by default, combined with option of &lt;code&gt;mut&lt;/code&gt; and feature of shadowing, provides fine grained control over data manipulation.&lt;/p&gt;

&lt;p&gt;👉 Follow &lt;a href="https://medium.com/@themayurkumbhar" rel="noopener noreferrer"&gt;&lt;strong&gt;@themayurkumbhar&lt;/strong&gt;&lt;/a&gt; on Medium&lt;/p&gt;



</description>
      <category>rust</category>
      <category>programming</category>
      <category>beginners</category>
      <category>coding</category>
    </item>
    <item>
      <title>Rust Essentials: How to Set Up Your Development Environment</title>
      <dc:creator>MAYUR KUMBHAR</dc:creator>
      <pubDate>Sat, 10 May 2025 13:00:24 +0000</pubDate>
      <link>https://dev.to/themayurkumbhar/rust-essentials-how-to-set-up-your-development-environment-6f9</link>
      <guid>https://dev.to/themayurkumbhar/rust-essentials-how-to-set-up-your-development-environment-6f9</guid>
      <description>&lt;p&gt;In the previous article, we uncovered the power of Rust and explored its fundamental concepts. But theory alone isn’t enough — it’s time to get our hands dirty! In this article, we’ll walk you through setting up your local Rust development environment and writing your very first program. Let’s dive in and bring Rust to life on your machine!&lt;/p&gt;

&lt;p&gt;Rust offers an exceptional toolchain manager called rustup to simplify your development experience. Pair it with a reliable code editor or an integrated development environment (IDE) for a seamless and efficient coding journey.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Installing the Rust Toolchain with &lt;code&gt;rustup&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;What is &lt;code&gt;rustup&lt;/code&gt;? It’s the official command-line tool for installing and managing Rust versions along with its essential tools, such as &lt;code&gt;rustc&lt;/code&gt;, &lt;code&gt;cargo&lt;/code&gt;, and documentation. With &lt;code&gt;rustup&lt;/code&gt;, keeping your Rust environment up-to-date becomes effortless, ensuring you always have access to the latest features and fixes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How to Install Rust:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Linux/macOS&lt;/strong&gt;: Open your terminal and run the following command to install Rust:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;--proto&lt;/span&gt; &lt;span class="s1"&gt;'=https'&lt;/span&gt; &lt;span class="nt"&gt;--tlsv1&lt;/span&gt;.2 &lt;span class="nt"&gt;-sSf&lt;/span&gt; https://sh.rustup.rs | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Windows&lt;/strong&gt;: Visit the official Rust website and download rustup-init.exe. Run the installer to set up Rust on your system.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Post-Installation Steps:
After installing Rust, it’s essential to ensure that cargo and rustc are properly added to your system's PATH. If they aren’t, you might need to restart your terminal or execute a source command, such as:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt;/.cargo/env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(For Linux/macOS users).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verification:&lt;/strong&gt;&lt;br&gt;
To confirm a successful installation, open a new terminal and run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rustc &lt;span class="nt"&gt;--version&lt;/span&gt;

cargo &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These will display the installed versions of Rust’s compiler and package manager, verifying that everything is set up correctly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Tools&lt;/strong&gt; Installed by &lt;code&gt;rustup&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;rustc&lt;/code&gt;: The Rust compiler that transforms your source code into executables or libraries, forming the backbone of Rust development.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cargo&lt;/code&gt;: Rust's indispensable build system and package manager. It simplifies project creation, builds your code, manages dependencies (crates from &lt;a href="//crates.io"&gt;crates.io&lt;/a&gt;), runs tests, and much more.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Setting Up Your IDE
&lt;/h2&gt;

&lt;p&gt;While a plain text editor can get the job done, using an IDE or advanced code editor can supercharge your productivity. With features like syntax highlighting, autocompletion, and real-time error detection, you’ll spend less time debugging and more time building.&lt;/p&gt;

&lt;p&gt;Pair Visual Studio Code (VS Code) with the Rust Analyzer extension for the ultimate Rust development experience. This powerful combination provides intelligent code assistance, making your workflow smoother and more efficient.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;rustup&lt;/code&gt; installed (giving you &lt;code&gt;rustc&lt;/code&gt; and &lt;code&gt;cargo&lt;/code&gt;) and your IDE set up with Rust Analyzer, your development environment is ready!&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Hello Rust! your first program
&lt;/h2&gt;

&lt;p&gt;Projects in Rust are managed with cargo, a versatile tool that acts as a package manager, build system, test runner, and documentation generator. We'll use cargo to create and manage our project.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Step 1:&lt;/strong&gt; Create project with cargo
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cargo new hello_rust
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cargo&lt;/code&gt;: Runs the Cargo tool, Rust's package manager and build system.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;new&lt;/code&gt;: A subcommand that creates a new Rust project.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;hello_rust&lt;/code&gt;: The name of the project. Cargo will create a new directory with this name containing the project files.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you run this, cargo will output something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Created binary &lt;span class="o"&gt;(&lt;/span&gt;application&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="sb"&gt;`&lt;/span&gt;hello_rust&lt;span class="sb"&gt;`&lt;/span&gt; package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Step 2: Explore project structure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Navigate into the newly created directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;hello_rust
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, look at the files and directories inside. You should see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
├── Cargo.toml
└── src
    └── main.rs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Cargo.toml&lt;/code&gt;: The manifest file of your project, written in TOML (Tom's Obvious, Minimal Language). It includes metadata like the project's name, version, author, and dependencies. We'll explore this file in detail in the next lesson.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;src/&lt;/code&gt;: Directory containing your project's source code.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;src/main.rs&lt;/code&gt;: The crate root file for a binary application. By default, Cargo creates a binary crate (an executable program), and &lt;code&gt;main.rs&lt;/code&gt; serves as the entry point for the executable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step 3: Examine the Default Code (&lt;code&gt;src/main.rs&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Open the &lt;code&gt;src/main.rs&lt;/code&gt; file in your chosen IDE (VS Code or IntelliJ IDEA). You'll find the following code already written for you by &lt;code&gt;cargo new&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, world!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;fn&lt;/code&gt;: Declares a new function.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;main&lt;/code&gt;: The special entry point function for Rust executable programs.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;()&lt;/code&gt;: Indicates the main function takes no arguments.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{}&lt;/code&gt;: Encloses the body of the function, where instructions are written.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;println!&lt;/code&gt;: A macro (not a function, identified by !) used to print text to the console, followed by a newline.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"Hello, world!"&lt;/code&gt;: A string literal, representing the text to be printed.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;;&lt;/code&gt;: Marks the end of a statement in Rust.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step 4: Build and Run Your Program&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Building the Project&lt;/strong&gt;:&lt;br&gt;
Make sure you are inside the &lt;code&gt;hello_rust&lt;/code&gt; directory in your terminal. Then, run the following command to build your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cargo build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output will look something like this (details may vary):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Compiling hello_rust v0.1.0 (/path/to/your/project/hello_rust)
    Finished dev [unoptimized + debuginfo] target(s) in X.XXs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Step 5: Running the project (the easy way):&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The most common way to run your Rust program is using &lt;code&gt;cargo run&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cargo run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command is a shortcut. Cargo will first check if your code needs to be rebuilt. If it does, it will compile it. Then, it will execute the compiled program.&lt;/p&gt;

&lt;p&gt;You should see the following output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Finished dev [unoptimized + debuginfo] target(s) in Y.YYs
     Running `target/debug/hello_rust`
Hello, world!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Success! You have written, compiled, and run your first Rust program.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There’s another useful cargo command: cargo check. This command quickly checks your code for errors without producing an executable&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You’ve successfully learned the basics of creating, building, and running a Rust program using &lt;code&gt;cargo&lt;/code&gt;, while exploring the default project structure. You're now ready to dive deeper into Rust's powerful features. Happy coding!&lt;/p&gt;

&lt;p&gt;👉 Follow &lt;a href="https://medium.com/@themayurkumbhar" rel="noopener noreferrer"&gt;&lt;strong&gt;@themayurkumbhar&lt;/strong&gt;&lt;/a&gt; on Medium&lt;/p&gt;













</description>
      <category>rust</category>
      <category>programming</category>
      <category>softwaredevelopment</category>
      <category>coding</category>
    </item>
    <item>
      <title>Rust 101: the fundamentals</title>
      <dc:creator>MAYUR KUMBHAR</dc:creator>
      <pubDate>Tue, 06 May 2025 04:48:46 +0000</pubDate>
      <link>https://dev.to/themayurkumbhar/rust-101-the-fundamentals-20hf</link>
      <guid>https://dev.to/themayurkumbhar/rust-101-the-fundamentals-20hf</guid>
      <description>&lt;p&gt;Hello learner’s, in this article, we will discuss about the Rust language fundamentals. We’ll explore why we need Rust, What it is? And Core philosophy behind the language.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Rust programming language was started in 2006 as personal project, in 2009 Mozilla sponsored project, in 2015 Rust 1.0 was released.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is rust?
&lt;/h2&gt;

&lt;p&gt;Rust is &lt;strong&gt;general-purpose&lt;/strong&gt;, &lt;strong&gt;multi-paradigm system programming&lt;/strong&gt; Language. It’s designed for &lt;strong&gt;performance critical tasks&lt;/strong&gt;, often handled by languages such as C and C++, used in operating systems, embedded systems, game engines etc. It also offers flexibility for command-line tools, web development and more.&lt;/p&gt;

&lt;p&gt;Essentially, rust achieves this low-level control and performance &lt;strong&gt;without requiring a garbage collector&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core philosophy of Rust
&lt;/h2&gt;

&lt;p&gt;Rust is built on key pillars:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Safety&lt;/strong&gt;: Rust guarantees memory safety at compile time, eliminating common bugs like dangling pointers, null pointer dereferencing, and data races in concurrent code, which are major causes of crashes and security vulnerabilities in other languages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance&lt;/strong&gt;: Rust compiles code into highly efficient native code, comparable in performance to C and C++, while eliminating runtime overhead. Its “Zero-cost abstraction” ensures speed without compromising high-level features.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Concurrency&lt;/strong&gt;: Rust’s ownership system and borrow checker prevent data races at compile time, making concurrent code much more manageable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Productivity&lt;/strong&gt;: Rust offers good tooling (cargo), a helpful compiler with detailed error messages, and a growing tooling ecosystem of libraries (crates) to boost productivity, despite its focus on low-level control.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why learn rust?
&lt;/h2&gt;

&lt;p&gt;Selecting rust offers significant advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reliability&lt;/strong&gt;: Rust’s robust safety guarantees that successfully compiled code is remarkably free of common, challenging-to-debug runtime errors related to memory or concurrency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Speed&lt;/strong&gt;: For performance–sensitive applications, Rust is top choice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Safer concurrency&lt;/strong&gt;: Build multithreaded applications confidently, knowing compiler helps prevent dangerous bugs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Growing demand&lt;/strong&gt;: rust’s adoption is increasing across various domains, creating new opportunities&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deeper understanding&lt;/strong&gt;: Learning Rust provides valuable insights into how computer programs manage resources like memory.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common use-cases:
&lt;/h2&gt;

&lt;p&gt;Rust’s journey and its role in the world include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Operating systems&lt;/li&gt;
&lt;li&gt;Web servers and web assembly&lt;/li&gt;
&lt;li&gt;Command line tools&lt;/li&gt;
&lt;li&gt;Databases and distributed systems&lt;/li&gt;
&lt;li&gt;Embedded systems&lt;/li&gt;
&lt;li&gt;Blockchain&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In summary, Rust empowers developers to &lt;strong&gt;construct dependable&lt;/strong&gt;, &lt;strong&gt;efficient&lt;/strong&gt;, and &lt;strong&gt;secure software&lt;/strong&gt;, effectively &lt;strong&gt;addressing intricate challenges such as concurrency&lt;/strong&gt; directly &lt;strong&gt;through compile-time guarantees&lt;/strong&gt;.&lt;/p&gt;




&lt;p&gt;👉 &lt;a href="https://medium.com/@themayurkumbhar" rel="noopener noreferrer"&gt;&lt;strong&gt;Follow @themayurkumbhar on Medium&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;



</description>
      <category>rust</category>
      <category>programming</category>
      <category>coding</category>
      <category>developers</category>
    </item>
    <item>
      <title>Circular ⭕ dependency exceptions in Spring❗</title>
      <dc:creator>MAYUR KUMBHAR</dc:creator>
      <pubDate>Wed, 21 Jun 2023 16:48:42 +0000</pubDate>
      <link>https://dev.to/themayurkumbhar/circular-dependency-exceptions-in-spring-3k1n</link>
      <guid>https://dev.to/themayurkumbhar/circular-dependency-exceptions-in-spring-3k1n</guid>
      <description>&lt;h2&gt;
  
  
  Issue?
&lt;/h2&gt;

&lt;p&gt;When two beans are waiting for each other to be created in the spring context so that autowiring can happen, this state is called as &lt;strong&gt;Circular Dependency&lt;/strong&gt; and we get the &lt;code&gt;BeanCurrentlyInCreationException&lt;/code&gt; exception.&lt;/p&gt;

&lt;p&gt;Scenario, lets say BeanA is defined as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Component&lt;/span&gt; 
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BeanA&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;

&lt;span class="nd"&gt;@Autowired&lt;/span&gt; &lt;span class="c1"&gt;// here BeanA is depends on BeanB&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;BeanB&lt;/span&gt; &lt;span class="n"&gt;bean&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now lets say we have BeanB as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Component&lt;/span&gt; 
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BeanB&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;

&lt;span class="nd"&gt;@Autowired&lt;/span&gt; &lt;span class="c1"&gt;// here BeanB is depending on BeanA&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;BeanA&lt;/span&gt; &lt;span class="n"&gt;bean&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So there is dependency between two components resulting in circular dependency as each bean is waiting for its dependent bean to created for autowiring.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;Developer should be careful while creating the Beans, making sure there are no circular dependency. But is worst case if there exists case or by mistake some developer put the circular dependency then we can follow below to resolve this.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use setter injection instead of constructor injection
&lt;/h3&gt;

&lt;p&gt;We can use the setter injection in one of class for dependent bean, so that injection is happed after one object is created avoiding the race condition.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use Lazy initialization on beans
&lt;/h3&gt;

&lt;p&gt;We can use &lt;code&gt;@Lazy&lt;/code&gt; annotation on one of the bean in circular dependency so that one of bean creation is delayed until bean is actually required.&lt;/p&gt;

&lt;h3&gt;
  
  
  Refactor code to remove circular dependency
&lt;/h3&gt;

&lt;p&gt;We should avoid creating such circular dependency in first place, and refactor code respectively to remove the circular dependency.&lt;/p&gt;




</description>
      <category>spring</category>
      <category>springboot</category>
      <category>java</category>
      <category>exception</category>
    </item>
    <item>
      <title>How @Autowired works in Spring - A detailed guide</title>
      <dc:creator>MAYUR KUMBHAR</dc:creator>
      <pubDate>Mon, 19 Jun 2023 14:53:09 +0000</pubDate>
      <link>https://dev.to/themayurkumbhar/how-autowired-works-in-details-14a5</link>
      <guid>https://dev.to/themayurkumbhar/how-autowired-works-in-details-14a5</guid>
      <description>&lt;p&gt;In &lt;a href="https://dev.to/themayurkumbhar/wiring-in-spring-51lc"&gt;last post&lt;/a&gt; we have seen how &lt;code&gt;@Autowired&lt;/code&gt; can be used at multiple places to inject the dependent beans. Spring framework handles the dependency between the components and based on field, setter or constructor injection injects appropriate objects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Issue?
&lt;/h2&gt;

&lt;p&gt;What happens when spring context has multiple beans of same type? which object spring framework injects for &lt;code&gt;@Autowired&lt;/code&gt; annotation?&lt;/p&gt;

&lt;p&gt;If we have single bean of required type in the spring context, there is no ambiguity to framework and it will inject the dependent bean wherever required.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Spring framework handle such scenarios?
&lt;/h2&gt;

&lt;p&gt;When spring framework gets into situation of multiple beans of same type which need to be injected in one of the &lt;code&gt;@Autowired&lt;/code&gt; dependency, it will follow the &lt;code&gt;three&lt;/code&gt; steps to resolve the ambiguity.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;By Default IoC container will always look for &lt;code&gt;class type&lt;/code&gt; of bean to inject.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Step 1: look for bean name with same parameter/field name.
&lt;/h3&gt;

&lt;p&gt;Spring IoC container will look for bean name with equal to parameter name mentioned with &lt;code&gt;@Autowired&lt;/code&gt; annotation in filed, setter parameter, constructor parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="c1"&gt;// field injection&lt;/span&gt;
&lt;span class="nd"&gt;@Autowired&lt;/span&gt; 
&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;SomeBean&lt;/span&gt; &lt;span class="n"&gt;bean&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// here spring looks for bean with name "bean" in context&lt;/span&gt;

&lt;span class="c1"&gt;// setter injection&lt;/span&gt;
&lt;span class="nd"&gt;@Autowired&lt;/span&gt; 
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setSomeBean&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SomeBean&lt;/span&gt; &lt;span class="n"&gt;bean1&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt; &lt;span class="c1"&gt;// here spring looks for bean with name "bean1" in context to inject.&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;bean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bean1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// constructor injection&lt;/span&gt;
&lt;span class="nd"&gt;@Autowired&lt;/span&gt; 
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Example&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SomeBean&lt;/span&gt; &lt;span class="n"&gt;bean2&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt; &lt;span class="c1"&gt;// here spring looks for bean with name "bean2" in context to inject.&lt;/span&gt;
   &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;bean&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;bean2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;if no matching name bean found, follow step 2&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Step 2: Spring IoC container looks for bean marked as &lt;code&gt;@Primary&lt;/code&gt; bean
&lt;/h3&gt;

&lt;p&gt;So if no matching name bean found, then spring IoC Container check for if there is any bean among multiple beans which is marked as &lt;code&gt;@Primary&lt;/code&gt; bean, if yes inject that bean.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="nd"&gt;@Primary&lt;/span&gt; &lt;span class="c1"&gt;// this is primary bean&lt;/span&gt;
&lt;span class="nd"&gt;@Bean&lt;/span&gt; 
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;SomeBean&lt;/span&gt; &lt;span class="nf"&gt;myBean&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SomeBean&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;@Bean&lt;/span&gt; &lt;span class="c1"&gt;// this is normal bean&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;SomeBean&lt;/span&gt; &lt;span class="nf"&gt;myOtherBean&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SomeBean&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Welcome"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// when @Autowired is invoked, as we have multiple beans of same class type, @Primary bean will be injected for below wiring.&lt;/span&gt;

&lt;span class="nd"&gt;@Autowired&lt;/span&gt; 
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;SomeBean&lt;/span&gt; &lt;span class="n"&gt;bean&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// as no name bean matching with myBean, myOtherBean so Primary bean will be injected here.&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;If no &lt;code&gt;@Primary&lt;/code&gt; bean found in context, follow step 3&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Step 3: Spring IoC container will look for @Qualifier annotation and find the bean with name matching.
&lt;/h3&gt;

&lt;p&gt;Now, IoC container checks if &lt;code&gt;@Qualifier&lt;/code&gt; is used or not and if found look for the name of the bean mentioned in &lt;code&gt;@Qualifier&lt;/code&gt; and injects that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Bean&lt;/span&gt; 
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;SomeBean&lt;/span&gt; &lt;span class="nf"&gt;myBean&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SomeBean&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;@Bean&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;SomeBean&lt;/span&gt; &lt;span class="nf"&gt;myOtherBean&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SomeBean&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Welcome"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// when @Autowired is invoked, as we have multiple beans of same class type, @Primary bean not found checks name with @Qualifier and injects below&lt;/span&gt;

&lt;span class="nd"&gt;@Autowired&lt;/span&gt; &lt;span class="c1"&gt;// here qualifier used is "myBean" so IoC will inject the bean with name myBean&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Example&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@Qualifier&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"myBean"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nc"&gt;SomeBean&lt;/span&gt; &lt;span class="n"&gt;bean&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt; 
   &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;bean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bean&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Use of @Qualifier is beneficial as the parameter name can change based on developers choice to improve readability of code, but it will not impact the autowiring due to qualifier name used.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If all the above step followed and no matching bean is found then it will throw an exception &lt;code&gt;NoUniqueBeanDefinitionException&lt;/code&gt; as multiple beans are present but are ambiguious.&lt;/p&gt;






</description>
      <category>springboot</category>
      <category>spring</category>
      <category>java</category>
    </item>
    <item>
      <title>Difference between @Autowiring ➿&amp; @Inject 🔌</title>
      <dc:creator>MAYUR KUMBHAR</dc:creator>
      <pubDate>Sun, 18 Jun 2023 16:00:03 +0000</pubDate>
      <link>https://dev.to/themayurkumbhar/difference-between-autowiring-inject-18c6</link>
      <guid>https://dev.to/themayurkumbhar/difference-between-autowiring-inject-18c6</guid>
      <description>&lt;p&gt;In &lt;a href="https://dev.to/themayurkumbhar/wiring-in-spring-51lc"&gt;article&lt;/a&gt; we looked at how &lt;code&gt;wiring&lt;/code&gt; works in the spring framework, how to use the &lt;code&gt;@Autowired&lt;/code&gt; annotation and different ways to use it.&lt;br&gt;
Here we will briefly compare the &lt;code&gt;@Autowired&lt;/code&gt; annotation with &lt;code&gt;@Inject&lt;/code&gt; annotation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Qualifier support
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@Autowired&lt;/code&gt; built-in support the qualifier to qualify which exact bean to use foe dependency injection.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@Inject&lt;/code&gt; dose not have built-in support for qualifying the specific bean.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Standardization of annotation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@Autowired&lt;/code&gt; is annotation specific to spring framework and dose not work outside spring context&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@Inject&lt;/code&gt; is part of java dependency injection (&lt;a href="https://jcp.org/en/jsr/detail?id=330"&gt;JSR-330&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Optional Dependency Support
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@Autowired&lt;/code&gt; supports the optional dependency with &lt;code&gt;Optional&amp;lt;T&amp;gt;&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@Inject&lt;/code&gt; however dose not have built-in mechanism to make dependency as optional&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Framework Integration
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@Autowired&lt;/code&gt; is specifically developed to use with the spring framework.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@Inject&lt;/code&gt; is more general annotation can be used with any framework supporting the &lt;a href="https://jcp.org/en/jsr/detail?id=330"&gt;JSR-330&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that both &lt;code&gt;@Inject&lt;/code&gt; and &lt;code&gt;@Autowired&lt;/code&gt; serve the purpose of dependency injection and can be used effectively in their respective contexts&lt;/p&gt;
&lt;/blockquote&gt;




</description>
      <category>spring</category>
      <category>springboot</category>
      <category>java</category>
    </item>
    <item>
      <title>Wiring in Spring</title>
      <dc:creator>MAYUR KUMBHAR</dc:creator>
      <pubDate>Wed, 14 Jun 2023 14:48:30 +0000</pubDate>
      <link>https://dev.to/themayurkumbhar/wiring-in-spring-51lc</link>
      <guid>https://dev.to/themayurkumbhar/wiring-in-spring-51lc</guid>
      <description>&lt;h2&gt;
  
  
  Context
&lt;/h2&gt;

&lt;p&gt;Bean is most fundamental unit in spring framework which we have seen in previous posts. Bean creation may include creating the normal object which dose not have any dependency on other objects they solely can be created from the primitive data types.&lt;/p&gt;

&lt;p&gt;But most of the objects we create they depends on other objects either developer created or library objects. &lt;/p&gt;

&lt;p&gt;Now with bean we give control to spring framework how to create and manage the java objects in application. When there is dependency between the Objects, spring framework should understand and construct the dependent objects (beans) as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wiring
&lt;/h2&gt;

&lt;p&gt;So to enable the framework to create dependent beans objects and inject them on runtime whenever required this concept is called as &lt;strong&gt;"wiring"&lt;/strong&gt;. &lt;br&gt;
Here spring framework process the connection between the objects &amp;amp; make sure required objects are created and injected.&lt;/p&gt;
&lt;h2&gt;
  
  
  Ways to wire a bean
&lt;/h2&gt;

&lt;p&gt;Spring provides multiple ways to wire a bean, by dependency injection, annotation based wiring, xml-based wiring, java-based configuration wiring, component scanning.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Springboot provides the &lt;code&gt;@Autowired&lt;/code&gt; annotation to automatically wire the dependent objects.&lt;/p&gt;

&lt;p&gt;Similarly java has &lt;code&gt;@Inject&lt;/code&gt; annotation which more general dose can be used without spring, to wire the dependent objects.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;@Inject&lt;/code&gt; annotation is part of the Java Dependency Injection (JSR-330) standard, which is supported by frameworks like Spring&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Ways to use @Autowired annotation
&lt;/h2&gt;

&lt;p&gt;Annotation &lt;code&gt;@Autowired&lt;/code&gt; used with multiple ways via field injection, constructor injection, setter injection, optional dependency &amp;amp; with &lt;code&gt;@Qualifier&lt;/code&gt; annotation.&lt;/p&gt;
&lt;h3&gt;
  
  
  Field injection
&lt;/h3&gt;

&lt;p&gt;To inject the dependent object in bean, we can put &lt;code&gt;@Autowired&lt;/code&gt; annotation on the class fields, which then framework detects and injects the appropriate dependency.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="nd"&gt;@Autowired&lt;/span&gt; 
&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;ExampleBean&lt;/span&gt; &lt;span class="n"&gt;someBean&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Constructor injection
&lt;/h3&gt;

&lt;p&gt;While creating the bean, we can provide the constructor param as &lt;code&gt;@Autowired&lt;/code&gt; to inject the required object. Spring will automatically pass the require Object as param in constructor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="nd"&gt;@Autowired&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;ExampleBean&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;DependentBean&lt;/span&gt; &lt;span class="n"&gt;dependentBean&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
   &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;dependentBean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dependentBean&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setter injection
&lt;/h3&gt;

&lt;p&gt;Another way to inject the dependency is to use the setter method annotated with &lt;code&gt;@Autowired&lt;/code&gt;, So spring can use it to inject the required dependency.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="nd"&gt;@Autowired&lt;/span&gt; 
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setDependentBean&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;DependeentBean&lt;/span&gt; &lt;span class="n"&gt;bean&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
   &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;dependentBean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bean&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Optional Dependency injection
&lt;/h3&gt;

&lt;p&gt;Sometimes the dependency on object is optional, as with some objects can be created without depending on all the objects. This can be achieved using the &lt;code&gt;Optional&lt;/code&gt; and &lt;code&gt;required=false&lt;/code&gt; in the &lt;code&gt;@Autowired&lt;/code&gt;. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;By default the &lt;code&gt;@Autowired&lt;/code&gt; is not optional &amp;amp; always injects the dependency.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="nd"&gt;@Autowired&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;required&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DependentBean&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;bean&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Use of Qualifiers with Autowiring
&lt;/h2&gt;

&lt;p&gt;Sometime we have multiple beans in our context, now if we only specify the &lt;code&gt;@Autowired&lt;/code&gt; on the field, constructor, setter Spring frameworks get confused on which exact dependency to inject as there are multiple objects of same type are available in context.&lt;/p&gt;

&lt;p&gt;To remove ambiguity and provide exact dependent object to inject we use &lt;code&gt;@Qualifier&lt;/code&gt; with &lt;code&gt;value&lt;/code&gt; to specify the which exact bean to use for this dependency injection.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="nd"&gt;@Autowired&lt;/span&gt; 
&lt;span class="nd"&gt;@Qualifier&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"someSpecificBean"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;DependentBean&lt;/span&gt; &lt;span class="n"&gt;bean&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;@Inject&lt;/code&gt; can also be used similar to &lt;code&gt;@Autowired&lt;/code&gt; annotation, with slight difference.&lt;/p&gt;
&lt;/blockquote&gt;






</description>
      <category>spring</category>
      <category>springboot</category>
      <category>java</category>
    </item>
    <item>
      <title>@PreDestroy annotation in spring 💥</title>
      <dc:creator>MAYUR KUMBHAR</dc:creator>
      <pubDate>Tue, 13 Jun 2023 17:21:14 +0000</pubDate>
      <link>https://dev.to/themayurkumbhar/predestroy-annotation-in-spring-3mmi</link>
      <guid>https://dev.to/themayurkumbhar/predestroy-annotation-in-spring-3mmi</guid>
      <description>&lt;h2&gt;
  
  
  Need of the @PreDestroy annotation
&lt;/h2&gt;

&lt;p&gt;Sometime in our application we have perform some business operations before the destroy the bean of a class. Such business logic can be performed with &lt;code&gt;@PreDestroy&lt;/code&gt; annotation. &lt;/p&gt;

&lt;h2&gt;
  
  
  How to use?
&lt;/h2&gt;

&lt;p&gt;Below code snippet help in understanding how to configure the &lt;code&gt;@PreDestroy&lt;/code&gt; annotation on bean.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="nd"&gt;@Component&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BeanExample&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;BeanExample&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@PreDestroy&lt;/span&gt; 
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;destroy&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Doing destructive operations!"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whenever the bean of &lt;code&gt;BeanExample&lt;/code&gt; class about to get destroyed the code in method &lt;code&gt;destroy()&lt;/code&gt; will be invoked. Here in case of our example it will output &lt;code&gt;Doing destructive operations!&lt;/code&gt; when you close the context &lt;code&gt;annotationConfigApplicationContext.close()&lt;/code&gt; by deliberately destroying all the beans.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use?
&lt;/h2&gt;

&lt;p&gt;When you want to perform some business operations on the bean during the closing/removing/end of lifecycle you can use the &lt;code&gt;@PreDestroy&lt;/code&gt; annotation. Some common use case can be to close the IO resources, release the dependent objects, close acquired connections such as DB connections etc.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Most of the time the spring framework is handling all the resource closing, destruction related activities, but in case you have some scenarios where you want to perform tasks before the bean is destroyed you can use the annotation.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>springboot</category>
      <category>spring</category>
      <category>annotations</category>
      <category>java</category>
    </item>
    <item>
      <title>@PostContruct Annotation in Spring</title>
      <dc:creator>MAYUR KUMBHAR</dc:creator>
      <pubDate>Tue, 13 Jun 2023 17:20:58 +0000</pubDate>
      <link>https://dev.to/themayurkumbhar/postcontruct-annotation-in-spring-3m7m</link>
      <guid>https://dev.to/themayurkumbhar/postcontruct-annotation-in-spring-3m7m</guid>
      <description>&lt;h2&gt;
  
  
  Issue?
&lt;/h2&gt;

&lt;p&gt;Spring beans are most basic building block of spring framework. We have seen ways we can create the beans in spring in &lt;a href="https://dev.to/themayurkumbhar/bean-vs-component-in-spring-23em"&gt;this post&lt;/a&gt; and its benefits. We also understood that there is drawback of using &lt;code&gt;@Component&lt;/code&gt; annotation for bean creation.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;With &lt;code&gt;@Component&lt;/code&gt; you can not specify or configure how the bean is created, spring framework is responsible for creating &amp;amp; configuring the bean. With Normal &lt;code&gt;@Bean&lt;/code&gt; annotation developer have more control on bean creation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Solves?
&lt;/h2&gt;

&lt;p&gt;To solve the issue of having some control on created bean using &lt;code&gt;@Component&lt;/code&gt; annotation, spring provides another annotation which is called &lt;code&gt;@PostConstruct&lt;/code&gt; annotation inspired from the Java EE edition.&lt;/p&gt;

&lt;p&gt;With help of &lt;code&gt;@PostContruct&lt;/code&gt; annotation, after the bean is created developer can execute the desired code. This annotation is applied on the method of the bean class which marked as &lt;code&gt;@Component&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="nd"&gt;@Component&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BeanExample&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;BeanExample&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@PostConstruct&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"DEFAULT_STRING"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;printName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we get the object after spring has created the bean of &lt;code&gt;BeanExample&lt;/code&gt; class, we can call the &lt;code&gt;printName()&lt;/code&gt; on the bean and verify that the &lt;code&gt;DEFAULT_STRING&lt;/code&gt; is set as part of &lt;code&gt;PostContruct&lt;/code&gt; code execution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use?
&lt;/h2&gt;

&lt;p&gt;Whenever the application requires the some business logic to be applied after the specific object is created we can use this annotation to perform the action e.g. initialize with default values.&lt;/p&gt;

</description>
      <category>springboot</category>
      <category>annotations</category>
      <category>spring</category>
      <category>java</category>
    </item>
    <item>
      <title>Bean vs Component in Spring</title>
      <dc:creator>MAYUR KUMBHAR</dc:creator>
      <pubDate>Fri, 09 Jun 2023 16:45:06 +0000</pubDate>
      <link>https://dev.to/themayurkumbhar/bean-vs-component-in-spring-23em</link>
      <guid>https://dev.to/themayurkumbhar/bean-vs-component-in-spring-23em</guid>
      <description>&lt;h2&gt;
  
  
  @Bean in Spring
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;more than one instance of class can be added to spring context&lt;/li&gt;
&lt;li&gt;we can create bean of any class, from libraries classes as well as user defined classes&lt;/li&gt;
&lt;li&gt;need to write specific code methods to create the instances&lt;/li&gt;
&lt;li&gt;developer is in control of how to create &amp;amp; configure the objects&lt;/li&gt;
&lt;li&gt;spring will create the beans based on the instructions, configuration specified by the developer&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  @Component in Spring
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;only one instance of class can be added to spring context&lt;/li&gt;
&lt;li&gt;only user defined class can be marked as component to instantiate as bean, library class objects can not instantiated&lt;/li&gt;
&lt;li&gt;only the &lt;code&gt;@Component&lt;/code&gt; annotation is required to add on class, no more code is required&lt;/li&gt;
&lt;li&gt;developer will not have control on how to create &amp;amp; configure bean&lt;/li&gt;
&lt;li&gt;spring framework is in charge of creating the bean &amp;amp; post that developer will have access to bean&lt;/li&gt;
&lt;/ol&gt;




&lt;blockquote&gt;
&lt;p&gt;Sometimes you want to create bean based on the certain conditions are met. Developer can create the objects manually and register them to spring context with help of &lt;code&gt;context.registerBean("&amp;lt;name_of_bean&amp;gt;", &amp;lt;class_of_bean&amp;gt;.class, &amp;lt;Supplier&amp;gt;)&lt;/code&gt; basic method. There are multiple ways you can register a bean.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>springboot</category>
      <category>spring</category>
    </item>
    <item>
      <title>Spring IoC container 📦</title>
      <dc:creator>MAYUR KUMBHAR</dc:creator>
      <pubDate>Sun, 28 May 2023 13:13:49 +0000</pubDate>
      <link>https://dev.to/themayurkumbhar/spring-ioc-container-3gf4</link>
      <guid>https://dev.to/themayurkumbhar/spring-ioc-container-3gf4</guid>
      <description>&lt;p&gt;Spring IoC container is the component in spring core framework. Lifecycle of bean is maintained by this container. This container converts the java objects into the beans by provided configurations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Spring IoC container responsibilities:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;instantiate the application class&lt;/li&gt;
&lt;li&gt;configure object&lt;/li&gt;
&lt;li&gt;assemble the dependencies between objects&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Types of IoC
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Bean Factory - Basic IoC container, no advance feature, only bean creation, maintenance, auto wiring &amp;amp; injecting dependencies. &lt;/li&gt;
&lt;li&gt;Application Context - advanced IoC provides all features of Bean Factory &amp;amp; on top of it provides extra features like event handling based on bean events.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>spring</category>
      <category>basics</category>
      <category>container</category>
    </item>
    <item>
      <title>Spring Beans 🫘&amp; Context</title>
      <dc:creator>MAYUR KUMBHAR</dc:creator>
      <pubDate>Sun, 28 May 2023 12:40:05 +0000</pubDate>
      <link>https://dev.to/themayurkumbhar/spring-beans-context-dh1</link>
      <guid>https://dev.to/themayurkumbhar/spring-beans-context-dh1</guid>
      <description>&lt;h2&gt;
  
  
  Bean
&lt;/h2&gt;

&lt;p&gt;A java class which is maintained by the spring framework, it is called as &lt;code&gt;Bean&lt;/code&gt; in spring. Its fundamental building block of spring framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  How spring knows which class maintain as Bean?
&lt;/h2&gt;

&lt;p&gt;We can configures the beans using the annotations or XML configurations in spring. Based on configurations available spring container instantiates and assembles them to become bean in spring. IoC container help to maintain the lifecycle of the beans.&lt;/p&gt;

&lt;h2&gt;
  
  
  Spring Context
&lt;/h2&gt;

&lt;p&gt;Context is memory location of web application in which all the objects instantiated by the framework are present and managed by the context framework.&lt;br&gt;
By default spring dose not know all the objects in the application, based on the configuration spring will instantiate &amp;amp; maintain the object during the initialization so all the information related to those object is available inside spring context.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If object dose not available in spring context then spring dose not know about the object.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  SpEL - spring expression language
&lt;/h2&gt;

&lt;p&gt;It is the expression language provided by the spring framework to perform the operations such as manipulating object graph like setting, getting property values, property assignments &amp;amp; method invocations etc.&lt;/p&gt;

</description>
      <category>spring</category>
      <category>beans</category>
      <category>basics</category>
    </item>
  </channel>
</rss>
