<?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>Forem: Priyanshu Belwal</title>
    <description>The latest articles on Forem by Priyanshu Belwal (@priyanshubelwal).</description>
    <link>https://forem.com/priyanshubelwal</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%2F647656%2F11b07d13-38d3-4bf0-9c7e-d62b8236a137.jpeg</url>
      <title>Forem: Priyanshu Belwal</title>
      <link>https://forem.com/priyanshubelwal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/priyanshubelwal"/>
    <language>en</language>
    <item>
      <title>Strict Mode in JavaScript: A Comprehensive Guide</title>
      <dc:creator>Priyanshu Belwal</dc:creator>
      <pubDate>Thu, 04 Jan 2024 13:01:19 +0000</pubDate>
      <link>https://forem.com/priyanshubelwal/strict-mode-in-javascript-a-comprehensive-guide-b2f</link>
      <guid>https://forem.com/priyanshubelwal/strict-mode-in-javascript-a-comprehensive-guide-b2f</guid>
      <description>&lt;p&gt;Javascript is a widely used programming language, famous for its dynamic nature. As a good developer, we tends to write clean, maintainable and error-free code. There are various tools and features which enhances the language's capabilities and helps developers to write more robuts and reliable JavaScript code. &lt;strong&gt;Strict Mode&lt;/strong&gt; is also a set of rules introduced in ECMAScript 5 (ES5) to help developers for the same.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Strict Mode?
&lt;/h3&gt;

&lt;p&gt;Strict Mode is a feature in JavaScript that allows developers to opt into a more restricted and disciplined variant of the language. When enabled, it catches common coding mistakes, prevents the use of certain error-prone features, and promotes writing secure and maintainable code. Strict Mode was introduced to address some of the language's design flaws and provide a safer development environment.&lt;/p&gt;

&lt;p&gt;To enable Strict Mode, we simply add the following directive to the top of our JavaScript file or within a function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why Strict Mode:
&lt;/h3&gt;

&lt;p&gt;There are some benefits included in Strict Mode, which are following:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Error Prevention
&lt;/h4&gt;

&lt;p&gt;Strict Mode helps catch common coding errors by turning them into explicit exceptions. For example, in non-strict mode, assigning a value to an undeclared variable would create a global variable. In Strict Mode, this would throw a ReferenceError, preventing accidental global variable leakage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Non-strict mode&lt;/span&gt;
&lt;span class="nx"&gt;undeclaredVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// No error, creates a global variable&lt;/span&gt;

&lt;span class="c1"&gt;// Strict mode&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;undeclaredVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Throws a ReferenceError&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Elimination of Silent Failures
&lt;/h4&gt;

&lt;p&gt;In non-strict mode, some actions may fail silently, leading to unexpected behavior. Strict Mode makes these failures more noticeable by turning them into errors. For instance, assignments to read-only properties and assignments to undeclared variables are flagged as errors in Strict Mode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Non-strict mode&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;defineProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;x&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;writable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// No error, fails silently&lt;/span&gt;

&lt;span class="c1"&gt;// Strict mode&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;defineProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;x&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;writable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Throws a TypeError&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Safer Code
&lt;/h4&gt;

&lt;p&gt;Strict Mode prohibits certain "unsafe" actions, such as using with statements and assigning values to read-only properties. By disallowing these practices, developers are encouraged to adopt safer alternatives, leading to more reliable code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Non-strict mode&lt;/span&gt;
&lt;span class="nf"&gt;with &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// May lead to unexpected behavior&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Strict mode&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;with &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Throws a SyntaxError&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Strict Mode Restrictions
&lt;/h3&gt;

&lt;p&gt;Below are some of the restrictions in Strict Mode, described in brief:&lt;/p&gt;

&lt;h5&gt;
  
  
  1. Variable Declarations:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Undeclared Variables:&lt;/strong&gt; Assigning a value to an undeclared variable throws a &lt;code&gt;ReferenceError&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Duplicate Parameter Names:&lt;/strong&gt; Defining a function with duplicate parameter names results in a &lt;code&gt;SyntaxError&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  2. Assignments
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Read-only Properties:&lt;/strong&gt; Assigning a value to a read-only property or a non-writable global variable throws a &lt;code&gt;TypeError&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assignment to eval and arguments:&lt;/strong&gt; Assigning values to &lt;code&gt;eval&lt;/code&gt; and &lt;code&gt;arguments&lt;/code&gt; is prohibited.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  3. Functions
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Octal Syntax:&lt;/strong&gt; Octal literals (e.g., &lt;code&gt;0123&lt;/code&gt;) are not allowed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;with Statements:&lt;/strong&gt; The use of &lt;code&gt;with&lt;/code&gt; statements is forbidden.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;arguments Object:&lt;/strong&gt; Writing to the &lt;code&gt;arguments&lt;/code&gt; object doesn't affect named parameters.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  4. Miscellaneous
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;delete Operator:&lt;/strong&gt; Deleting variables, functions, or function arguments is not allowed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Restricted Identifiers:&lt;/strong&gt; Using certain keywords, such as &lt;code&gt;eval&lt;/code&gt; and &lt;code&gt;arguments&lt;/code&gt;, as variable or function names is not allowed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;this Binding:&lt;/strong&gt; Assigning values to &lt;code&gt;this&lt;/code&gt; in non-constructor functions is prohibited.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Strict Mode in JavaScript is a valuable tool for developers aiming to write safer and more maintainable code. By catching common errors, eliminating silent failures, and imposing stricter rules, it helps prevent bugs and enhances code quality. While it may introduce a learning curve for those accustomed to more lenient JavaScript, the long-term benefits in terms of code reliability and maintainability make it a worthwhile addition to any development workflow.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Securing Kubernetes with RBAC: A Quick Guide</title>
      <dc:creator>Priyanshu Belwal</dc:creator>
      <pubDate>Tue, 26 Dec 2023 02:07:08 +0000</pubDate>
      <link>https://forem.com/priyanshubelwal/securing-kubernetes-with-rbac-a-quick-guide-3gd0</link>
      <guid>https://forem.com/priyanshubelwal/securing-kubernetes-with-rbac-a-quick-guide-3gd0</guid>
      <description>&lt;p&gt;Role-Based Access Control (RBAC) serves as a fundamental pillar in safeguarding and regulating access within the bustling Kubernetes ecosystem, where services, pods, and nodes act as diverse entities. Similar to a city's need for a comprehensive system to manage access to buildings and resources, Kubernetes relies on RBAC to control access to its myriad resources.&lt;/p&gt;

&lt;p&gt;In a distributed and segmented operational landscape, RBAC provides granular control over user permissions, preventing chaos in a multi-tenant environment. Without RBAC, managing permissions would be equivalent to leaving the doors of a secure facility unlocked, risking unauthorized access.&lt;/p&gt;

&lt;p&gt;At its core, Kubernetes RBAC revolves around defining roles with specific permissions, assigning these roles to users or groups, and tailoring access rights precisely to the cluster's needs. This approach ensures both security and operational efficiency within the Kubernetes environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Roles and ClusterRoles:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Roles operate at the namespace level, defining a set of permissions for resources within a specific namespace. ClusterRoles, on the other hand, operate at the cluster level, providing permissions across all namespaces.&lt;/li&gt;
&lt;li&gt;Roles are used to grant access within a limited scope, allowing fine-grained control over resources like pods, services, and deployments. ClusterRoles are suitable for granting broad access to cluster-wide resources like nodes, persistent volumes, and other non-namespaced objects.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  i. Role Example In Kubernetes:
&lt;/h4&gt;

&lt;p&gt;A Role in the “ns-sample-system” namespace granting read access to pods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: ns-sample-system
  name: pod-reader
rules:
- apiGroups: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
  resources: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pods"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
  verbs: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"get"&lt;/span&gt;, &lt;span class="s2"&gt;"watch"&lt;/span&gt;, &lt;span class="s2"&gt;"list"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  ii. ClusterRole Example In Kubernetes:
&lt;/h4&gt;

&lt;p&gt;A ClusterRole, which is granting read access to secrets across all namespaces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: secret-reader
rules:
- apiGroups: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
  resources: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"secrets"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
  verbs: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"get"&lt;/span&gt;, &lt;span class="s2"&gt;"watch"&lt;/span&gt;, &lt;span class="s2"&gt;"list"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Understanding Verbs Used in RBAC:
&lt;/h2&gt;

&lt;p&gt;Kubernetes actions are defined in the form of Verbs like below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get: Allows reading a specific resource.&lt;/li&gt;
&lt;li&gt;List: Permits listing all instances of a resource.&lt;/li&gt;
&lt;li&gt;Watch: Enables watching changes to a particular resource.&lt;/li&gt;
&lt;li&gt;Create: Grants the ability to create new instances of a resource.&lt;/li&gt;
&lt;li&gt;Update: Provides permission to modify existing resources.&lt;/li&gt;
&lt;li&gt;Patch: Similar to update, but for making partial changes.&lt;/li&gt;
&lt;li&gt;Delete: Allows the removal of specific resources.&lt;/li&gt;
&lt;li&gt;Exec: Permits executing commands in a container.&lt;/li&gt;
&lt;li&gt;Bind: Enables linking a role to specific subjects.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. ServiceAccounts in Kubernetes:
&lt;/h2&gt;

&lt;p&gt;ServiceAccounts are like worker robots in Kubernetes, playing a crucial role in making things happen automatically. Unlike accounts for people, these are for applications and pods. Just picture them as robot users doing specific jobs in the Kubernetes world. These jobs can be anything from running a pod to handling workloads or talking to the Kubernetes API. Essentially, ServiceAccounts act as the automated helpers that keep the Kubernetes cluster running smoothly by taking care of various tasks without needing human intervention.&lt;/p&gt;

