<?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: Phoenix</title>
    <description>The latest articles on DEV Community by Phoenix (@phoenix_238501d86d417e).</description>
    <link>https://dev.to/phoenix_238501d86d417e</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%2F2105472%2F08677fa2-ad87-48ad-b9d1-33ff0bbb848c.png</url>
      <title>DEV Community: Phoenix</title>
      <link>https://dev.to/phoenix_238501d86d417e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/phoenix_238501d86d417e"/>
    <language>en</language>
    <item>
      <title>LLM vs Agentic AI</title>
      <dc:creator>Phoenix</dc:creator>
      <pubDate>Mon, 02 Mar 2026 06:57:11 +0000</pubDate>
      <link>https://dev.to/phoenix_238501d86d417e/llm-vs-agentic-ai-9bc</link>
      <guid>https://dev.to/phoenix_238501d86d417e/llm-vs-agentic-ai-9bc</guid>
      <description>&lt;p&gt;&lt;strong&gt;LLM&lt;/strong&gt;&lt;br&gt;
An LLM (like OpenAI’s GPT models) reads text and predicts what words should come next. It can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Answer questions&lt;/li&gt;
&lt;li&gt;Write emails&lt;/li&gt;
&lt;li&gt;Explain concepts&lt;/li&gt;
&lt;li&gt;Translate languages&lt;/li&gt;
&lt;li&gt;Help with code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But here’s the key thing:&lt;/p&gt;

&lt;p&gt;👉 It only responds when you ask it something.&lt;br&gt;
👉 It doesn’t take actions on its own.&lt;br&gt;
👉 It doesn’t have goals.&lt;/p&gt;

&lt;p&gt;ChatGPT, Claude (in basic chat mode) = LLMs in action&lt;/p&gt;

&lt;p&gt;It’s like a very smart assistant waiting for instructions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agentic AI&lt;/strong&gt;&lt;br&gt;
Agentic AI is more like:&lt;br&gt;
An AI that can act to achieve a goal.&lt;/p&gt;

&lt;p&gt;Instead of just answering, it can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make a plan&lt;/li&gt;
&lt;li&gt;Use tools (search the web, run code, access apps)&lt;/li&gt;
&lt;li&gt;Make decisions without you guiding each step&lt;/li&gt;
&lt;li&gt;Try again if something fails&lt;/li&gt;
&lt;li&gt;Work step-by-step toward a goal&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Claude Code, ChatGPT with plugins doing multi-step tasks = Agentic AI&lt;br&gt;
It behaves more like an independent worker than just a chatbot.&lt;/p&gt;

&lt;p&gt;Most agentic AI systems actually use LLMs inside them.&lt;/p&gt;

&lt;p&gt;Think of it like this:&lt;/p&gt;

&lt;p&gt;LLM = the brain&lt;/p&gt;

&lt;p&gt;Agentic system = the brain + hands + memory + ability to act&lt;/p&gt;

</description>
      <category>agents</category>
      <category>ai</category>
      <category>beginners</category>
      <category>llm</category>
    </item>
    <item>
      <title>Annotation in SpringBoot Web Application</title>
      <dc:creator>Phoenix</dc:creator>
      <pubDate>Mon, 02 Feb 2026 07:29:45 +0000</pubDate>
      <link>https://dev.to/phoenix_238501d86d417e/annotation-in-springboot-web-application-19lh</link>
      <guid>https://dev.to/phoenix_238501d86d417e/annotation-in-springboot-web-application-19lh</guid>
      <description>&lt;p&gt;&lt;strong&gt;Core Spring&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Component&lt;/code&gt;&lt;br&gt;
Marks a class as a Spring-managed bean so it can be automatically created and injected.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Service&lt;/code&gt;&lt;br&gt;
Used for business logic classes; it’s a specialized form of @Component.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Autowired&lt;/code&gt;&lt;br&gt;
Tells Spring to automatically inject a required dependency.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Bean&lt;/code&gt;&lt;br&gt;
Defines a bean inside a configuration class.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Configuration&lt;/code&gt;&lt;br&gt;
Marks a class that contains Spring bean definitions.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Primary&lt;/code&gt;&lt;br&gt;
Marks a bean as the default choice when multiple beans are available.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Qualifier&lt;/code&gt;&lt;br&gt;
Used when multiple beans exist to specify which one should be injected.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Repository&lt;/code&gt;&lt;br&gt;
“Used for data access classes and also enables automatic exception translation.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Controller&lt;/code&gt;&lt;br&gt;
Marks a class as a web controller that handles HTTP requests.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@RestController&lt;/code&gt;&lt;br&gt;
A controller that returns data (usually JSON) instead of views.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spring Boot&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;@SpringBootApplication&lt;/code&gt;&lt;br&gt;
Main annotation that enables auto-configuration, component scanning, and configuration support.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@EnableAutoConfiguration&lt;/code&gt;&lt;br&gt;
Allows Spring Boot to automatically configure beans based on the project setup.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@ComponentScan&lt;/code&gt;&lt;br&gt;
Tells Spring where to look for components.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Value&lt;/code&gt;&lt;br&gt;
Used to read values from application.properties.&lt;/p&gt;

</description>
      <category>springboot</category>
      <category>spring</category>
      <category>java</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Password Management - SpringBoot</title>
      <dc:creator>Phoenix</dc:creator>
      <pubDate>Mon, 02 Feb 2026 06:12:39 +0000</pubDate>
      <link>https://dev.to/phoenix_238501d86d417e/password-management-springboot-56n3</link>
      <guid>https://dev.to/phoenix_238501d86d417e/password-management-springboot-56n3</guid>
      <description>&lt;p&gt;&lt;strong&gt;Why Password Hashing Is Needed&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Storing passwords in plain text is dangerous.&lt;br&gt;
