<?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: Anupam Tarai</title>
    <description>The latest articles on DEV Community by Anupam Tarai (@anupam_tarai_3250344e48cd).</description>
    <link>https://dev.to/anupam_tarai_3250344e48cd</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%2F1656233%2F42ec15ce-5496-4801-b8db-572880a5b40b.jpg</url>
      <title>DEV Community: Anupam Tarai</title>
      <link>https://dev.to/anupam_tarai_3250344e48cd</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anupam_tarai_3250344e48cd"/>
    <language>en</language>
    <item>
      <title>Implement a Global Handler for UserNotFoundException</title>
      <dc:creator>Anupam Tarai</dc:creator>
      <pubDate>Sun, 01 Sep 2024 01:20:36 +0000</pubDate>
      <link>https://dev.to/anupam_tarai_3250344e48cd/enhance-exception-handling-and-implement-global-exception-handler-for-usernotfoundexception-22ap</link>
      <guid>https://dev.to/anupam_tarai_3250344e48cd/enhance-exception-handling-and-implement-global-exception-handler-for-usernotfoundexception-22ap</guid>
      <description>

&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;This implementation enhances the exception handling mechanism within the Journal REST API application by defining a custom exception, &lt;code&gt;UserNotFoundException&lt;/code&gt;, and implementing a global exception handler to manage this exception effectively. The goal is to centralize exception handling, improving code maintainability and consistency.&lt;/p&gt;

&lt;p&gt;Got to &lt;a href="https://github.com/a-n-u-p-01/Journal-Rest-API/issues/4" rel="noopener noreferrer"&gt;Issue&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Tasks
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Define &lt;code&gt;UserNotFoundException&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Create a custom exception class named &lt;code&gt;UserNotFoundException&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Implement Global Exception Handler
&lt;/h3&gt;

&lt;p&gt;Implement a global exception handler to manage the &lt;code&gt;UserNotFoundException&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Refactor Existing Code
&lt;/h3&gt;

&lt;p&gt;Refactor the existing controller code to remove local handling of &lt;code&gt;UserNotFoundException&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  How to Contribute
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Fork the repository:&lt;/strong&gt; &lt;a href="https://github.com/a-n-u-p-01/Journal-Rest-API" rel="noopener noreferrer"&gt;Journal-Rest-API&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Clone the repository:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/yourusername/Journal-Rest-API.git
&lt;span class="nb"&gt;cd &lt;/span&gt;Journal-Rest-API
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a new branch:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; enhance-exception-handling
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Make your changes and commit them:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Enhance exception handling and implement global exception handler for UserNotFoundException"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Push to the branch:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push origin enhance-exception-handling
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a pull request:&lt;/strong&gt; Go to the repository on GitHub and create a pull request.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By enhancing the exception handling mechanism and implementing a global exception handler, we can improve the maintainability and consistency of the codebase. I welcome contributions from the community to help me achieve this goal.&lt;/p&gt;




&lt;p&gt;Feel free to reach out if you have any questions or need further assistance. Happy coding!&lt;/p&gt;

</description>
      <category>contributorswanted</category>
      <category>springboot</category>
      <category>java</category>
      <category>github</category>
    </item>
    <item>
      <title>Enhance Your Debugging Skills by Contributing to the Journal REST API</title>
      <dc:creator>Anupam Tarai</dc:creator>
      <pubDate>Wed, 28 Aug 2024 11:03:26 +0000</pubDate>
      <link>https://dev.to/anupam_tarai_3250344e48cd/enhance-your-debugging-skills-by-contributing-to-the-journal-rest-api-2f74</link>
      <guid>https://dev.to/anupam_tarai_3250344e48cd/enhance-your-debugging-skills-by-contributing-to-the-journal-rest-api-2f74</guid>
      <description>&lt;p&gt;Hello, fellow developers!&lt;/p&gt;

&lt;p&gt;Are you looking to improve your debugging skills while contributing to an open-source project? Our Journal REST API project is the perfect opportunity for you to dive into a real-world Spring Boot application, debug issues, and make meaningful contributions.&lt;br&gt;
&lt;a href="https://github.com/a-n-u-p-01/Journal-Rest-API" rel="noopener noreferrer"&gt;Contribute to the Journal REST API on GitHub&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  About the Journal REST API
&lt;/h2&gt;