&lt;h4&gt;
  
  
  i. Integrating ServiceAccounts with RBAC:
&lt;/h4&gt;

&lt;p&gt;Connecting ServiceAccounts with RBAC lets Kubernetes administrators give special jobs to automated processes. This makes sure that the access control system is both careful and secure. It doesn't just regulate people using the system but also makes sure that automated processes follow the same strict security rules. Below example illustrate the example of applying RBAC on the &lt;code&gt;deployment-service-account&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Role For Deployment Service Account:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: deployment
  name: deployment-manager
rules:
- apiGroups: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"apps"&lt;/span&gt;, &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
  resources: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"deployments"&lt;/span&gt;, &lt;span class="s2"&gt;"pods"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
  verbs: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"create"&lt;/span&gt;, &lt;span class="s2"&gt;"update"&lt;/span&gt;, &lt;span class="s2"&gt;"delete"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Binding Role With Service Account:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: deployment-manager-binding
  namespace: deployment
subjects:
- kind: ServiceAccount
  name: deployment-service-account
  namespace: deployment
roleRef:
  kind: Role
  name: deployment-manager
  apiGroup: rbac.authorization.k8s.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. RBAC Best Practices:
&lt;/h2&gt;

&lt;p&gt;Implementing RBAC effectively involves understanding and applying best practices listed below:&lt;/p&gt;

&lt;h4&gt;
  
  
  i. Adhere to Least Privilege:
&lt;/h4&gt;

&lt;p&gt;Grant users and service accounts the minimum permissions required to perform their tasks. This principle limits potential security risks by restricting unnecessary access.&lt;/p&gt;

&lt;h4&gt;
  
  
  ii. Regular Auditing and Review:
&lt;/h4&gt;

&lt;p&gt;Conduct frequent audits of RBAC configurations to identify and rectify any discrepancies or outdated access permissions. This proactive approach helps maintain the security posture of the Kubernetes environment.&lt;/p&gt;

&lt;h4&gt;
  
  
  iii. Namespace-specific Considerations:
&lt;/h4&gt;

&lt;p&gt;Understand the nuances of role bindings within namespaces. Tailor permissions to the specific requirements of each namespace, ensuring that access is finely tuned to the needs of distinct projects or teams.&lt;/p&gt;

&lt;h4&gt;
  
  
  iv. Document RBAC Policies:
&lt;/h4&gt;

&lt;p&gt;Maintain comprehensive documentation of RBAC policies, clearly outlining roles, permissions, and the reasoning behind specific access decisions. This documentation aids in knowledge sharing and ensures a transparent understanding of the access control framework.&lt;/p&gt;

&lt;h4&gt;
  
  
  v. Regularly Update RBAC Policies:
&lt;/h4&gt;

&lt;p&gt;Keep RBAC policies up-to-date with the evolving needs of the organization. Regularly revisit and adjust permissions to align with changes in project structures, teams, and operational requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Conclusion: Keep Kubernetes Safe with RBAC:
&lt;/h2&gt;

&lt;p&gt;In the end, using RBAC in Kubernetes is like having a smart plan to keep everything safe. It's the superhero that makes sure only the right things can do their jobs, stopping any chaos or trouble. RBAC's special powers let it control who can do what, making the whole system work smoothly and securely. So, if you want a safe and organized Kubernetes world, remember to let RBAC be your superhero!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>HTTP Security Headers: Enhancing Web Application Security</title>
      <dc:creator>Priyanshu Belwal</dc:creator>
      <pubDate>Mon, 09 Oct 2023 13:14:48 +0000</pubDate>
      <link>https://forem.com/priyanshubelwal/http-security-headers-enhancing-web-application-security-358m</link>
      <guid>https://forem.com/priyanshubelwal/http-security-headers-enhancing-web-application-security-358m</guid>
      <description>&lt;p&gt;HTTP security headers are the fundamental part of web application security. These headers protects us against various types of attacks and tightens the security. In this article, we will discuss most commonly used HTTP headers in context to application security.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Enforcing HTTPS (HTTP Strict Transport Security (HSTS)):
&lt;/h2&gt;

&lt;p&gt;This header helps to protect websites against man-in-the-middle attacks and cookie hijacking. &lt;br&gt;
Let's assume, we have one website &lt;a href="http://www.example.com"&gt;www.example.com&lt;/a&gt;. Suppose some users are visiting our HTTP website, and we are redirecting our HTTP users to HTTPS via redirection as a solution.&lt;br&gt;
Since visitors may first communicate with the non-encrypted version of the site before being redirected. This creates an opportunity for a man-in-the-middle attack. &lt;br&gt;
The HTTP Strict Transport Security header informs the browser that it should never load a site using HTTP and should automatically convert all attempts to access the site using HTTP to HTTPS requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&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;Strict-Transport-Security: max-age=&amp;lt;expire-time&amp;gt;; includeSubDomains
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;max-age= directive allows us to specify the amount of time (in seconds) that the content of the header will be stored in the browser cache.&lt;/li&gt;
&lt;li&gt;includeSubDomains directive specifies that this rule applies to all of the site's subdomains as well.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Cross-Site Scripting Protection (X-XSS):
&lt;/h2&gt;

&lt;p&gt;Cross-Site Scripting (XSS) happen when hackers take advantage of a security hole to upload malicious scripts to a website which are then downloaded to a victim’s browser. The HTTP X-XSS-Protection response header is a feature of browsers, that stops pages from loading when they detect reflected cross-site scripting (XSS) attacks.&lt;/p&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;X-XSS-Protection: 0  (Disable the XSS Filtering)
X-XSS-Protection: 1 (Enable the XSS Filtering and remove the unsafe part)
X-XSS-Protection: 1; mode=block (Entire page is being prevented from rendering)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. IFrame Protection:
&lt;/h2&gt;

&lt;p&gt;The X-Frame-Options security header helps stop click-jacking attacks. It instructs the browser whether a web page should be allowed to render a , ,  or  element on website or not.&lt;/p&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;X-Frame-Options: DENY (This will not allow to page rendering in a iframe)
X-Frame-Options: SAMEORIGIN (This will allow the page to only be displayed in a iframe over same domain)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Content-Type Sniffing Prevention:
&lt;/h2&gt;

&lt;p&gt;The X-Content-Type-Options HTTP header is used to instruct the browser that the MIME types provided in the Content-Type headers should be followed and not guessed. This is used to prevent MIME Confusion Attacks.&lt;/p&gt;

&lt;p&gt;Suppose an attacker changes the response for an innocent resource, such as an image to an executable script. If MIME sniffing is enabled, the browser will ignore the declared image content type, and instead of rendering an image will execute the malicious script.&lt;/p&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;X-Content-Type-Options: nosniff (Instructs browser to not guess the mime type of resource)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Content Security Policy (CSP):
&lt;/h2&gt;

&lt;p&gt;This is a security feature, which is used to specify the origin of content that is allowed to be loaded on a web page.  If implemented properly, this policy prevents the exploitation of Cross-Site Scripting (XSS), ClickJacking, and HTML injection attacks.&lt;/p&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;Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline (This CSP allows resources to be loaded only from the same origin (self) and allows inline scripts (unsafe-inline))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Referrer-Policy:
&lt;/h2&gt;

&lt;p&gt;The Referrer-Policy header controls how much information about the originating page (referrer) is shared with the destination when a user clicks on a link or loads a resource from another origin. &lt;br&gt;
It helps enhance user privacy and security by limiting the information exposed in the Referer header.&lt;/p&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;Referrer-Policy: strict-origin-when-cross-origin (This policy sends the full referrer when navigating within the same origin but only the origin when navigating to a different origin.)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. Access-Control-Allow-Origin:
&lt;/h2&gt;

&lt;p&gt;This header specifies the trusted domain(s) that are allowed to access the resources via cross-origin resource sharing.  if Site-A requests a resource from Site-B, Site-B should indicate in its Access-Control-Allow-Origin header that Site-A is allowed to fetch that resource, if not, the access is blocked due to Same Origin Policy (SOP).&lt;/p&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;Access-Control-Allow-Origin: https://yoursite.com (Allows only yoursite.com origin to fetch this resource)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. Server and X-Powered-By:
&lt;/h2&gt;

&lt;p&gt;These headers describes the software used by the origin server that handled the request and the technology used by them. Using the information in this header, attackers can find vulnerabilities easier.&lt;/p&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;Server: Apache
X-Powered-By: Express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  9. Cache-Control:
&lt;/h2&gt;

&lt;p&gt;This header allows us to specify various directives to instruct both client browsers and proxy servers on how to handle caching.&lt;/p&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;Cache-Control: private (Content is sensitive or user-specific and should not be cached.)
Cache-Control: public (Content can be cached by proxy caches as well as browsers.)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In conclusion, the judicious implementation of HTTP security headers is an indispensable aspect of web application security. These headers provide a formidable defense against a host of cyber threats, preserving the confidentiality, integrity, and availability of online resources. Staying vigilant and proactive in utilizing these headers is paramount in the ongoing battle to secure the digital realm.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Exploring Docker Volumes: Data Management in Containers</title>
      <dc:creator>Priyanshu Belwal</dc:creator>
      <pubDate>Sat, 02 Sep 2023 12:55:57 +0000</pubDate>
      <link>https://forem.com/priyanshubelwal/exploring-docker-volumes-data-management-in-containers-4co6</link>
      <guid>https://forem.com/priyanshubelwal/exploring-docker-volumes-data-management-in-containers-4co6</guid>
      <description>&lt;p&gt;Docker, the containerization platform that has revolutionized the way we deploy and manage applications, brings a wealth of features to the table. Among these, Docker Volumes stand out as a crucial tool for efficient data management within containers. In this article, we will dive into the world of Docker Volumes, exploring their introduction, use cases, and the different types available.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to Docker Volumes:
&lt;/h2&gt;