If a database is leaked, attackers immediately get all user passwords.&lt;/p&gt;

&lt;p&gt;So instead of storing passwords, we store &lt;strong&gt;hashed values.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A hash is a one-way mathematical function that converts a password into an unreadable string.&lt;br&gt;
You cannot reverse it to get the original password.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mypassword → $2a$10$Hf7sd8KJH...3fd2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How Login Works with Hashed Passwords&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When a user logs in:&lt;/li&gt;
&lt;li&gt;User enters password&lt;/li&gt;
&lt;li&gt;Spring Security hashes the entered password&lt;/li&gt;
&lt;li&gt;It compares the new hash with the stored hash in DB&lt;/li&gt;
&lt;li&gt;If both match → login succeeds&lt;/li&gt;
&lt;li&gt;The original password is never stored or compared&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;PasswordEncoder in Spring Security&lt;/p&gt;

&lt;p&gt;Spring Security uses an interface called:&lt;/p&gt;

&lt;p&gt;PasswordEncoder&lt;/p&gt;

&lt;p&gt;It has two main methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String encode(CharSequence rawPassword);
boolean matches(CharSequence rawPassword, String encodedPassword);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best Algorithm: BCrypt&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spring recommends BCrypt because it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uses salt automatically&lt;/li&gt;
&lt;li&gt;Is slow (harder for hackers to brute force)&lt;/li&gt;
&lt;li&gt;Is adaptive (can be made stronger over time)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Bean
public PasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why Salting Matters&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Without salt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;password → hash

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

&lt;/div&gt;



&lt;p&gt;With salt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;password + randomValue → hash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even if two users have the same password, their hashes will be different.&lt;/p&gt;

&lt;p&gt;BCrypt handles salting automatically.&lt;/p&gt;

&lt;p&gt;“A salt is a random value added to a password before hashing to make each hash unique and protect against rainbow-table and brute-force attacks.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Salt Works&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User creates a password&lt;/li&gt;
&lt;li&gt;System generates a random salt&lt;/li&gt;
&lt;li&gt;Password + salt are hashed together&lt;/li&gt;
&lt;li&gt;Both salt and hash are stored in the database&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$2a$10$WERTY...SALT...HASH
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When user logs in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spring Security extracts the salt from the stored hash&lt;/li&gt;
&lt;li&gt;It hashes the entered password using that same salt&lt;/li&gt;
&lt;li&gt;If hashes match → login succeeds&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>security</category>
      <category>springboot</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Tomcat Server - Servlet Container</title>
      <dc:creator>Phoenix</dc:creator>
      <pubDate>Sat, 31 Jan 2026 09:48:55 +0000</pubDate>
      <link>https://dev.to/phoenix_238501d86d417e/tomcat-server-servlet-container-53og</link>
      <guid>https://dev.to/phoenix_238501d86d417e/tomcat-server-servlet-container-53og</guid>
      <description>&lt;p&gt;&lt;strong&gt;Tomcat is the web server that runs your Spring application and connects it to the browser.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Servlet?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Java web development, a Servlet is just a Java class that:&lt;/p&gt;

&lt;p&gt;Receives an HTTP request and returns an HTTP response&lt;/p&gt;

&lt;p&gt;Like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Browser  →  Servlet  →  Response (HTML / JSON)
&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 plaintext"&gt;&lt;code&gt;GET /login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Servlet runs Java code and returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Welcome&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But…&lt;/p&gt;

&lt;p&gt;A servlet cannot run by itself&lt;br&gt;
It needs a Servlet Container&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Servlet Container?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Servlet Container is a software that:&lt;/p&gt;

&lt;p&gt;✔ Starts your servlets&lt;br&gt;
✔ Listens to HTTP requests&lt;br&gt;
✔ Calls the right servlet&lt;br&gt;
✔ Sends the response back&lt;br&gt;
✔ Manages threads, memory, security&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Servlet Container = Runtime environment for servlets&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So we need something that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Opens port 8080&lt;/li&gt;
&lt;li&gt;Accepts browser requests&lt;/li&gt;
&lt;li&gt;Runs your servlet Java code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That “something” is called a &lt;strong&gt;Servlet Container&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Tomcat?&lt;/strong&gt;&lt;br&gt;
Apache Tomcat is a Servlet Container&lt;/p&gt;

&lt;p&gt;Tomcat’s job is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Browser → Tomcat → Servlet → Response → Tomcat → Browser&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tomcat:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Opens a port (like 8080)&lt;/li&gt;
&lt;li&gt;Understands HTTP&lt;/li&gt;
&lt;li&gt;Runs servlets&lt;/li&gt;
&lt;li&gt;Manages lifecycle of web apps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Without Tomcat, your Spring web app is just Java files — nobody can access it via browser.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spring is a framework that helps you write Java code.&lt;/p&gt;

&lt;p&gt;So Spring needs Tomcat to run on.&lt;/p&gt;

&lt;p&gt;Think like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Spring Boot Application
    ↓
Runs inside Tomcat
    ↓
Tomcat runs inside JVM
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happens when you run a Spring Boot app?&lt;/p&gt;