&lt;p&gt;The Journal REST API is a Spring Boot application designed to manage journal entries for users. It provides endpoints for creating, reading, updating, and deleting journal entries, as well as user management functionalities. The project prioritizes security and privacy with encrypted data transmission and robust access controls.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Contribute?
&lt;/h2&gt;

&lt;p&gt;Contributing to open-source projects is a fantastic way to improve your coding skills, learn new technologies, and collaborate with other developers. Here are some specific benefits of contributing to our project:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Enhance Your Debugging Skills:&lt;/strong&gt; Debugging is a crucial skill for any developer. By contributing to our project, you'll get hands-on experience with debugging a real-world application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Learn Spring Boot:&lt;/strong&gt; If you're new to Spring Boot, this project is an excellent way to get familiar with its features and best practices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collaborate and Share Knowledge:&lt;/strong&gt; Working on open-source projects allows you to collaborate with other developers, share knowledge, and learn from each other.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Contribution Guidelines
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Fork the repository:&lt;/strong&gt; Click the "Fork" button at the top right of the repository page. &lt;a href="https://github.com/a-n-u-p-01/Journal-Rest-API" rel="noopener noreferrer"&gt;Journal REST API Repository&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clone your fork:&lt;/strong&gt; Clone your forked repository to your local machine.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a new branch:&lt;/strong&gt; Create a new branch for your changes.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; my-feature-branch
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;Make your changes:&lt;/strong&gt; Make your changes to the codebase.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Commit your changes:&lt;/strong&gt; Commit your changes with a descriptive commit message.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Description of my changes"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Push your changes:&lt;/strong&gt; Push your changes to your forked repository.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;git push origin my-feature-branch
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;Submit a pull request:&lt;/strong&gt; Go to the original repository and submit a pull request.&lt;/p&gt;&lt;/li&gt;

&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I welcome contributions from developers of all skill levels. Whether you're a seasoned Spring Boot developer or just getting started, there's something for everyone in this project. By contributing, you'll not only improve your debugging skills but also help make the Journal REST API better for everyone.&lt;/p&gt;

&lt;p&gt;If you have any questions or need help, feel free to reach out. Thank you!&lt;/p&gt;




</description>
      <category>springboot</category>
      <category>java</category>
      <category>restapi</category>
      <category>contributorswanted</category>
    </item>
    <item>
      <title>Thread In Java</title>
      <dc:creator>Anupam Tarai</dc:creator>
      <pubDate>Sat, 22 Jun 2024 15:22:08 +0000</pubDate>
      <link>https://dev.to/anupam_tarai_3250344e48cd/thread-in-java-2f6e</link>
      <guid>https://dev.to/anupam_tarai_3250344e48cd/thread-in-java-2f6e</guid>
      <description>&lt;ul&gt;