&lt;p&gt;Docker containers are lightweight, portable, and offer consistency across various environments. However, containers are stateless, which means that any data or changes made inside a container are lost once the container is stopped or removed. This limitation poses a significant challenge when dealing with persistent data such as databases, configuration files, and user uploads.&lt;/p&gt;

&lt;p&gt;This is where Docker Volumes come into play. Docker Volumes provide a mechanism for persisting and managing data beyond the lifecycle of a container. Docker containers allowing data to survive container termination and be shared among multiple containers. Folder in physical host file system is mounted into the virtual file system of Docker. When container writes to its file system, its automatically written into the host file system and in this way, we can achieve some kind of persistence in case of stateless docker containers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Cases for Docker Volume:
&lt;/h2&gt;

&lt;p&gt;Docker Volumes offer a wide range of use cases, enabling developers and administrators to address various data management challenges:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Database Management:&lt;/strong&gt; Docker Volumes plays key role for databases like MySQL, PostgreSQL, and MongoDB. They ensure that the database data remains intact even if the container running the database is restarted or replaced.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Application Configuration:&lt;/strong&gt; Storing configuration files as Docker Volumes ensures that the application's settings can be easily modified without rebuilding the container image.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Logging and Metrics:&lt;/strong&gt; Containerized applications generate logs and metrics that need to be stored and analysed. Docker Volumes can be used to persist log files and metric data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Shared Data:&lt;/strong&gt; When multiple containers need access to the same data, Docker Volumes provide a convenient way to share that data among containers. This is particularly useful in microservices architectures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Backup and Restore:&lt;/strong&gt; Docker Volumes simplify the process of backing up and restoring data by isolating it from the container. This makes disaster recovery more manageable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Working with different type of Docker Volumes:
&lt;/h2&gt;

&lt;h4&gt;
  
  
  1. Bind Volumes:
&lt;/h4&gt;

&lt;p&gt;Bind volumes allow us to mount a specific path from the host's filesystem directly into the container. They are useful when we need to interact with host files and directories from within a container.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample Command:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; /path/on/host:/app/data ubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command starts a container from the ubuntu image. It uses the -v flag to create a bind volume by specifying a path on the host machine (/path/on/host) and the corresponding path inside the container (/app/data).&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Anonymous Volumes:
&lt;/h4&gt;

&lt;p&gt;Anonymous volumes are created, when we create a volume just by referencing the container directory. We don't specify which directory on the host should be mounted but that's taking care of the docker itself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample Command:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; /var/lib/mysql/data ubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While running above command, a directory is automatically created by docker under &lt;code&gt;/var/lib/docker/volumes/....&lt;/code&gt;.For each container, there is a folder generated that gets mounted automatically to the specified container path (In our case, &lt;code&gt;/var/lib/mysql/data&lt;/code&gt;)&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Named Volumes:
&lt;/h4&gt;

&lt;p&gt;Names volumes are the enhancements over anonymous volumes. In this case as well the folders on host file system are created and managed by docker itself, but we can provide a user friendly name to it to refer. Named volumes are suitable for scenarios where multiple containers need to share and persist data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample Command:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume create mydata
docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; mydata:/app/data myapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first command creates a new named volume named mydata.&lt;br&gt;
The second command starts a container from the myapp image. It uses the -v flag to mount the mydata named volume into the container at the path /app/data.&lt;/p&gt;

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

&lt;p&gt;In summary, Docker offers different types of volumes to address various data management requirements within containers. Local volumes are suitable for single-container scenarios that require data persistence, named volumes are ideal for sharing data among multiple containers, and bind volumes are useful for development and debugging, enabling direct interaction between the host and container filesystems. Understanding these volume types and their appropriate use cases is crucial for effective containerized application management.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Returning Customized Content Based On Location In AWS</title>
      <dc:creator>Priyanshu Belwal</dc:creator>
      <pubDate>Sat, 05 Aug 2023 06:47:20 +0000</pubDate>
      <link>https://forem.com/priyanshubelwal/returning-customized-content-based-on-location-in-aws-26e3</link>
      <guid>https://forem.com/priyanshubelwal/returning-customized-content-based-on-location-in-aws-26e3</guid>
      <description>&lt;p&gt;As businesses expand globally, catering to users from different locations becomes crucial. Providing personalized content based on the user's location enhances the user experience and helps businesses tailor their offerings to specific regions. In this article, we will explore &lt;strong&gt;how to leverage Amazon CloudFront and an EC2 instance with a Node.js application to return customized content based on the user's country header.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Amazon CloudFront Overview:
&lt;/h2&gt;

&lt;p&gt;Amazon CloudFront is a content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to users with low latency and high transfer speeds. It caches and distributes content from AWS edge locations strategically placed around the world, reducing the load on your origin server and improving the user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  EC2 Instance with Node.js Application:
&lt;/h2&gt;

&lt;p&gt;Amazon Elastic Compute Cloud (EC2) provides resizable compute capacity in the cloud. We'll use an EC2 instance to host our Node.js application, which will handle the logic of returning customized responses based on the user's country header. The Node.js application will receive requests from CloudFront and analyze the "Country" header to determine the appropriate response.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EmaRDyk0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ivfiwspe0ddmb7qd0fd.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EmaRDyk0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ivfiwspe0ddmb7qd0fd.jpg" alt="Returning Customized Content Based On Location In AWS" width="800" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Set Up CloudFront Distribution:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Sign in to your AWS Management Console.&lt;/li&gt;
&lt;li&gt;Navigate to the Amazon CloudFront service.&lt;/li&gt;
&lt;li&gt;Click "Create Distribution."&lt;/li&gt;
&lt;li&gt;Choose "Web" as the delivery method.&lt;/li&gt;
&lt;li&gt;Configure the following settings:&lt;/li&gt;
&lt;li&gt;Origin Domain Name: Select your EC2 instance as the origin server.&lt;/li&gt;
&lt;li&gt;Allowed HTTP Methods: Choose the appropriate HTTP methods for your application (e.g., GET, POST).&lt;/li&gt;
&lt;li&gt;Viewer Protocol Policy: Select "Redirect HTTP to HTTPS" for enhanced security.&lt;/li&gt;
&lt;li&gt;Cache and Origin Request Settings: Use the default settings for now; you can fine-tune them later.&lt;/li&gt;
&lt;li&gt;Distribution Settings: Set the desired options for your content delivery preferences.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 2: Install Node.js Application on EC2 Instance:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Launch an EC2 instance with an appropriate Amazon Machine Image (AMI) that supports Node.js.&lt;/li&gt;
&lt;li&gt;Connect to your EC2 instance using SSH.&lt;/li&gt;
&lt;li&gt;Install Node.js and npm on the instance.&lt;/li&gt;
&lt;li&gt;Deploy your Node.js application to the EC2 instance.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 3: Implement Customized Response Logic:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;In your Node.js application, listen for incoming requests from CloudFront.&lt;/li&gt;
&lt;li&gt;Extract the "Country" header from the incoming request.&lt;/li&gt;
&lt;li&gt;Use a geolocation database or a third-party API to map the user's IP address to their country.&lt;/li&gt;
&lt;li&gt;Based on the user's country, customize the content to be returned. For example, you could show region-specific offers, language preferences, or localized content.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 4: Pass Country Header from CloudFront to EC2:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;In your CloudFront distribution settings, navigate to "Cache Behavior Settings."&lt;/li&gt;
&lt;li&gt;Click "Add/Edit Headers."&lt;/li&gt;
&lt;li&gt;Add a new header with the name "Country" (you can choose any custom name you prefer).&lt;/li&gt;
&lt;li&gt;Set the "Forward" option to "Whitelist," and add "Country" to the Whitelist Headers list.&lt;/li&gt;
&lt;li&gt;Save your changes.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 5: Test the Solution:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Access your CloudFront distribution using its domain name.&lt;/li&gt;
&lt;li&gt;Ensure you include the "Country" header in your requests. You can use browser developer tools or tools like cURL to add custom headers.&lt;/li&gt;
&lt;li&gt;Observe the customized response from your Node.js application based on the user's location.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Implementing a location-based content customization solution using Amazon CloudFront and an EC2 instance with a Node.js application can significantly enhance user experience and improve your application's global scalability. By leveraging CloudFront's global network and EC2's compute capabilities, you can efficiently deliver personalized content to users based on their location. This approach can help businesses reach a wider audience, increase user engagement, and provide targeted offerings tailored to specific regions.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>🔧 Solid Principles Made Easy: Building a Strong Foundation for Your Code ⚙️</title>
      <dc:creator>Priyanshu Belwal</dc:creator>
      <pubDate>Tue, 18 Jul 2023 16:01:36 +0000</pubDate>
      <link>https://forem.com/priyanshubelwal/solid-principles-made-easy-2e49</link>
      <guid>https://forem.com/priyanshubelwal/solid-principles-made-easy-2e49</guid>
      <description>&lt;p&gt;Software development is like building a house. To construct a strong and reliable structure, architects follow specific principles. Similarly, in software design, we have &lt;strong&gt;SOLID principles&lt;/strong&gt; to guide us in building robust and maintainable code. Let's explore these principles in simple terms:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. S: Single Responsibility Principle
&lt;/h2&gt;

&lt;p&gt;Imagine you have a toolbox, and each tool has a specific purpose. Just like that, a class should have one clear responsibility. It should do one thing and do it well. If a class has multiple responsibilities, it becomes hard to understand, maintain, and change without affecting other parts of the code.&lt;/p&gt;

&lt;h5&gt;
  
  
  How to identify:
&lt;/h5&gt;

&lt;p&gt;Ask yourself, "What is the main responsibility of my class?" If you find yourself using the word "and" in the answer, you might be breaking the single responsibility principle.&lt;/p&gt;

&lt;h5&gt;
  
  
  Example:
&lt;/h5&gt;

&lt;p&gt;Imagine a FileManager class responsible for both reading files and processing data from the file.&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FileManager&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;readFile&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;filePath&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Logic to read the file and return its content as a string&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;processData&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;data&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Logic to process the data read from the file&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;This violates the single responsibility principle. Instead, you can create two separate classes: &lt;code&gt;FileReader&lt;/code&gt; and &lt;code&gt;DataProcessor&lt;/code&gt;, each handling its respective responsibility.&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FileReader&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;readFile&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;filePath&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Logic to read the file and return its content as a 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;class&lt;/span&gt; &lt;span class="nc"&gt;DataProcessor&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;processData&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;data&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Logic to process the data read from the file&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;h5&gt;
  
  
  What to avoid:
&lt;/h5&gt;

&lt;p&gt;Avoid creating classes that try to do too much. Also there is no need to have multiple classes that all hold just one function. Aim for a good balance by keeping each class focused on a single task.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. O: Open/Closed Principle
&lt;/h2&gt;

&lt;p&gt;Think of software as a LEGO set. When you want to expand your creation, you don't modify existing bricks; you add new ones. Similarly, in your code, you should be able to extend functionality without changing existing code.&lt;/p&gt;

&lt;p&gt;Assume you have a class, which stores the binary data into database like 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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BinaryDataDbSaver&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;save&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Blob&lt;/span&gt; &lt;span class="n"&gt;binaryData&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// ... DB Persistance Logic Here.&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 in future, you want to save this binary data into an object storage (like: AWS S3 or Microsoft Azure Blob) One possible solution can be like this:&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BinaryDataDbSaver&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;saveToDB&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Blob&lt;/span&gt; &lt;span class="n"&gt;binaryData&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// ... DB Persistance Logic Here.&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;saveToBlob&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Blob&lt;/span&gt; &lt;span class="n"&gt;binaryData&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// ... DB Persistance Logic Here.&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;In above solution, to add a new functionality, we modified an existing class, which was already well tested and serving the traffic.&lt;/p&gt;

&lt;p&gt;To Handle such scenarios efficiently, we can extract an interface from it and can provide a solution like 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="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;BinaryDataSaver&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Blob&lt;/span&gt; &lt;span class="n"&gt;binaryData&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BinaryDataDbSaver&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;BinaryDataSaver&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;save&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Blob&lt;/span&gt; &lt;span class="n"&gt;binaryData&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// ... DB Persistance Logic Here.&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BinaryDataBlobSaver&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;BinaryDataSaver&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;save&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Blob&lt;/span&gt; &lt;span class="n"&gt;binaryData&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// ... Blob Persistance Logic Here.&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;By adapting this solution, we did not changed any existing implementation and were able to meet our purpose.&lt;/p&gt;

&lt;h5&gt;
  
  
  Important Pointers:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;The initial idea of Open/Closed principal was related to the inheritance.&lt;/li&gt;
&lt;li&gt;But inheritance introduces tight coupling if the subclasses depend on implementation details of their parent class.&lt;/li&gt;
&lt;li&gt;Thats why the Open/Closed Principal was re-defined to the Polymorphic Open/Closed Principle. &lt;/li&gt;
&lt;li&gt;It uses interfaces instead of superclasses to allow different implementations which you can easily substitute without changing the code that uses them.&lt;/li&gt;
&lt;li&gt;The interfaces are closed for modifications, and you can provide new implementations to extend the functionality of your software.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. L: Liskov Substitution Principle
&lt;/h2&gt;

&lt;p&gt;In a well-designed software system, you should be able to replace an object of a parent class with an object of its subclass without causing issues. Subclasses should enhance the behavior of the parent class, not restrict or alter it.&lt;/p&gt;

&lt;h5&gt;
  
  
  In simple terms:
&lt;/h5&gt;

&lt;p&gt;If you have a Fruit class and an Apple class that inherits from Fruit, you should be able to use an Apple object wherever you expect a Fruit object.&lt;/p&gt;

&lt;h5&gt;
  
  
  Why is it useful:
&lt;/h5&gt;

&lt;p&gt;By adhering to this principle, your code becomes more flexible and allows for code reuse.&lt;/p&gt;

&lt;h5&gt;
  
  
  Example:
&lt;/h5&gt;

&lt;p&gt;Consider a Bird base class and a Penguin subclass. Since penguins cannot fly, calling the fly() method on a Penguin object should not lead to errors or unexpected behavior.&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bird&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;fly&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Fly behavior for birds&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Penguin&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Bird&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Penguins cannot fly, so this method should not be here&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Complying with Liskov Substitution Principle, one possible solution can be as:&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="kd"&gt;abstract&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bird&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;fly&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Penguin&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Bird&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;fly&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Penguins cannot fly, so this method is not implemented&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;h2&gt;
  
  
  4. I: Interface Segregation Principle
&lt;/h2&gt;

&lt;p&gt;Imagine ordering a meal at a restaurant and getting a plate with everything on it, even the dishes you don't like. The Interface Segregation Principle advises against forcing clients to implement methods they don't need.&lt;/p&gt;

&lt;h5&gt;
  
  
  In simple terms:
&lt;/h5&gt;

&lt;p&gt;Create smaller, specific interfaces, rather than one large interface with many methods.&lt;/p&gt;

&lt;h5&gt;
  
  
  Why it matters:
&lt;/h5&gt;

&lt;p&gt;This prevents clients from being burdened with unnecessary methods and makes code more maintainable and adaptable.&lt;/p&gt;

&lt;h5&gt;
  
  
  Example:
&lt;/h5&gt;

&lt;p&gt;You have a large interface, &lt;code&gt;Vehicle&lt;/code&gt;, containing methods like &lt;code&gt;startEngine()&lt;/code&gt;, &lt;code&gt;accelerate()&lt;/code&gt;, and &lt;code&gt;playRadio()&lt;/code&gt;. If a class implementing &lt;code&gt;Vehicle&lt;/code&gt; has no use for &lt;code&gt;playRadio()&lt;/code&gt;, it's forced to implement it, violating the Interface Segregation Principle.&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="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;startEngine&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;accelerate&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;playRadio&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&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;startEngine&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Car specific engine starting logic&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;accelerate&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Car specific acceleration logic&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;playRadio&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Radio playing logic - not needed for all vehicles&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;To resolve this, you can split the interface into smaller, specific interfaces 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="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;startEngine&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;accelerate&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;RadioPlayable&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;playRadio&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;RadioPlayable&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;startEngine&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Car specific engine starting logic&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;accelerate&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Car specific acceleration logic&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;playRadio&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Radio playing logic - implemented only for vehicles that can play radio&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;h5&gt;
  
  
  Important note:
&lt;/h5&gt;

&lt;p&gt;Violating the Interface Segregation Principle can lead to issues with Liskov Substitution Principle if clients are forced to implement methods they don't properly support.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. D: Dependency Inversion Principle
&lt;/h2&gt;

&lt;p&gt;Think of software modules as pieces in a jigsaw puzzle. Instead of directly connecting each piece, you use connectors that allow different pieces to fit together. Similarly, the Dependency Inversion Principle encourages depending on abstractions (interfaces) rather than concrete implementations.&lt;/p&gt;

&lt;h5&gt;
  
  
  In simple terms:
&lt;/h5&gt;

&lt;p&gt;Your classes should rely on interfaces, not on specific classes.&lt;/p&gt;

&lt;h5&gt;
  
  
  Why it matters:
&lt;/h5&gt;

&lt;p&gt;By depending on abstractions, your code becomes more flexible, maintainable, and easier to test. You can easily swap implementations without changing the dependent classes.&lt;/p&gt;

&lt;p&gt;Lets consider below code, which represents a MacBook of very old generation and imagine it uses Wired Keyboard and Mouse.&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MacBook&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;WiredKeyboard&lt;/span&gt; &lt;span class="n"&gt;keyboard&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;WiredMouse&lt;/span&gt; &lt;span class="n"&gt;mouse&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;MacBook&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;WiredKeyboard&lt;/span&gt; &lt;span class="n"&gt;keyboard&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;WiredMouse&lt;/span&gt; &lt;span class="n"&gt;mouse&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;keyboard&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;keyboard&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;mouse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mouse&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;In above example, in future if you would have to replace &lt;code&gt;WiredKeyboard&lt;/code&gt; to &lt;code&gt;WirelessKeyboard&lt;/code&gt;, then we need to change the existing class, which can violate &lt;strong&gt;Open/Closed Principal&lt;/strong&gt; and lead to buggy code.&lt;/p&gt;

&lt;p&gt;Instead, MacBook class should rely on interfaces, rather then implementor classes. Above problem can be solved like 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="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Keyboard&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//... Methods&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Mouse&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//.. Methods&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WiredKeyboard&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Keyboard&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//... Implementations&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WirelessKeyboard&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Keyboard&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//... Implementations&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WiredMouse&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Mouse&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//... Implementations&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WirelessMouse&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Mouse&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//... Implementations&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MacBook&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;Keyboard&lt;/span&gt; &lt;span class="n"&gt;keyboard&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;Mouse&lt;/span&gt; &lt;span class="n"&gt;mouse&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;MacBook&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Keyboard&lt;/span&gt; &lt;span class="n"&gt;keyboard&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Mouse&lt;/span&gt; &lt;span class="n"&gt;mouse&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;keyboard&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;keyboard&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;mouse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mouse&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;Now in future, if we need to change the components, just we need to inject other type of SubClasses and our work will be done very easily, without touching &lt;code&gt;MacBook&lt;/code&gt; class implementation.&lt;/p&gt;

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

&lt;p&gt;By following these SOLID principles, you can create software that is easier to understand, maintain, and extend, just like building a strong foundation for your projects.&lt;/p&gt;