&lt;p&gt;When you click Run on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@SpringBootApplication
public class MyApp {
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring Boot:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Starts Tomcat internally&lt;/li&gt;
&lt;li&gt;Registers Spring as a servlet&lt;/li&gt;
&lt;li&gt;Tomcat listens on port 8080&lt;/li&gt;
&lt;li&gt;Requests come in&lt;/li&gt;
&lt;li&gt;Tomcat forwards them to Spring&lt;/li&gt;
&lt;li&gt;Spring runs your controllers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you create a Spring Boot Web project, this dependency is added automatically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;spring-boot-starter-web
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside it is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;spring-boot-starter-tomcat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring Boot comes with Tomcat built-in by default&lt;/p&gt;

&lt;p&gt;Spring Boot creates exactly &lt;strong&gt;ONE main servlet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is called:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DispatcherServlet

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;This is Spring’s front controller.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is DispatcherServlet?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is a special servlet written by Spring.&lt;/p&gt;

&lt;p&gt;Tomcat talks only to servlets.&lt;br&gt;
So Spring creates one servlet and tells Tomcat:&lt;/p&gt;

&lt;p&gt;“Send all requests to this servlet.”&lt;/p&gt;

&lt;p&gt;So flow becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Browser
   ↓
Tomcat
   ↓
DispatcherServlet (Spring)
   ↓
Your @Controller / @RestController

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;One DispatcherServlet
        |
        |-- "/login" → login()
        |-- "/register" → register()
        |-- "/products" → products()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So:&lt;/p&gt;

&lt;p&gt;Spring has one servlet but thousands of routes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happens internally when you hit a URL in Spring Boot?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You type this in browser&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:8080/hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;1️⃣ &lt;strong&gt;Browser sends HTTP request&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Browser sends:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /hello
Host: localhost:8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This goes to…&lt;/p&gt;

&lt;p&gt;2️⃣ &lt;strong&gt;Tomcat (Web Server)&lt;/strong&gt;&lt;br&gt;
Tomcat is running because Spring Boot started it.&lt;/p&gt;

&lt;p&gt;Tomcat:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is listening on port 8080&lt;/li&gt;
&lt;li&gt;Receives the HTTP request&lt;/li&gt;
&lt;li&gt;But Tomcat doesn’t know Spring controllers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It only knows:&lt;/p&gt;

&lt;p&gt;“I must send requests to a servlet”&lt;/p&gt;

&lt;p&gt;Spring registered one servlet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DispatcherServlet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So Tomcat forwards request to it.&lt;/p&gt;

&lt;p&gt;3️⃣&lt;strong&gt;DispatcherServlet (Heart of Spring MVC)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;DispatcherServlet receives:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4️⃣ &lt;strong&gt;HandlerMapping&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spring looks in HandlerMapping&lt;br&gt;
This is just an internal routing table.&lt;/p&gt;

&lt;p&gt;It finds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/hello → HelloController.hello()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5️⃣ &lt;strong&gt;Spring calls your method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your controller runs:&lt;/p&gt;

&lt;p&gt;Now it asks:&lt;/p&gt;

&lt;p&gt;“Which controller method should handle /hello?”&lt;/p&gt;

&lt;p&gt;To answer that, Spring has built a map when app started:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/hello  →  hello()
/login  →  login()
/users  →  getUsers()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Annotation  Returns&lt;br&gt;
@Controller HTML page&lt;br&gt;
@RestController JSON / Text / Data&lt;/p&gt;

&lt;p&gt;@RestController = @Controller + @ResponseBody&lt;/p&gt;

</description>
      <category>spring</category>
      <category>springboot</category>
      <category>backend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Beans using Autowiring</title>
      <dc:creator>Phoenix</dc:creator>
      <pubDate>Thu, 29 Jan 2026 15:49:32 +0000</pubDate>
      <link>https://dev.to/phoenix_238501d86d417e/beans-using-autowiring-50bg</link>
      <guid>https://dev.to/phoenix_238501d86d417e/beans-using-autowiring-50bg</guid>
      <description>&lt;p&gt;Creating beans alone is not enough.&lt;br&gt;
They must also be wired together.&lt;/p&gt;

&lt;p&gt;That wiring is what Autowiring (DI) does.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What does “wiring” mean?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Connecting beans together by injecting one bean into another.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Car → needs → Engine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Autowired
Engine engine;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring injects the dependency for you.&lt;/p&gt;

&lt;p&gt;That is &lt;strong&gt;autowiring.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is @Autowired?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;@Autowired tells Spring to automatically inject a required dependency into a Spring Bean.&lt;/p&gt;

&lt;p&gt;It is Spring’s way of doing Dependency Injection&lt;/p&gt;

&lt;p&gt;When &lt;code&gt;@Autowired&lt;/code&gt; is on a &lt;code&gt;setter&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Component
class Car {

    private Engine engine;