&lt;li&gt;A thread is a small part of a process capable of execute independently.&lt;/li&gt;
&lt;li&gt;Java supports multithreading, allowing a process to be divided into multiple threads. These threads can be scheduled by the CPU to execute in parallel, improving the performance of the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creation of a Thread
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We can create a thread by extending the 'Thread' class or implementing the 'Runnable' interface. Override the run method inside the thread.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  CODE
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class A extends Thread{ //A is a thread that extends "Thread" class
    public void run(){ //Override the run method
        for (int i=0; i&amp;lt;10; i++){
        System.out.println("AAAA");
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

class B implements Runnable{ //B is a thread that impliments "Runnable" interface
    public void run(){ //Override the run method
        for (int i=0; i&amp;lt;10; i++){
            System.out.println("BB");
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

public class Server {
   public static void main(String[] args){
        A a = new A();
        B b = new B();
        Thread Tb = new Thread(b); // we need to pass that runnable into the costructor of thread class to create a thread
        a.start();
       try {
           Thread.sleep(10);
       } catch (InterruptedException e) {
           throw new RuntimeException(e);
       }
       Tb.start();

    }
}

Output:
AAAA
AAAA
BB
BB
AAAA
AAAA
BB
AAAA
BB
BB
AAAA
BB
AAAA
AAAA
BB
BB
AAAA
BB
AAAA
BB

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

&lt;/div&gt;



&lt;p&gt;Here we have two classes, A and B, both representing threads. When we start the threads using the start method, both threads begin executing in parallel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Methods in the Thread Class
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;start():&lt;/strong&gt; Starts the thread's execution; the JVM calls the thread's run method.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;run():&lt;/strong&gt; Contains the code to be executed by the thread.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;join():&lt;/strong&gt; Waits for the thread to die. If called on a thread, the calling thread will wait until the thread on which join was called finishes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;sleep(long millis):&lt;/strong&gt; Causes the current thread to sleep for the specified number of milliseconds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;interrupt():&lt;/strong&gt; Interrupts the thread, causing it to stop its current task and handle the interruption (if it checks for interruptions).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  CONCLUSION
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Threads are helpful in large applications that require more time and resources to execute. By dividing such applications into multiple threads and executing them in parallel, the performance of the application can be significantly increased.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Please comment below if I have made any mistakes or if you know any additional concepts related to this topic.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>Thread and Process</title>
      <dc:creator>Anupam Tarai</dc:creator>
      <pubDate>Fri, 21 Jun 2024 02:46:54 +0000</pubDate>
      <link>https://dev.to/anupam_tarai_3250344e48cd/thread-53h1</link>
      <guid>https://dev.to/anupam_tarai_3250344e48cd/thread-53h1</guid>
      <description>&lt;h2&gt;
  
  
  What is a Thread? Let's understand it.
&lt;/h2&gt;

&lt;p&gt;As we know, every computational device has a CPU, in which all the operations or code executions are done. Some CPUs can execute only one process at a time, which is known as a single-core CPU. In modern computers, CPUs are multi-core. Multi-core CPUs allow the execution of multiple code blocks or multiple processes simultaneously.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A thread is the smallest unit of a process. Mordern OS supports multithreading. It divides the process into smaller units/thread to execute multiple parts of the process concurrently, maximizing CPU utilization.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Process VS Thread
&lt;/h2&gt;

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

&lt;h2&gt;
  
  
  Process
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A process is a independent program in execution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It has it's own memory space, computer resource and execution context.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Each process is operate/execute in isolation from other processes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Processes are managed by operating system and have their own address space, Which means they do not share memory directly with other processes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Thread
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A thread is a smaller unit of a process. It is sometimes referred to as a "lightweight process."&lt;/li&gt;
&lt;li&gt;Threads within the same process share the same memory space and resources. This allows for easier communication and data sharing between threads.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Differences
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Memory and Resource Allocation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Process:&lt;/strong&gt; Each process has its own memory space and resources. Inter-process communication (IPC) mechanisms like pipes, sockets, or shared memory are needed for processes to communicate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thread:&lt;/strong&gt;Threads within the same process share the same memory space and resources. This makes inter-thread communication faster and more efficient, as they can directly access shared data.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Process:&lt;/strong&gt; Processes are isolated from each other. A crash in one process typically does not affect others.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thread:&lt;/strong&gt;Threads are not isolated. A crash in one thread can potentially bring down the entire process.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Creation and Context Switching:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Process:&lt;/strong&gt; Creating and context switching between processes is more expensive in terms of time and system resources because it involves switching the entire memory space and resources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thread:&lt;/strong&gt;Creating and context switching between threads is faster and more efficient since threads share the same memory space and resources.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Process:&lt;/strong&gt;Processes require explicit IPC mechanisms to communicate, which can be complex and slower.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thread:&lt;/strong&gt; Threads can communicate directly through shared memory, making inter-thread communication faster and simpler.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Process:&lt;/strong&gt; Processes can run concurrently, but they require more system resources. Useful for running separate applications or tasks that do not need to share data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thread:&lt;/strong&gt; Threads allow for more fine-grained concurrency within a single application, enabling better utilization of multi-core processors for parallel tasks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Processes:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Suitable for running independent applications.&lt;br&gt;
Useful when tasks need strong isolation for security or stability.&lt;br&gt;
Examples: Web servers, database servers, separate programs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Threads:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ideal for tasks that require shared data or resources.&lt;br&gt;
Useful for parallelism within a single application to improve performance.&lt;br&gt;
Examples: Multi-threaded applications like web browsers, games, or parallel computations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Processes offer strong isolation but are more resource-intensive and slower in context switching.&lt;br&gt;
Threads provide faster context switching and efficient communication but require careful management to avoid issues like race conditions and deadlocks due to shared resources.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Please comment below if I have made any mistakes or if you know any additional concepts related to this topic.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>backend</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