</description>
      <category>designpatterns</category>
      <category>java</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>⚡️ Understanding React's Node Reconciliation and the Benefits of React Fiber ⚡️</title>
      <dc:creator>Priyanshu Belwal</dc:creator>
      <pubDate>Sat, 08 Jul 2023 13:14:51 +0000</pubDate>
      <link>https://forem.com/priyanshubelwal/understanding-reacts-node-reconciliation-and-the-benefits-of-react-fiber-5c03</link>
      <guid>https://forem.com/priyanshubelwal/understanding-reacts-node-reconciliation-and-the-benefits-of-react-fiber-5c03</guid>
      <description>&lt;p&gt;React, a popular JavaScript library for building user interfaces, utilizes a process called "reconciliation" to efficiently update the DOM when there are changes in the application's state. &lt;/p&gt;

&lt;p&gt;React's reconciliation algorithm analyzes the virtual representation of the UI and determines which nodes need to be re-rendered. With the introduction of React Fiber, a new reconciliation engine, React has made significant improvements in performance, responsiveness, and concurrent rendering. In this article, we will delve into how React identifies which nodes to re-render, explore the reconciliation algorithm, and understand the advancements brought about by React Fiber. 🚀&lt;/p&gt;

&lt;h3&gt;
  
  
  React's Virtual DOM:
&lt;/h3&gt;

&lt;p&gt;React operates on a virtual representation of the DOM called the Virtual DOM. The virtual DOM is a lightweight in-memory representation of the real DOM, which allows React to make changes to the UI without manipulating the actual DOM. This makes updates faster, as changing the virtual DOM is less expensive than changing the real DOM.&lt;/p&gt;

&lt;p&gt;When a component's state or props change, React compares the new Virtual DOM with the previous one to identify the differences efficiently, minimizing unnecessary updates and improving performance. ⚛️&lt;/p&gt;

&lt;h3&gt;
  
  
  Reconciliation Algorithm:
&lt;/h3&gt;

&lt;p&gt;React's reconciliation algorithm, also known as the diffing algorithm, is responsible for determining the minimal set of changes required to update the real DOM. The algorithm follows a top-down, depth-first approach, comparing each node and its children. Let's understand the key steps involved: 🌳&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Tree Diffing:&lt;/strong&gt; React starts by diffing the new Virtual DOM with the previous one, comparing the root nodes. It determines if the root node types are the same and updates only the attributes that have changed. 🌱&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Component Instances:&lt;/strong&gt; If the root nodes differ, React creates new instances of the components involved. It then proceeds to recursively diff the children of these components, continuing the comparison process. 🔄&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Element Reordering:&lt;/strong&gt; React attempts to minimize changes by reordering elements instead of re-rendering them. It uses a technique called &lt;code&gt;keyed reconciliation&lt;/code&gt; where each element is assigned a unique key. If elements have the same keys, React assumes they are of the same type and can be reordered instead of completely re-rendered. 🔑&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Updating Children:&lt;/strong&gt; React compares the children of the elements and performs updates based on their changes. It uses various strategies, such as the "shortest path" algorithm, to efficiently update the DOM. After identifying change, React batches multiple changes into a single update, reducing the number of updates to the virtual DOM and, in turn, the real DOM. 🔄&lt;/p&gt;

&lt;h3&gt;
  
  
  React Fiber 🧶:
&lt;/h3&gt;

&lt;p&gt;React Fiber is a reimplementation of the reconciliation algorithm introduced in React 16. It is designed to improve performance and enable new features like suspense and concurrent rendering. Fiber works by breaking down the reconciliation process into smaller units of work, allowing React to prioritize and interrupt work if needed, resulting in a more responsive user interface. ⚡️&lt;/p&gt;

&lt;p&gt;The Fiber tree represents the virtual DOM that allows React to keep track of the work that needs to be done in a more fine-grained way. Each Fiber in the tree represents a unit of work that needs to be performed, such as updating a component or rendering a new element.&lt;/p&gt;

&lt;p&gt;When a component’s state changes, React creates a new Fiber for that component and adds it to the Fiber tree. React then schedules the Fiber for processing, adding it to a queue of Fibers that need to be worked on. React then begins processing the queue, one Fiber at a time.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;key to the Fiber architecture is that it allows React to pause and resume work anytime.&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  The main advantages of React Fiber include:
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Incremental Rendering:&lt;/strong&gt; Fiber allows React to split rendering work into chunks or "fibers," which can be interrupted and resumed. This enables the browser to respond to user input during large updates and prevents the application from becoming unresponsive. ⏳&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Smoother Animations:&lt;/strong&gt; By allowing React to prioritize animation updates over other work, the Fiber architecture can help to make animations smoother and more responsive. This can be especially important in applications that rely heavily on animations, such as games or video players. 🎯&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Better Concurrency Support:&lt;/strong&gt; Lays the groundwork for better concurrency support in React. By breaking up the work of rendering into smaller, independent units, React can more easily take advantage of new browser APIs, such as Web Workers, that allow for concurrent execution.🔄&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Easier Server-Side Rendering:&lt;/strong&gt; The Fiber architecture makes it easier to perform server-side rendering in React. Because React can pause and resume work at any time, it can split the rendering process into smaller chunks that can be executed on the server and sent to the client as needed. 🌐&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;React's reconciliation algorithm and the introduction of React Fiber have revolutionized the way UI updates are handled in React applications. By efficiently identifying which nodes to re-render, React minimizes unnecessary updates and ensures optimal performance. The introduction of React Fiber further enhances this process, making React more responsive, enabling concurrent rendering, and improving the user experience. As React continues to evolve, developers can expect even more advancements in rendering performance and responsiveness. 🌈&lt;/p&gt;

</description>
    </item>
    <item>
      <title>🚀🚀 A Comprehensive Guide to Spring Boot Actuator: Empower Your Applications</title>
      <dc:creator>Priyanshu Belwal</dc:creator>
      <pubDate>Sat, 08 Jul 2023 12:13:10 +0000</pubDate>
      <link>https://forem.com/priyanshubelwal/a-comprehensive-guide-to-spring-boot-actuator-empower-your-applications-2703</link>
      <guid>https://forem.com/priyanshubelwal/a-comprehensive-guide-to-spring-boot-actuator-empower-your-applications-2703</guid>
      <description>&lt;p&gt;Spring Boot Actuator is a powerful tool that comes bundled with the Spring Boot framework, providing a comprehensive set of features for monitoring, managing, and understanding the health of your Spring Boot applications. In this article, we will explore the key features of Spring Boot Actuator, delve into different configurations based on various use cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Section 1: Features of Spring Boot Actuator:
&lt;/h2&gt;

&lt;p&gt;Spring Boot Actuator offers a wide range of features that simplify application monitoring and management. Let's dive into its key capabilities:&lt;/p&gt;

&lt;h4&gt;
  
  
  1.1 🏥 Health Monitoring:
&lt;/h4&gt;

&lt;p&gt;Actuator provides endpoints to check the health of your application. It supports predefined and custom health indicators, ensuring you stay informed about the overall health of your application.&lt;/p&gt;

&lt;h4&gt;
  
  
  1.2 📊 Metrics Gathering:
&lt;/h4&gt;

&lt;p&gt;Actuator collects and exposes metrics about your application's performance, including CPU usage, memory consumption, request counts, and more. Integration with popular monitoring systems like Prometheus and Graphite is effortless.&lt;/p&gt;

&lt;h4&gt;
  
  
  1.3 📝 Custom Endpoints:
&lt;/h4&gt;

&lt;p&gt;Actuator empowers you to create custom endpoints tailored to your specific requirements. You can expose custom metrics, perform custom health checks, or implement any desired functionality through these endpoints.&lt;/p&gt;

&lt;h2&gt;
  
  
  Section 2: Actuator Endpoints and Their Significance:
&lt;/h2&gt;

&lt;p&gt;Understanding the various Actuator endpoints and their significance is crucial for effective application monitoring. Let's explore some essential endpoints:&lt;/p&gt;

&lt;h4&gt;
  
  
  2.1 🏥 /health Endpoint:
&lt;/h4&gt;

&lt;p&gt;The /health endpoint provides insights into your application's health status. It informs you whether your application is up and running or encountering issues. You can extend it with additional custom health checks.&lt;/p&gt;

&lt;h4&gt;
  
  
  2.2 📊 /metrics Endpoint:
&lt;/h4&gt;

&lt;p&gt;The /metrics endpoint exposes a wealth of performance metrics for your application. It offers detailed information about CPU usage, memory consumption, request counts, and more.&lt;/p&gt;

&lt;h4&gt;
  
  
  2.3 📝 /info Endpoint:
&lt;/h4&gt;

&lt;p&gt;The /info endpoint provides general information about your application, such as version details, descriptions, and any additional custom details you choose to include.&lt;/p&gt;

&lt;h2&gt;
  
  
  Section 3: Configurations for Different Use Cases:
&lt;/h2&gt;

&lt;p&gt;Let's explore different configurations to harness the full potential of Spring Boot Actuator based on your use case:&lt;/p&gt;

&lt;h4&gt;
  
  
  3.1 🔐 Enabling Actuator Endpoints:
&lt;/h4&gt;

&lt;p&gt;To enable Actuator endpoints, add the Actuator dependency to your project. Spring Boot autoconfigures the endpoints, and you can control their accessibility by securing them with authentication and authorization mechanisms.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# application.properties&lt;/span&gt;
&lt;span class="s"&gt;management.endpoints.web.exposure.include=*&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3.2 🛠️ Customizing Endpoints:
&lt;/h4&gt;