    @Autowired
    public void setEngine(Engine engine) {
        this.engine = engine;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might wonder:&lt;/p&gt;

&lt;p&gt;“Who calls this setter? I never call it.”&lt;/p&gt;

&lt;p&gt;Spring does.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happens internally?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When Spring starts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spring creates the Car object using its constructor&lt;/li&gt;
&lt;li&gt;Spring looks for any @Autowired methods&lt;/li&gt;
&lt;li&gt;It finds setEngine(...)&lt;/li&gt;
&lt;li&gt;It looks for an Engine bean&lt;/li&gt;
&lt;li&gt;It finds it in the context&lt;/li&gt;
&lt;li&gt;It calls the setter&lt;/li&gt;
&lt;li&gt;car.setEngine(engineBean);&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The dependency is injected&lt;/p&gt;

&lt;p&gt;This happens automatically during bean creation.&lt;/p&gt;

&lt;p&gt;Beans define which objects Spring manages, and autowiring defines how those objects are connected to each other through dependency injection.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>java</category>
      <category>springboot</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Creating Spring Beans</title>
      <dc:creator>Phoenix</dc:creator>
      <pubDate>Thu, 29 Jan 2026 09:42:15 +0000</pubDate>
      <link>https://dev.to/phoenix_238501d86d417e/creating-spring-beans-lf</link>
      <guid>https://dev.to/phoenix_238501d86d417e/creating-spring-beans-lf</guid>
      <description>&lt;p&gt;When you use Spring without Spring Boot, you start by creating something called the &lt;strong&gt;ApplicationContext&lt;/strong&gt;.&lt;br&gt;
This object is the &lt;strong&gt;Spring IoC container&lt;/strong&gt; — it is the place where Spring keeps and manages all the objects it creates.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ApplicationContext context =
        new AnnotationConfigApplicationContext(AppConfig.class);

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

&lt;/div&gt;



&lt;p&gt;Here, you are telling Spring:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“Start your container and use AppConfig as the configuration.”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is AppConfig?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AppConfig is a class you write and mark with @Configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Configuration
public class AppConfig {
}

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

&lt;/div&gt;



&lt;p&gt;This tells Spring:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This class contains methods that create objects Spring should manage (factory of Spring Beans)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Inside this class, you write methods marked with &lt;code&gt;@Bean&lt;/code&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Configuration
public class AppConfig {

    @Bean
    public Engine engine() {
        return new Engine();
    }

    @Bean
    public Car car() {
        return new Car(engine());
    }
}

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

&lt;/div&gt;



&lt;p&gt;Each &lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/bean"&gt;@bean&lt;/a&gt;&lt;/strong&gt; method:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The object returned by this method should be stored in the Spring context as a Bean.&lt;/li&gt;
&lt;li&gt;And hands it over to Spring&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Spring then takes that object and stores it inside the &lt;strong&gt;ApplicationContext.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These stored objects are called &lt;strong&gt;Spring Beans&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happens when the context is created?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When this line runs:&lt;/p&gt;

&lt;p&gt;new AnnotationConfigApplicationContext(AppConfig.class);&lt;/p&gt;

&lt;p&gt;Spring does the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reads AppConfig&lt;/li&gt;
&lt;li&gt;Finds all methods marked with &lt;a class="mentioned-user" href="https://dev.to/bean"&gt;@bean&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Calls those methods&lt;/li&gt;
&lt;li&gt;Creates the objects (Engine, Car)&lt;/li&gt;
&lt;li&gt;Stores them inside the context&lt;/li&gt;
&lt;li&gt;Keeps track of their dependencies and lifecycle&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now the IoC container fully controls these objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do you use them?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of writing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Car car = new Car();

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Car car = context.getBean(Car.class);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring gives you the object it created and manages.&lt;/p&gt;

&lt;p&gt;That is Inversion of Control:&lt;br&gt;
Spring controls object creation, not you.&lt;/p&gt;

&lt;p&gt;Putting it all together&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@Configuration&lt;/code&gt; tells Spring where the bean definitions are&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@Bean&lt;/code&gt; tells Spring which objects to create&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;AnnotationConfigApplicationContext&lt;/code&gt; starts the IoC container&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ApplicationContext&lt;/code&gt; stores and manages the beans&lt;/li&gt;
&lt;li&gt;You ask the context for objects instead of using new&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;@Component&lt;/strong&gt; is one of the most important Spring annotations — it’s how you tell Spring:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“Please create and manage an object of this class.”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is @Component?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;@Component marks a class as a Spring Bean so that Spring will automatically create and manage its object in the IoC container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Component
public class Engine {
}

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

&lt;/div&gt;



&lt;p&gt;This tells Spring:&lt;/p&gt;

&lt;p&gt;“When the context starts, create an Engine object and store it.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Spring finds it&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the ApplicationContext starts, Spring performs component scanning.&lt;/p&gt;

&lt;p&gt;It looks through your packages and finds classes annotated with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;@Component&lt;/li&gt;
&lt;li&gt;@Service&lt;/li&gt;
&lt;li&gt;@Repository&lt;/li&gt;
&lt;li&gt;@Controller
These are all forms of &lt;code&gt;@Component&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr4gd4crrtmc3cal5v3ur.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr4gd4crrtmc3cal5v3ur.png" alt=" " width="800" height="401"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>spring</category>
      <category>springboot</category>
      <category>java</category>
    </item>
    <item>
      <title>Spring Beans, Context, Spring IoC container</title>
      <dc:creator>Phoenix</dc:creator>
      <pubDate>Thu, 29 Jan 2026 07:16:10 +0000</pubDate>
      <link>https://dev.to/phoenix_238501d86d417e/spring-beans-context-2ijm</link>
      <guid>https://dev.to/phoenix_238501d86d417e/spring-beans-context-2ijm</guid>
      <description>&lt;p&gt;&lt;strong&gt;Spring Beans&lt;/strong&gt;&lt;br&gt;
we hear a lot about beans when we are working with spring&lt;/p&gt;

&lt;p&gt;A Spring Bean is any Java object that is instantiated, configured, and managed by the Spring IoC container.&lt;/p&gt;

&lt;p&gt;a Bean is a POJO(Plain Old Java Object)&lt;br&gt;
But not every POJO is a Bean.&lt;/p&gt;

&lt;p&gt;A Bean = POJO + managed by Spring&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What does “managed by Spring” mean?&lt;/strong&gt;&lt;br&gt;
Spring:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creates the object&lt;/li&gt;
&lt;li&gt;Stores it in the container&lt;/li&gt;
&lt;li&gt;Injects its dependencies&lt;/li&gt;
&lt;li&gt;Controls its lifecycle&lt;/li&gt;
&lt;li&gt;Destroys it when the app shuts down&lt;/li&gt;
&lt;li&gt;Only such objects are called Beans.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is  not mandatory that every class inside your application should be beans, like (utilities classes)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How spring knows which needs to be maintained?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;with the help of configurations that we supply either through XML files or Annotations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Context&lt;/strong&gt;&lt;br&gt;
context is like a memory location where we add all the object instances that we want the framework to manage. by default spring doesn't know any of the objects that we define in the application. to enable spring to see your object you need to add them to the context.&lt;/p&gt;

&lt;p&gt;We add classes to the Spring context by annotating them so that Spring can create and manage their objects as beans.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Spring IoC container *&lt;/em&gt;&lt;br&gt;
The Spring IoC Container is the core part of Spring that creates, manages, and injects application objects (beans) and controls their lifecycle.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy5zhz0ml13rdzd7v764m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy5zhz0ml13rdzd7v764m.png" alt=" " width="800" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s the &lt;strong&gt;big picture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When a Spring (or Spring Boot) application starts, the first thing it creates is something called the ApplicationContext.&lt;br&gt;
This ApplicationContext is the Spring IoC container.&lt;/p&gt;

&lt;p&gt;You can think of it as Spring’s brain and memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What does this IoC container do?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It looks at your project and searches for classes marked with things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;@Component&lt;/li&gt;
&lt;li&gt;@Service&lt;/li&gt;
&lt;li&gt;@Repository&lt;/li&gt;
&lt;li&gt;@Controller&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These annotations tell Spring:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;“You are allowed to manage this class.”&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spring then creates objects of those classes and stores them inside the ApplicationContext.&lt;/p&gt;

&lt;p&gt;These objects are called Spring Beans.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bean&lt;/strong&gt;→ the object Spring creates from that class&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Context&lt;/strong&gt; → where Spring stores and manages those objects&lt;/p&gt;

&lt;p&gt;In simple words:&lt;br&gt;
Spring creates a context (IoC container), puts your beans inside it, and then runs your application using those beans.&lt;/p&gt;

</description>
      <category>spring</category>
      <category>springboot</category>
      <category>java</category>
    </item>
    <item>
      <title>IoC and DI</title>
      <dc:creator>Phoenix</dc:creator>
      <pubDate>Thu, 29 Jan 2026 06:49:37 +0000</pubDate>
      <link>https://dev.to/phoenix_238501d86d417e/ioc-and-di-md4</link>
      <guid>https://dev.to/phoenix_238501d86d417e/ioc-and-di-md4</guid>
      <description>&lt;p&gt;IoC and DI are the core principles that spring framework follows&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inversion of Control&lt;/strong&gt; - It is a software design principle, in which the control of object creation and dependency management should be transferred from application code to framework or container. &lt;br&gt;
It is just a guideline that says who takes the control of creation? but not how to imeplement it.&lt;br&gt;
it just describes the way how objects are created. control of object creation should be shifted from application code to external entity or framework&lt;/p&gt;

&lt;p&gt;IoC is just this rule:&lt;/p&gt;

&lt;p&gt;A class must not decide or create the objects it depends on.&lt;/p&gt;

&lt;p&gt;It does not say:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Who will create them&lt;/li&gt;
&lt;li&gt;How they will be passed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It only says:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;“The control must be outside the class.”&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dependency Injection&lt;/strong&gt; - it is a design principle that implements IoC, where the dependencies are injected from outside through a framework, but not created by object itself.&lt;/p&gt;

&lt;p&gt;It reduces coupling between objects as it is dynamically injected by framework.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of IoC and DI&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Loose coupling - Don't have to change your code whenever the dependencies gets changed.&lt;/li&gt;
&lt;li&gt;minimises the amount of code.&lt;/li&gt;
&lt;li&gt;make unit testing very easy with different mock tests.&lt;/li&gt;
&lt;li&gt;increased system maintainability and module reusability.&lt;/li&gt;
&lt;li&gt;allows concurrent independent development.&lt;/li&gt;
&lt;li&gt;replacing modules has no side-effects on other modules.&lt;/li&gt;
&lt;li&gt;even if the requirements in future, we don't have to make lot of changes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Spring is called an &lt;strong&gt;IoC Container&lt;/strong&gt; because it stores application objects and takes control of their creation, lifecycle, and dependency wiring instead of the application code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzh4ff7hf96rkl5vjkilr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzh4ff7hf96rkl5vjkilr.png" alt=" " width="800" height="586"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;using spring framework&lt;br&gt;
we just define these are the dependencies of my class, during runtime execution the framework automatically creates this objects and injects them into this class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkx5w6evxpq0mvutgaija.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkx5w6evxpq0mvutgaija.png" alt=" " width="574" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>spring</category>
      <category>java</category>
      <category>springboot</category>
    </item>
    <item>
      <title>OS Notes - 1</title>
      <dc:creator>Phoenix</dc:creator>
      <pubDate>Tue, 01 Oct 2024 15:10:10 +0000</pubDate>
      <link>https://dev.to/phoenix_238501d86d417e/os-notes-1-3ioj</link>
      <guid>https://dev.to/phoenix_238501d86d417e/os-notes-1-3ioj</guid>
      <description>&lt;p&gt;*&lt;em&gt;Operating Systems - *&lt;/em&gt;&lt;br&gt;
It acts as an intermediate between computer applications and it's hardware. The OS handles tasks such as running applications, managing files, and controlling hardware like the keyboard, mouse, and printer, so you don’t have to manage these details yourself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multiprogramming Operating System -&lt;/strong&gt; Multiprogramming utilizes the CPU more efficiently. The OS assigns a process to the CPU and when it waits for I/O the CPU assigns another process in the queue to the CPU. The main aim is not to keep the CPU idle.&lt;br&gt;
&lt;strong&gt;Multitasking Operating System -&lt;/strong&gt; In multitasking, each job or process is given some time to execute and the operating system switches the jobs after a certain interval of time. The switch is so quick that the user can interact with each program as it runs. This is also known as Time Sharing OS.&lt;/p&gt;

&lt;p&gt;Process - &lt;br&gt;
A process is a large independent program that is in execution.&lt;br&gt;
Thread is small component in the process that performs individual tasks within program like running different parts of it at the same time.&lt;/p&gt;

&lt;p&gt;Threads can directly communicate between each other because it shares memory space where as for process, OS interventatioon takes place.&lt;br&gt;
There are two types of threads.&lt;br&gt;
&lt;strong&gt;User threads&lt;/strong&gt; - It is implemented by the user.&lt;br&gt;
&lt;strong&gt;Kernel threads&lt;/strong&gt; - It is implemented by the Operating System.&lt;/p&gt;

&lt;p&gt;A thread has its own &lt;strong&gt;program counter&lt;/strong&gt;, &lt;strong&gt;register set&lt;/strong&gt;, and &lt;strong&gt;stack&lt;/strong&gt;&lt;br&gt;
A thread shares resources with other threads of the same process the code section, the data section, files and signals.&lt;/p&gt;

&lt;p&gt;Context Switching- A context switch is the action of the computer switching from one task to another. It's necessary to efficiently manage different tasks and make sure they all get a turn to run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Process Scheduling Algorithms&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;First Come First Serve (FCFS)&lt;/strong&gt; - It schedules the Process according to the arrival time. The process which arrives first is scheduled first. It is the simplest scheduling algorithm.&lt;br&gt;
&lt;strong&gt;Shortest Job First (SJF)&lt;/strong&gt; - The Process which has the shortest execution time or Burst time is scheduled first in this algorithm.&lt;br&gt;
&lt;strong&gt;Shortest Remaining Time First&lt;/strong&gt; - The only difference between SJF and this is preemption happens in this. The processes are scheduled according to the shortest remaining time for execution.&lt;br&gt;
&lt;strong&gt;Round Robin Scheduling&lt;/strong&gt; - In Round Robin each process is cyclically assigned a fixed time. Each process executes for a certain time and waits for its turn again.&lt;br&gt;
&lt;strong&gt;Priority Scheduling&lt;/strong&gt; - In Priority Scheduling, processes are scheduled according to their priority. The process which has higher priority is scheduled first and so on.&lt;br&gt;
&lt;strong&gt;Multilevel Queue Scheduling&lt;/strong&gt; - There are multiple queues in this algorithm according to the priority of the processes. The processes with higher priority are placed in one queue and lower ones in another similarly. The processes with lower priority are executed only after the execution of all higher priority processes.&lt;br&gt;
*&lt;em&gt;Multilevel Queue with Feedback *&lt;/em&gt;- This also uses the multiple queues concept but the processes may be moved from lower priority queue to higher priority queue according to their feedback. If a process needs lower CPU time, it can be moved to a higher priority queue and vice versa.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Race Around Condition&lt;/strong&gt;&lt;br&gt;
This condition occurs when more than one process tries to access the same data at the same time and tries to manipulate it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Process Synchronization&lt;/strong&gt; is the coordination of execution of multiple processes in a multi-process system to ensure that they access shared resources in a controlled and predictable manner. It aims to resolve the problem of race conditions and other synchronization issues in a concurrent system. &lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;critical section&lt;/strong&gt; is a code segment that can be accessed by only one process at a time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Semaphore&lt;/strong&gt;&lt;br&gt;
A semaphore is a variable that is used to prevent the simultaneous access of common resources by one or more threads in concurrent systems.&lt;/p&gt;

&lt;p&gt;A deadlock is a situation where multiple processes or threads are stuck because they're waiting for each other to release something. It can be prevented with careful design and resolved by outside intervention or by making one of the processes let go.&lt;br&gt;
It is an unwanted situation in which processes block each other by holding one resource and waiting for another resource that is held by some other process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Virtual Memory&lt;/strong&gt;&lt;br&gt;
Virtual memory is a technique that lets a computer use more memory than it actually has. It does this by using a combination of RAM (real memory) and space on the computer's hard drive to store data that might not fit entirely in RAM.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Task Scheduler</title>
      <dc:creator>Phoenix</dc:creator>
      <pubDate>Thu, 26 Sep 2024 07:08:11 +0000</pubDate>
      <link>https://dev.to/phoenix_238501d86d417e/task-scheduler-3mia</link>
      <guid>https://dev.to/phoenix_238501d86d417e/task-scheduler-3mia</guid>
      <description>&lt;p&gt;&lt;strong&gt;Problem link&lt;/strong&gt; -  &lt;a href="https://leetcode.com/problems/task-scheduler/description/" rel="noopener noreferrer"&gt;Task Scheduler&lt;/a&gt;&lt;br&gt;
You are given an array of CPU tasks, each labeled with a letter from A to Z, and a number n. Each CPU interval can be idle or allow the completion of one task. Tasks can be completed in any order, but there's a constraint: there has to be a gap of at least n intervals between two tasks with the same label.&lt;/p&gt;

&lt;p&gt;Return the minimum number of CPU intervals required to complete all tasks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Input: tasks = ["A","A","A","B","B","B"], n = 2&lt;br&gt;
Output: 8&lt;br&gt;
Explanation: A possible sequence is: A -&amp;gt; B -&amp;gt; idle -&amp;gt; A -&amp;gt; B -&amp;gt; idle -&amp;gt; A -&amp;gt; B.&lt;br&gt;
After completing task A, you must wait two intervals before doing A again. The same applies to task B. In the 3rd interval, neither A nor B can be done, so you idle. By the 4th interval, you can do A again as 2 intervals have passed.&lt;br&gt;
&lt;strong&gt;Example 2:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Input: tasks = ["A","C","A","B","D","B"], n = 1&lt;br&gt;
Output: 6&lt;br&gt;
Explanation: A possible sequence is: A -&amp;gt; B -&amp;gt; C -&amp;gt; D -&amp;gt; A -&amp;gt; B.&lt;br&gt;
With a cooling interval of 1, you can repeat a task after just one other task.&lt;br&gt;
&lt;strong&gt;Approach&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;One key observation is that the task which appears more frequently needs to be executed first because delaying it causes more idle time, increasing the total time required to execute all tasks. Therefore, we will allow the most frequent task to be executed in the CPU whenever it is permitted, thus minimizing the chances of idle time.&lt;/li&gt;
&lt;li&gt;We will use a Max-Heap to keep track of the most frequent tasks and a map to store the frequency of each task. Every task frequency will be pushed into the Max-Heap.&lt;/li&gt;
&lt;li&gt;Additionally, we will maintain a cooldown queue that stores tasks if there are still instances left to execute. These tasks will be added to the queue along with the remaining executions and the next time when they can be executed.&lt;/li&gt;
&lt;li&gt;Whenever the cooldown period for a particular task expires, it will be removed from the queue and added back to the Max-Heap.&lt;/li&gt;
&lt;li&gt;A timer will count every step, whether it's an executed task or idle time.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    int leastInterval(vector&amp;lt;char&amp;gt;&amp;amp; tasks, int n) {
        priority_queue&amp;lt;int,vector&amp;lt;int&amp;gt;&amp;gt; pq;
        unordered_map&amp;lt;char,int&amp;gt; mp;
        queue&amp;lt;pair&amp;lt;int,int&amp;gt;&amp;gt; cooldown;
        // int maxi=1;
        for(int i=0;i&amp;lt;tasks.size();i++){
            mp[tasks[i]]++;
            // maxi=max(maxi,mp[tasks[i]]);
        }
        for(auto it: mp){
            pq.push(it.second);
            cout&amp;lt;&amp;lt;it.second&amp;lt;&amp;lt;endl;
        }
        int timer=0;
        while(!pq.empty() ||!cooldown.empty()){
            timer+=1;
            if(!pq.empty()){
                int task=pq.top()-1;
                // cout&amp;lt;&amp;lt;task;
                if(task&amp;gt;0){
                    cooldown.push({task,timer+n});
                }
                pq.pop();
            }
            if(!cooldown.empty()){
                if(cooldown.front().second==timer){
                    pq.push(cooldown.front().first);
                    cooldown.pop();
                }
            }

        }
        return timer;

    }

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Time complexity:&lt;/strong&gt;&lt;br&gt;
Main while loop:&lt;br&gt;
The number of iterations the loop runs is equal to the total time required to finish all tasks (including idle times). Hence, O(timer)&lt;br&gt;
Operations inside the loop:&lt;br&gt;
Heap: pop/push operations = O(logk), where k is the length of heap.&lt;br&gt;
Queue operations are O(1)&lt;br&gt;
Overall: O(timer*logk) as the dominant time complexity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Space complexity:&lt;/strong&gt;&lt;br&gt;
Overall, space complexity is O(n), where n is the number of unique tasks.&lt;br&gt;
Map: Uses O(n) space to store the frequency of each unique task.&lt;br&gt;
Max Heap: Can hold up to n unique tasks, so its space complexity is O(n).&lt;br&gt;
Cooldown Queue: Similarly, the cooldown queue can hold up to n unique tasks, so it also uses O(n) space.&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>dsa</category>
      <category>cpp</category>
      <category>learning</category>
    </item>
    <item>
      <title>Minimum Number of Platforms Required</title>
      <dc:creator>Phoenix</dc:creator>
      <pubDate>Wed, 25 Sep 2024 21:02:56 +0000</pubDate>
      <link>https://dev.to/phoenix_238501d86d417e/minimum-number-of-platforms-required-175k</link>
      <guid>https://dev.to/phoenix_238501d86d417e/minimum-number-of-platforms-required-175k</guid>
      <description>&lt;p&gt;&lt;strong&gt;Problem Statement:&lt;/strong&gt; We are given two arrays that represent the arrival and departure times of trains that stop at the platform. We need to find the minimum number of platforms needed at the railway station so that no train has to wait.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Input: N=6, &lt;br&gt;
arr[] = {9:00, 9:45, 9:55, 11:00, 15:00, 18:00} &lt;br&gt;
dep[] = {9:20, 12:00, 11:30, 11:50, 19:00, 20:00}&lt;br&gt;
Output:3&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Intuition:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;our goal is find the minimum number of platforms required so that no station waits. this means we have to track the maximum number of trains that are at the station at any point of time. this will give the minimum platforms that we want.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You are given two arrays:&lt;br&gt;
arr[]: the arrival times of trains.&lt;br&gt;
dep[]: the departure times of trains.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;how many trains are present at the station at any given moment?&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;for each train if it is at the station(hasn't departured), and a new train arrives you need a new platform. So, the task is to check at any moment how many trains overlap (i.e., are at the station at the same time). More overlaps mean more platforms are required.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Sort the trains according to arrival time&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To process the trains in order, you first sort them by their arrival time.&lt;/li&gt;
&lt;li&gt;intially for the first train one platform is needed.&lt;/li&gt;
&lt;li&gt;to keep track of departure times of trains, we will use a &lt;strong&gt;min-heap&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;it will help us in finding the train that is departuring soon.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;For every train&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;compare its arrival time with the departure times of trains that are already at the station (these departure times are stored in the min-heap).&lt;/li&gt;
&lt;li&gt;If the earliest departing train (the one on the top of the heap) has already left (i.e., its departure time is less than the arrival time of the current train), you can remove that train from the heap, freeing up a platform.&lt;/li&gt;
&lt;li&gt;add the current train's departure time to the heap (indicating that the platform is now occupied by the current train).&lt;/li&gt;
&lt;li&gt;at any time the size of heap tells us the how many platforms are occupied.&lt;/li&gt;
&lt;li&gt;so update the ans also to min of previous answer and size of heap.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct node {
    int arr;
    int dep;
};

// Comparison function to sort trains by arrival times
static bool comp(node a, node b) {
    return a.arr &amp;lt; b.arr;
}

int findPlatform(std::vector&amp;lt;int&amp;gt;&amp;amp; arr, std::vector&amp;lt;int&amp;gt;&amp;amp; dep) {
    int n = arr.size();
    vector&amp;lt;node&amp;gt; temp(n);

    // Initialize the temp array with arrival and departure times
    for (int i = 0; i &amp;lt; n; i++) {
        temp[i].arr=arr[i];
        temp[i].dep=dep[i];
    }

    // Sort the trains by their arrival times
   sort(temp.begin(), temp.end(), comp);

    // Min-heap to track the minimum departure time
    priority_queue&amp;lt;int, vector&amp;lt;int&amp;gt;, greater&amp;lt;int&amp;gt;&amp;gt; pq;

    // Push the first train's departure time
    pq.push(temp[0].dep);

    int ans = 1; // The minimum number of platforms required (at least 1)

    // Iterate over the rest of the trains
    for (int i = 1; i &amp;lt; n; i++) {
        // Remove all trains that have already departed by the time the current train arrives
        while (!pq.empty() &amp;amp;&amp;amp; pq.top() &amp;lt; temp[i].arr) {
            pq.pop();
        }

        // Push the current train's departure time
        pq.push(temp[i].dep);

        // Update the answer with the maximum size of the heap (i.e., the maximum number of overlapping trains)
        ans = max(ans, (int)pq.size());
    }

    return ans;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Time Complexity:&lt;/strong&gt;&lt;br&gt;
Sorting: O(n log n), where n is the number of trains.&lt;br&gt;
Heap Operations: Each train involves push and possibly pop operations, which are O(log n) per train. Thus, this part also takes O(n log n).&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>dsa</category>
      <category>cpp</category>
      <category>learning</category>
    </item>
    <item>
      <title>Minimum distance in an Array</title>
      <dc:creator>Phoenix</dc:creator>
      <pubDate>Wed, 25 Sep 2024 19:36:46 +0000</pubDate>
      <link>https://dev.to/phoenix_238501d86d417e/minimum-distance-in-an-array-m5</link>
      <guid>https://dev.to/phoenix_238501d86d417e/minimum-distance-in-an-array-m5</guid>
      <description>&lt;p&gt;&lt;strong&gt;Problem Link&lt;/strong&gt; - &lt;a href="https://leetcode.com/problems/shortest-word-distance/description/" rel="noopener noreferrer"&gt;Minimum Distance&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You are given an array a, of n elements. Find the minimum index based distance between two distinct elements of the array, x and y. Return -1, if either x or y does not exist in the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Input: arr[] = {1, 2}, x = 1, y = 2&lt;br&gt;
Output: Minimum distance between 1 and 2 is 1.&lt;br&gt;
Input: arr[] = {3, 4, 5}, x = 3, y = 5&lt;br&gt;
Output: Minimum distance between 3 and 5 is 2.&lt;br&gt;
Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6&lt;br&gt;
Output: Minimum distance between 3 and 6 is 4.&lt;br&gt;
Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2&lt;br&gt;
Output: Minimum distance between 3 and 2 is 1.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Approach&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Initialize two indices i1 and i2 to -1 to store the most recent indices of x and y found during the traversal of the array.&lt;/li&gt;
&lt;li&gt;Initialize a variable mini to a large value (e.g., INT_MAX) to keep track of the minimum distance. &lt;/li&gt;
&lt;li&gt;Traverse through the array and find the indices of x and y,if both were found then calculate the distance between them and update the mini variable.if again we found the x or y, then calcuate the distance with previously found x or y and update the mini variable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    int minDist(int a[], int n, int x, int y) {
        // code here
        int mini=INT_MAX;
        int i1=-1;
        int i2=-1;
        for(int i=0;i&amp;lt;n;i++){
            if(a[i]==x){
                i1=i;
            }
            else if(a[i]==y){
                i2=i;
            }
            if(i1!=-1&amp;amp;&amp;amp;i2!=-1){
                mini=min(mini,abs(i2-i1));
            }
        }
        if(i1==-1 || i2==-1){
            return -1;
        }
        return mini;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>leetcode</category>
      <category>dsa</category>
      <category>cpp</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