&lt;p&gt;Actuator endpoints can be easily customized to align with your application's needs. You can modify their paths, enable or disable specific endpoints, or change their default behavior.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# application.properties&lt;/span&gt;
&lt;span class="s"&gt;management.endpoints.web.path-mapping.health=custom/health&lt;/span&gt;
&lt;span class="s"&gt;management.endpoint.health.show-details=always&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Section 4: Customizing Actuator Endpoints for Metrics and Health Checks
&lt;/h2&gt;

&lt;p&gt;Actuator allows you to extend its capabilities by creating custom endpoints for specific metrics and health checks. Let's explore how you can achieve this:&lt;/p&gt;

&lt;h4&gt;
  
  
  4.1 🔢 Custom Metrics:
&lt;/h4&gt;

&lt;p&gt;You can create custom metrics by defining your own MeterRegistry beans. These metrics can measure application-specific aspects, such as the number of active users or the processing time of specific operations.&lt;/p&gt;

&lt;p&gt;Example:&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;MeterRegistryCustomizer&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MeterRegistry&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;customMetrics&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="n"&gt;registry&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Create custom metrics&lt;/span&gt;
        &lt;span class="n"&gt;registry&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;gauge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"custom.users"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AtomicInteger&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;h4&gt;
  
  
  4.2 🏥 Custom Health Checks:
&lt;/h4&gt;

&lt;p&gt;Actuator enables you to implement custom health indicators beyond the default ones. By creating your own HealthIndicator beans, you can monitor additional aspects of your application's health.&lt;/p&gt;

&lt;p&gt;Example:&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;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CustomHealthIndicator&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;HealthIndicator&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Health&lt;/span&gt; &lt;span class="nf"&gt;health&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Implement custom health check logic&lt;/span&gt;
        &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;isHealthy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="c1"&gt;// Perform health check&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isHealthy&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="nc"&gt;Health&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;up&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Health&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;down&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;build&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="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Section 5: Integration of Actuator with External Monitoring Systems
&lt;/h2&gt;

&lt;p&gt;Actuator seamlessly integrates with external monitoring systems, providing a comprehensive view of your application's performance. Let's see how Actuator can be integrated:&lt;/p&gt;

&lt;h4&gt;
  
  
  5.1 📈 Integration with Prometheus:
&lt;/h4&gt;

&lt;p&gt;You can configure Actuator to export metrics in Prometheus format, allowing seamless integration with Prometheus monitoring and alerting systems.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# application.properties&lt;/span&gt;
&lt;span class="s"&gt;management.metrics.export.prometheus.enabled=true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5.2 📊 Integration with Graphite and Other Systems:
&lt;/h4&gt;

&lt;p&gt;Actuator also supports exporting metrics to systems like Graphite, InfluxDB, or Micrometer-compatible systems. This integration helps you visualize and analyze your application's performance data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# application.properties&lt;/span&gt;
&lt;span class="s"&gt;management.metrics.export.graphite.enabled=true&lt;/span&gt;
&lt;span class="s"&gt;management.metrics.export.graphite.host=graphite.example.com&lt;/span&gt;
&lt;span class="s"&gt;management.metrics.export.graphite.port=2003&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;🎉 Spring Boot Actuator empowers developers to effortlessly monitor and manage their applications. With its robust features, flexible configurations, and seamless integration capabilities, Actuator simplifies the complexity of application management. By leveraging Actuator, you can gain valuable insights, ensure your applications are healthy, and optimize performance. Embrace Spring Boot Actuator today, and witness the transformation in your application management journey!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>🔒 Security with Microsoft Authenticator: A Closer Look at 2FA and TOTP Generation 🔒</title>
      <dc:creator>Priyanshu Belwal</dc:creator>
      <pubDate>Sun, 25 Jun 2023 03:54:01 +0000</pubDate>
      <link>https://forem.com/priyanshubelwal/security-with-microsoft-authenticator-a-closer-look-at-2fa-and-totp-generation-4ij7</link>
      <guid>https://forem.com/priyanshubelwal/security-with-microsoft-authenticator-a-closer-look-at-2fa-and-totp-generation-4ij7</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;In today's digital landscape, ensuring the security of our online accounts is of utmost importance.💻💡 Microsoft Authenticator, a mobile app developed by Microsoft, has emerged as a powerful tool to provide an additional layer of protection through two-factor authentication (2FA). In this article, we will delve into the working of Microsoft Authenticator, focusing specifically on the generation of six-digit TOTPs (Time-Based One-Time Passwords) that play a crucial role in securing user accounts.🔒📱&lt;/p&gt;

&lt;p&gt;Let's understand the working of these apps:&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1: Opting for Enhanced Security
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;(i).&lt;/strong&gt; To enable 2FA, users begin by navigating to the Microsoft website and selecting the option to add a new sign-in method. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GxFeSIlU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ou3kx0ymqidzj48qtetx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GxFeSIlU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ou3kx0ymqidzj48qtetx.png" alt="Microsoft Website, Add New Sign-In Method" width="800" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(ii).&lt;/strong&gt; The registration process begins, and behind the scenes, the Microsoft Authenticator service generates a highly secure secret key unique to the user. This secret key is stored in a secure manner at the Microsoft end. The service then presents a QR code to the user, having the same secret key inside it. 🛡️💼&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BUC__4xk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jqvv0y1s8qmepaisffxs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BUC__4xk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jqvv0y1s8qmepaisffxs.png" alt="Image description" width="800" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(iii).&lt;/strong&gt; Users then open the Microsoft Authenticator app on their mobile devices and scan the QR code. In case the QR code cannot be scanned, an alternative option allows users to manually enter the secret key into the app. Once this process is complete, the secret key is securely stored within the Authenticator app, ready to generate the essential six-digit TOTPs. 🔑📱&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2: Seamless Login Process
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;(i).&lt;/strong&gt; With the secret key securely stored both by Microsoft and within the user's Authenticator app, users can now initiate the sign-in process on the desired website. As the website requests a six-digit one-time password, users open the Authenticator app, which swiftly generates a new TOTP every 30 seconds. ⏱️🔢&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(ii).&lt;/strong&gt; The TOTP is generated by combining the secret key with the current time, employing a time-based OTP generation algorithm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(iii).&lt;/strong&gt; This dynamic combination ensures that the generated TOTP is unique and changes every 30 seconds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(iv).&lt;/strong&gt; Users enter the TOTP into the website's login prompt, while simultaneously, the website utilizes the same secret key and algorithm to generate the corresponding TOTP on the backend for verification. ✨🔢&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(v).&lt;/strong&gt; If the verification process succeeds, granting access to the user, it serves as a testament to the robust security provided by Microsoft Authenticator. 🔒✅&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion:
&lt;/h4&gt;

&lt;p&gt;In a world where online security threats continue to evolve, these mobile apps ensures the protection of user accounts. From opting into 2FA to seamlessly generating TOTPs, Microsoft Authenticator plays a vital role in safeguarding sensitive information and providing peace of mind to users worldwide. 🔐💪&lt;/p&gt;

&lt;p&gt;So, embrace the power of 2-Factor Authentication and take control of your online security like never before! 🔒💙&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This post is inspired from the below LinkedIn post :&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/posts/bytebytego_systemdesign-coding-interviewtips-activity-7077885585222164480-V-LN"&gt;Click Here&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Avoiding Pitfalls: Unraveling Lombok and JPA Integration 🌟</title>
      <dc:creator>Priyanshu Belwal</dc:creator>
      <pubDate>Tue, 20 Jun 2023 04:01:52 +0000</pubDate>
      <link>https://forem.com/priyanshubelwal/avoiding-pitfalls-unraveling-lombok-and-jpa-integration-2aj0</link>
      <guid>https://forem.com/priyanshubelwal/avoiding-pitfalls-unraveling-lombok-and-jpa-integration-2aj0</guid>
      <description>&lt;h3&gt;
  
  
  Introduction:
&lt;/h3&gt;

&lt;p&gt;The combination of Lombok and JPA offers tremendous convenience and productivity in Java development. With Lombok's annotations, we can reduce boilerplate code, while JPA simplifies database interactions. However, like any powerful tool, there are potential pitfalls to be aware of.&lt;/p&gt;

&lt;p&gt;In this article, we will explore three common issues that may arise when using Lombok and JPA together, along with practical examples and solutions to keep your codebase running smoothly. Let's dive in! 💻&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Accidentally Loading Lazy Attributes 😱
&lt;/h4&gt;

&lt;p&gt;Lombok's &lt;a class="mentioned-user" href="https://dev.to/data"&gt;@data&lt;/a&gt; annotation generates various methods, including getters and setters, for our entities. While this can save us time, it's crucial to understand its impact on lazy loading. Consider the following scenario:&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;@Entity&lt;/span&gt;
&lt;span class="nd"&gt;@Data&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Id&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Long&lt;/span&gt; &lt;span class="n"&gt;id&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;title&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;@OneToMany&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mappedBy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"book"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fetch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FetchType&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;LAZY&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;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Comment&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;comments&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;In this case, Lombok generates a getter for the comments field. If we mistakenly call this getter outside a transactional context, we might trigger a lazy loading exception. To avoid this, always ensure that you access lazy attributes within a transaction or eagerly fetch the necessary data when querying the entity.&lt;/p&gt;

&lt;p&gt;Lombok also provides equals()/hashCode()/toString() annotations to generate respective methods. These methods includes all the object fields by default. This can have an unwanted side-effect for JPA entities: accidentally loading lazy attributes or this can easily harm the application performance if lazy loading objects are large.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Malfunctioning of HashSets and HashMaps 😨
&lt;/h4&gt;

&lt;p&gt;Lombok's &lt;code&gt;@EqualsAndHashCode&lt;/code&gt; annotation automatically generates the &lt;code&gt;equals()&lt;/code&gt; and &lt;code&gt;hashCode()&lt;/code&gt; methods for our entities, considering all fields by default.&lt;/p&gt;

&lt;p&gt;In case of a new entity, generally the Id or unique identieir of an entity gets generated by the database, while trigerring the insert operation. So it gets changed after the entity is persisted.&lt;/p&gt;

&lt;p&gt;Lets understand this problem with the help of an example:&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;@Entity&lt;/span&gt;
&lt;span class="nd"&gt;@EqualsAndHashCode&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

   &lt;span class="nd"&gt;@Id&lt;/span&gt;
   &lt;span class="nd"&gt;@GeneratedValue&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strategy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;GenerationType&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;IDENTITY&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
   &lt;span class="nd"&gt;@Column&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nullable&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;Long&lt;/span&gt; &lt;span class="n"&gt;id&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;title&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 we will execute below code and will check the result:&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="nc"&gt;Book&lt;/span&gt; &lt;span class="n"&gt;newBook&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;newBook&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setTitle&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Book1"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HashSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;

&lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newBook&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;bookRepository&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;save&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newBook&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;contains&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newBook&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;"Set Contains Book"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;else&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;"Set Does Not Contains Book"&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;By executing, we found that above code prints &lt;code&gt;Set Does Not Contains Book&lt;/code&gt;, even we added the entity in set initially. The reason is as below:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(i).&lt;/strong&gt; Lombok's &lt;code&gt;@EqualsAndHashCode&lt;/code&gt; method generated a &lt;code&gt;hashCode()&lt;/code&gt; method for this entity and considered id and title.&lt;br&gt;
&lt;strong&gt;(ii).&lt;/strong&gt; On a high level, HashSet/HashMap uses the hashCode() method to determine where to store a particular object, and it is also used during lookup when calling the contains method. First, the hashCode method is calculated, which returns the location that is referred to in order to check if the object is present at that particular level.&lt;br&gt;
&lt;strong&gt;(iii).&lt;/strong&gt; When we added the entity to set initially, the id attribute of entity was null, hence the hashCode was something different.&lt;br&gt;
&lt;strong&gt;(iv).&lt;/strong&gt; Now, since the entity is persisted in database, the id attribute of entity is changed. This resulted in the changed value of hashCode.&lt;br&gt;
&lt;strong&gt;(v).&lt;/strong&gt; When hashset will check if entity exists or not, it will refer the hashCode method and will found that at that location, entity does not exists.&lt;/p&gt;

&lt;p&gt;This problem can lead to unexpected behaviour in our application logic.&lt;/p&gt;
&lt;h4&gt;
  
  
  3. Missing No-Argument Constructor 😕
&lt;/h4&gt;

&lt;p&gt;JPA relies on a no-argument constructor to create entities. Lombok's &lt;code&gt;@NoArgsConstructor&lt;/code&gt; annotation seems like an ideal solution, automatically generating the required constructor for us. However, we must exercise caution, especially when using inheritance or constructors with arguments.&lt;/p&gt;

&lt;p&gt;Consider the following example:&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;@Entity&lt;/span&gt;
&lt;span class="nd"&gt;@Data&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Book&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;title&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;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;title&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;In this case, if we attempt to create an instance of &lt;code&gt;Book&lt;/code&gt; using the no-argument constructor, it will throw a runtime exception due to the missing &lt;code&gt;title&lt;/code&gt; argument. To overcome this, we can explicitly define a no-argument constructor, add &lt;code&gt;@NoArgsConstructor&lt;/code&gt; annotation or provide default values for all constructor parameters.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;Lombok and JPA integration can significantly enhance our Java development experience, but it's crucial to understand potential pitfalls that may arise. By being mindful of lazy loading, carefully handling collections in equals() and hashCode() methods, and addressing the no-argument constructor requirements, we can build robust and efficient applications. Remember, the key is to leverage these powerful tools while remaining vigilant in our coding practices. Happy coding! 🚀🔥&lt;/p&gt;

</description>
      <category>java</category>
      <category>lombok</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🚀 How to Use AWS S3 Bucket to Host a Static Website 🌐</title>
      <dc:creator>Priyanshu Belwal</dc:creator>
      <pubDate>Thu, 15 Jun 2023 15:21:18 +0000</pubDate>
      <link>https://forem.com/priyanshubelwal/how-to-use-aws-s3-bucket-to-host-a-static-website-8ah</link>
      <guid>https://forem.com/priyanshubelwal/how-to-use-aws-s3-bucket-to-host-a-static-website-8ah</guid>
      <description>&lt;p&gt;Are you ready to launch your static website into the vast online universe? Look no further! In this guide, we'll unveil the secrets of using AWS S3 Bucket to seamlessly host your website. 🎉&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites: What You'll Need 📋
&lt;/h2&gt;

&lt;p&gt;Before we begin our exhilarating journey, let's make sure you have the essentials at your fingertips:&lt;/p&gt;

&lt;p&gt;1️⃣ &lt;strong&gt;An AWS account:&lt;/strong&gt; If you don't have one yet, fear not! Signing up is as easy as a few clicks. Head over to the AWS website (&lt;a href="https://aws.amazon.com/"&gt;https://aws.amazon.com/&lt;/a&gt;) and join the cloud revolution.&lt;br&gt;
2️⃣ &lt;strong&gt;AWS CLI :&lt;/strong&gt; AWS CLI installed and configured on your local machine: Prepare to wield the power of the command line as we navigate the AWS cosmos.&lt;br&gt;
3️⃣ &lt;strong&gt;An static website:&lt;/strong&gt;  Ensure you've created a dazzling static website. In this article, we will be using React and Angular, but any static website or framework can be used.💡&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Create an S3 Bucket 🪣
&lt;/h2&gt;

&lt;p&gt;To kick off our journey, we'll create an S3 bucket using the AWS CLI. Follow these steps and watch your bucket take flight:&lt;/p&gt;

&lt;p&gt;1️⃣ Open your command line interface, ready to send commands to the AWS universe.&lt;br&gt;
2️⃣ Type the following command and let it echo through the digital atmosphere, creating your S3 bucket:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3api create-bucket &lt;span class="nt"&gt;--bucket&lt;/span&gt; your-bucket-name &lt;span class="nt"&gt;--region&lt;/span&gt; your-region
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;your-bucket-name&lt;/code&gt; with a unique and captivating name for your bucket. Also, replace &lt;code&gt;your-region&lt;/code&gt; with the AWS region of your choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Configure the S3 Bucket 🛠️
&lt;/h2&gt;

&lt;p&gt;Your bucket is now waiting to be molded into a spectacular host for your website. Let's shape it with these simple steps:&lt;/p&gt;

&lt;p&gt;1️⃣ Issue the following command to enable static website hosting for your bucket:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3 website s3://your-bucket-name/ &lt;span class="nt"&gt;--index-document&lt;/span&gt; index.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;your-bucket-name&lt;/code&gt; with the name of your bucket. The above command. By running this command, you are instructing AWS to treat the specified S3 bucket as a website and configure it to serve the index.html file as the default page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Upload Your Website Files 🚀
&lt;/h2&gt;

&lt;p&gt;Now that your bucket is configured, it's a great time to upload your website files:&lt;/p&gt;

&lt;p&gt;1️⃣ If you are creating the website using some framework like: React or Angular, you need to create an optimized build, which will be deployed to S3. For the build command, please refer to the documentation of the framework. After preparing the build, navigate to the build directory.&lt;br&gt;
2️⃣ Run the following command to upload the files to your S3 bucket:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3 &lt;span class="nb"&gt;sync&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt; s3://your-bucket-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will upload all files and folders in the current directory to your bucket.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Set Permissions 🔒
&lt;/h2&gt;

&lt;p&gt;1️⃣ To make your website file publicly accessible, you first need to disable &lt;strong&gt;Block Public Access Configuration&lt;/strong&gt; for the respective bucket. To do this, you need to run the following command by replacing your bucket name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3api put-public-access-block &lt;span class="nt"&gt;--bucket&lt;/span&gt; your-bucket-name &lt;span class="nt"&gt;--public-access-block-configuration&lt;/span&gt; &lt;span class="s2"&gt;"BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2️⃣ Now you need to create a &lt;code&gt;policy.json&lt;/code&gt; file as below and replace &lt;strong&gt;your-bucket-name&lt;/strong&gt; with the name of your bucket.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Sid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"PublicReadGetObject"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Principal"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"s3:GetObject"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::your-bucket-name/*"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2️⃣ Run the following command to set the bucket policy using the policy file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3api put-bucket-policy &lt;span class="nt"&gt;--bucket&lt;/span&gt; your-bucket-name &lt;span class="nt"&gt;--policy&lt;/span&gt; file://policy.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;strong&gt;your-bucket-name&lt;/strong&gt; with the name of your bucket.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Configure Custom Domain (Optional) 🌐
&lt;/h2&gt;

&lt;p&gt;If you want to host your website to a custom domain, you can follow below steps:&lt;/p&gt;

&lt;p&gt;1️⃣ Go to your preferred DNS provider and create a new CNAME record.&lt;br&gt;
2️⃣ Set the record's name (or host) to your desired domain (e.g., &lt;code&gt;www.yourdomain.com&lt;/code&gt;).&lt;br&gt;
3️⃣ Set the record's value to the endpoint of your S3 bucket. You can find the endpoint by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3api get-bucket-location &lt;span class="nt"&gt;--bucket&lt;/span&gt; your-bucket-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;strong&gt;your-bucket-name&lt;/strong&gt; with the name of your bucket.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prepare for Launch! 🚀🌌
&lt;/h2&gt;

&lt;p&gt;That's it! Your website is now hosted using an AWS S3 Bucket. It should be publicly accessible through the provided endpoint or your custom domain.✨🪐&lt;/p&gt;

&lt;p&gt;To optimize the speed and performance of your website, leveraging a content delivery network (CDN) such as &lt;strong&gt;AWS CloudFront or Cloudflare&lt;/strong&gt; is highly recommended. CDNs help reduce latency and enhance the overall user experience by caching content closer to the end-users. In an upcoming article, we will delve deeper into how you can leverage these CDNs to boost your website's speed and performance. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>🔥 JIT Compilation in Java &amp; Code Caching: Enhancing Performance for Faster Execution 🔥</title>
      <dc:creator>Priyanshu Belwal</dc:creator>
      <pubDate>Sat, 10 Jun 2023 17:47:17 +0000</pubDate>
      <link>https://forem.com/priyanshubelwal/jit-compilation-in-java-code-caching-enhancing-performance-for-faster-execution-1ba8</link>
      <guid>https://forem.com/priyanshubelwal/jit-compilation-in-java-code-caching-enhancing-performance-for-faster-execution-1ba8</guid>
      <description>&lt;p&gt;&lt;strong&gt;Just-In-Time (JIT) compilation&lt;/strong&gt; is a game-changer in the world of Java programming, unleashing the power of optimization during runtime. 🚀 Imagine code that not only gets translated into bytecode but also dynamically compiles into native machine code for lightning-fast execution. This is where JIT compilation comes into play, revolutionizing the performance of our Java applications. 🏃‍♂️&lt;/p&gt;

&lt;p&gt;In Java, the execution process involves two crucial steps: the translation of code into bytecode and the interpretation of bytecode by the Java Virtual Machine (JVM). However, the JIT compiler takes things to the next level. It continuously analyzes the bytecode and identifies frequently executed portions, known as hotspots. 🎯&lt;/p&gt;

&lt;p&gt;Once these hotspots are detected, the JIT compiler swings into action. It optimizes the code by compiling it into highly efficient native machine code, which can be executed directly by the CPU. This dynamic adaptation of the JVM allows for real-time performance enhancements based on the actual runtime conditions of our program. 📈&lt;/p&gt;

&lt;p&gt;To grasp the magic of JIT compilation, let's dive into a practical example. 🧪 Consider the following Java code snippet:&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="cm"&gt;/**
 * The PrimeNumberGenerator class generates a specified number of prime numbers.
 */&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PrimeNumberGenerator&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="cm"&gt;/**
     * The main method of the PrimeNumberGenerator class.
     * It takes a command-line argument specifying the total number of prime numbers to generate.
     *
     * @param args The command-line arguments.
     */&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;numbersToGenerate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;parseInt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;]);&lt;/span&gt;
        &lt;span class="n"&gt;generateNumbers&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numbersToGenerate&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="cm"&gt;/**
     * Generates the specified number of prime numbers.
     *
     * @param totalNumbers The total number of prime numbers to generate.
     */&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;generateNumbers&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;totalNumbers&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;totalPrimesGenerated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;totalPrimesGenerated&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;totalNumbers&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;getNextPrimeAbove&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;next&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;"Next Prime Number: "&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;totalPrimesGenerated&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="cm"&gt;/**
     * Finds the next prime number greater than the given previous number.
     *
     * @param previous The previous number.
     * @return The next prime number.
     */&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;getNextPrimeAbove&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;previous&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Integer&lt;/span&gt; &lt;span class="n"&gt;testNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;previous&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;isPrime&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;testNumber&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;testNumber&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="n"&gt;testNumber&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="cm"&gt;/**
     * Checks if the given number is prime.
     *
     * @param testNumber The number to test.
     * @return True if the number is prime, false otherwise.
     */&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;isPrime&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt; &lt;span class="n"&gt;testNumber&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;testNumber&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;testNumber&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&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="kc"&gt;true&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;This code generates a specified number of prime numbers. But what's interesting is that the execution count of the &lt;code&gt;isPrime&lt;/code&gt; method directly affects the generation process. So, let's run the code and see the results unfold! 💫&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YJIopaya--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uruceql0wnic6tdmp7xw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YJIopaya--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uruceql0wnic6tdmp7xw.png" alt="PrimeNumberGenerator Program Execution" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see from the execution results, the program runs successfully. But let's take things up a notch and peek behind the scenes. We can print the &lt;strong&gt;JIT Compiler Compilation logs&lt;/strong&gt; to see which methods are being natively compiled. To achieve this, we'll follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Compile the Java program using the command &lt;code&gt;javac PrimeNumberGenerator.java&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Run the program with the JVM instructed to print the compilation logs on the console using the command &lt;code&gt;java -XX:+PrintCompilation PrimeNumberGenerator 15&lt;/code&gt;. Alternatively, we can generate a JIT compilation log file by running the program with the command &lt;code&gt;java -XX:+UnlockDiagnosticVMOptions -XX:+LogCompilation PrimeNumberGenerator 15&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After running the program, A log file named hotspot_pid.log is generated, revealing the secrets of JIT compilation. 😲&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qCioS80j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vxi9ac4jfs47il4xrs2c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qCioS80j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vxi9ac4jfs47il4xrs2c.png" alt="Program Execution With Generating Log File" width="800" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Analyzing the log file, we notice that the &lt;code&gt;isPrime&lt;/code&gt; method, our target for optimization, did not undergo any compilation. But don't fret! This is due to the limited execution count since we generated only 15 prime numbers. 🧮&lt;/p&gt;

&lt;p&gt;Let's level up our analysis and generate 5000 prime numbers this time using the command &lt;code&gt;java -XX:+UnlockDiagnosticVMOptions -XX:+LogCompilation PrimeNumberGenerator 5000&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Behold! In the image below, we'll witness the mighty JIT compiler optimizing the isPrime method through various levels of compilation. 🌟&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ee_wlpHB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xjctgkvd4o4jakax27hf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ee_wlpHB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xjctgkvd4o4jakax27hf.png" alt="Image description" width="800" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Leveled Compilation in JIT Compiler: A Performance Marvel
&lt;/h2&gt;

&lt;p&gt;When it comes to JIT compilation, it's all about levels and tiers of optimization. The JVM is not content with a one-size-fits-all approach. Instead, it employs leveled compilation to gradually boost performance and deliver optimal results. 📈&lt;/p&gt;

&lt;p&gt;Here's the deal: The initial tier, known as &lt;strong&gt;Tier 1&lt;/strong&gt;, focuses on swiftly generating compiled code while keeping compilation times low. This level of compilation includes nifty optimizations like inlining frequently called methods or removing redundant checks. But the journey doesn't end there! 😎&lt;/p&gt;

&lt;p&gt;As our program continues to execute and hotspots persist, the JIT compiler cranks up the heat and elevates the hotspots to higher tiers like &lt;strong&gt;Tier 2, Tier 3, and Tier 4&lt;/strong&gt;. These tiers introduce more advanced and time-consuming optimization techniques, such as loop unrolling, advanced inlining, and specialized code transformations. Gradually, the performance of our code scales new heights without overwhelming the initial compilation phase. It's an optimization marvel in action! 💪&lt;/p&gt;

&lt;p&gt;However, there's a twist in the tale. When a Java bytecode is compiled to Tier 4, the code finds its home in the mighty Code Cache, a sacred space with a size limit. But what happens if this cache overflows? It will show up a message like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;VM warning: CodeCache is full. Compiler has been disabled.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This foreboding warning indicates that the code could run even better if more parts of it could be compared to native machine code. Alas, there's no room in the code cache for further optimization. But fear not! Increasing the size of the code cache can unlock new realms of application performance. 🚀&lt;/p&gt;

&lt;p&gt;We can gauge the size of the code cache using the JVM flag -XX:+PrintCodeCache, which yields intriguing insights into its dimensions. 📊&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YuVCIMbn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fb8mwkn76zk4987ju9ph.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YuVCIMbn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fb8mwkn76zk4987ju9ph.png" alt="Image description" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To customize the code cache size, we have three essential flags at o urdisposal:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. InitialCodeCacheSize:&lt;/strong&gt; This flag sets the initial size of the code cache when the JVM starts. We can tweak it using the &lt;code&gt;-XX:InitialCodeCacheSize&lt;/code&gt; VM option. The default value varies depending on the JVM implementation and platform.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. ReservedCodeCacheSize:&lt;/strong&gt; It determines the maximum size the code cache can grow up to. Use the &lt;code&gt;-XX:ReservedCodeCacheSize={sizeInMb}m&lt;/code&gt; VM option to adjust this value. The default value also depends on the JVM implementation and platform.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. CodeCacheExpansionSize:&lt;/strong&gt; This flag governs the amount by which the code cache can expand when it reaches its limits. We can set it using the &lt;code&gt;-XX:CodeCacheExpansionSize&lt;/code&gt; VM option. The default value is typically a fraction of the reserved code cache size.&lt;/p&gt;

&lt;p&gt;Code Snippets Are Available At: &lt;a href="https://github.com/belwalpb/jvm-code-cache-optimization"&gt;https://github.com/belwalpb/jvm-code-cache-optimization&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion: Unleashing the Full Potential of Java
&lt;/h2&gt;

&lt;p&gt;In this captivating journey, we've unraveled the incredible power of JIT compilation in Java. The ability to optimize program execution dynamically opens doors to unprecedented performance levels. JIT compilation, with its leveled approach, propels our code to greatness by gradually refining it through multiple tiers of optimization. And let's not forget the sacred Code Cache, a sanctuary for native machine code that can supercharge our application's speed. 💥&lt;/p&gt;

&lt;p&gt;Remember, the size of the Code Cache plays a pivotal role in unlocking further performance enhancements. If we find ourself restricted by a full Code Cache, fear not! By tweaking the cache's size, we can unleash the true potential of our Java application and watch it soar to new heights. 🚀✨&lt;/p&gt;

&lt;p&gt;Now, armed with this knowledge, go forth and conquer the world of Java optimization. Embrace JIT compilation, harness the power of Code Caching, and witness the remarkable transformation of our applications. Happy coding! 😄👩‍💻👨‍💻&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
