<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nikhil Soman Sahu</title>
    <description>The latest articles on DEV Community by Nikhil Soman Sahu (@nikhilxd).</description>
    <link>https://dev.to/nikhilxd</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%2F950472%2F0ea4bd4c-c090-443c-b2de-8f4d1d9f78e9.jpg</url>
      <title>DEV Community: Nikhil Soman Sahu</title>
      <link>https://dev.to/nikhilxd</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nikhilxd"/>
    <language>en</language>
    <item>
      <title>Vaadin vs Frontend Frameworks: A Java Developer’s Sarcastic Survival Guide</title>
      <dc:creator>Nikhil Soman Sahu</dc:creator>
      <pubDate>Sat, 17 May 2025 07:15:10 +0000</pubDate>
      <link>https://dev.to/nikhilxd/vaadin-vs-frontend-frameworks-a-java-developers-sarcastic-survival-guide-4f7j</link>
      <guid>https://dev.to/nikhilxd/vaadin-vs-frontend-frameworks-a-java-developers-sarcastic-survival-guide-4f7j</guid>
      <description>&lt;h2&gt;
  
  
  Subtitle: &lt;em&gt;Because Sometimes You Just Want to Write Code, Not Fight JavaScript Demons&lt;/em&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Hey, why don’t you just use React with TypeScript, Webpack, Babel, Vite, Tailwind, and Docker to build a simple contact form?”&lt;/p&gt;

&lt;p&gt;— Every frontend developer ever.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As a senior Java developer, I’ve spent years in the warm, type-safe embrace of the JVM. Life was simple. A little Spring Boot here, some Hibernate there, and boom—robust backend magic. Then someone said: “Let’s make it a web app.”&lt;/p&gt;

&lt;p&gt;Great. Suddenly, I was knee-deep in &lt;strong&gt;JavaScript frameworks&lt;/strong&gt;, where every library has 17 versions, 84 breaking changes, and documentation written by a caffeine-fueled squirrel.&lt;/p&gt;

&lt;p&gt;Enter &lt;strong&gt;Vaadin&lt;/strong&gt;. The messiah for backend developers who just want to build web apps without dealing with the frontend circus.&lt;/p&gt;




&lt;h2&gt;
  
  
  🤹‍♂️ Frontend Tech Stack Today: Welcome to the JavaScript Carnival
&lt;/h2&gt;

&lt;p&gt;Let’s paint a picture.&lt;/p&gt;

&lt;p&gt;You want a simple UI: a form, a button, a table. What do you need?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React (or Vue or Angular… pick your poison)&lt;/li&gt;
&lt;li&gt;TypeScript (because JavaScript wasn’t confusing enough)&lt;/li&gt;
&lt;li&gt;Node.js (to npm install 1,200 dependencies)&lt;/li&gt;
&lt;li&gt;Webpack (because nothing screams "simple" like 3,000 lines of config)&lt;/li&gt;
&lt;li&gt;Babel (so you can write modern JS and watch it turn into ancient hieroglyphs)&lt;/li&gt;
&lt;li&gt;Tailwind (if you're into writing class names longer than your actual content)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Oh, and don’t forget to make everything responsive, secure, reactive, and testable.&lt;/p&gt;

&lt;p&gt;By now, your “simple” UI has its own dev server, build system, and full-stack deployment pipeline. Bravo. 👏&lt;/p&gt;




&lt;h2&gt;
  
  
  😎 Meanwhile in VaadinLand...
&lt;/h2&gt;

&lt;p&gt;You open your Java IDE. You write 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="nd"&gt;@Route&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;""&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;class&lt;/span&gt; &lt;span class="nc"&gt;MainView&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;VerticalLayout&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;MainView&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;TextField&lt;/span&gt; &lt;span class="n"&gt;name&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;TextField&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Your name"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="nc"&gt;Button&lt;/span&gt; &lt;span class="n"&gt;button&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;Button&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Greet"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addClickListener&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;add&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;Label&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getValue&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;p&gt;And guess what? That’s it. It works. No npm. No webpack. No JavaScript. Just glorious, type-safe Java.&lt;/p&gt;

&lt;p&gt;Welcome to Vaadin. The frontend framework that doesn’t pretend you have time to learn a new ecosystem every 3 months.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧩 What Is Vaadin, Really?
&lt;/h2&gt;

&lt;p&gt;Vaadin is a &lt;strong&gt;Java-based UI framework&lt;/strong&gt; that lets you build &lt;strong&gt;modern web apps&lt;/strong&gt; entirely in &lt;strong&gt;Java&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Unlike traditional frontend frameworks that dump half the logic on the browser and half on the server (like a bad divorce), Vaadin takes a &lt;strong&gt;server-side-first&lt;/strong&gt; approach.&lt;/p&gt;

&lt;h3&gt;
  
  
  There Are Two Flavors of Vaadin:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Vaadin Flow&lt;/strong&gt; – Pure Java UI (no JS needed).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vaadin Fusion&lt;/strong&gt; – Use TypeScript for frontend if you miss the chaos.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We’ll focus on Flow because it’s the one that makes you feel like a wizard casting spells with Java.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔥 Why Vaadin Is a Backend Developer's Dream
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ✅ No JavaScript
&lt;/h3&gt;

&lt;p&gt;No &lt;code&gt;npm install&lt;/code&gt;, no &lt;code&gt;yarn.lock&lt;/code&gt;, no wondering why your build broke after a minor version update.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Component-based UI
&lt;/h3&gt;

&lt;p&gt;Need a table? Use &lt;code&gt;Grid&amp;lt;&amp;gt;&lt;/code&gt;. Need a dialog? Use &lt;code&gt;Dialog&lt;/code&gt;. No CSS classes required. It just works.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Spring Boot Integration
&lt;/h3&gt;

&lt;p&gt;Add the Vaadin dependency and keep coding in the warm Spring Boot cocoon.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Secure by Default
&lt;/h3&gt;

&lt;p&gt;All UI logic runs server-side, so your business logic isn’t sitting in a browser console for hackers to giggle at.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Modern UX
&lt;/h3&gt;

&lt;p&gt;Vaadin uses Web Components under the hood and provides responsive, mobile-friendly layouts—without you touching a single &lt;code&gt;media query&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  👨‍🔧 But… Is It for Real-World Projects?
&lt;/h2&gt;

&lt;p&gt;You bet. Vaadin is used in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Admin dashboards&lt;/li&gt;
&lt;li&gt;ERP systems&lt;/li&gt;
&lt;li&gt;Intranet tools&lt;/li&gt;
&lt;li&gt;Banking apps&lt;/li&gt;
&lt;li&gt;Basically, anywhere a dropdown actually matters more than a dancing button&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's not a toy. It's an enterprise-grade toolkit that lets you focus on business logic instead of messing with toolchains from the seventh circle of frontend hell.&lt;/p&gt;




&lt;h2&gt;
  
  
  🤯 Frontend Comparison Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;React + Friends 😬&lt;/th&gt;
&lt;th&gt;Vaadin 🧘‍♂️&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Language&lt;/td&gt;
&lt;td&gt;JS/TS&lt;/td&gt;
&lt;td&gt;Java&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Framework Complexity&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Setup Time&lt;/td&gt;
&lt;td&gt;~1-2 days&lt;/td&gt;
&lt;td&gt;5 minutes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;UI Development&lt;/td&gt;
&lt;td&gt;Manual + CSS&lt;/td&gt;
&lt;td&gt;Component-based&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Backend Integration&lt;/td&gt;
&lt;td&gt;REST, GraphQL&lt;/td&gt;
&lt;td&gt;Direct Java binding&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Build Tool&lt;/td&gt;
&lt;td&gt;Webpack/Vite&lt;/td&gt;
&lt;td&gt;Maven/Gradle&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Security&lt;/td&gt;
&lt;td&gt;Client-heavy&lt;/td&gt;
&lt;td&gt;Server-side by default&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Debugging&lt;/td&gt;
&lt;td&gt;Console.logs + browser devtools&lt;/td&gt;
&lt;td&gt;Stack traces like God intended&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Productivity&lt;/td&gt;
&lt;td&gt;Depends on caffeine&lt;/td&gt;
&lt;td&gt;Smooth sailing with Java&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🐍 Myth-Busting: Vaadin Edition
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ❌ “Vaadin is outdated.”
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Reality: Vaadin constantly evolves. It now supports reactive endpoints, Hilla (Fusion), and even uses Web Components.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  ❌ “It’s too heavyweight.”
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Reality: You’re not shipping Electron here. It’s leaner than most modern JS stacks when done right.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  ❌ “No one uses it.”
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Reality: Ever heard of NASA, Dell, or the European Space Agency? Yep, they’ve used Vaadin.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧙‍♂️ Final Thoughts from a Battle-Hardened Java Developer
&lt;/h2&gt;

&lt;p&gt;I didn’t choose Vaadin. Vaadin chose me—when I grew tired of spending 3 hours aligning a button in CSS.&lt;/p&gt;

&lt;p&gt;If you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Know Java,&lt;/li&gt;
&lt;li&gt;Hate fighting with frontend build tools,&lt;/li&gt;
&lt;li&gt;Prefer writing clean, maintainable code,&lt;/li&gt;
&lt;li&gt;And want your UI to just work without rituals and sacrifices,&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then &lt;strong&gt;Vaadin is your best friend&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Frontend frameworks may come and go, but Java is eternal—and now it builds UIs too. 😏&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 Want to Try It?
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mvn &lt;span class="nt"&gt;-n&lt;/span&gt; vaadin-archetype-application
&lt;span class="nb"&gt;cd &lt;/span&gt;your-app
mvn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the browser. Watch the magic.&lt;/p&gt;




</description>
      <category>webdev</category>
      <category>vaadin</category>
      <category>java</category>
      <category>javascript</category>
    </item>
    <item>
      <title>🤔 `spring.kafka.consumer.fetch-min-size` Not Applying? Let’s Talk About It.</title>
      <dc:creator>Nikhil Soman Sahu</dc:creator>
      <pubDate>Sat, 05 Apr 2025 17:41:20 +0000</pubDate>
      <link>https://dev.to/nikhilxd/springkafkaconsumerfetch-min-size-not-applying-lets-talk-about-it-j7o</link>
      <guid>https://dev.to/nikhilxd/springkafkaconsumerfetch-min-size-not-applying-lets-talk-about-it-j7o</guid>
      <description>&lt;p&gt;So you’re building a Spring Boot Kafka consumer, tweaking those sweet &lt;code&gt;application.properties&lt;/code&gt;, and then you drop this gem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="py"&gt;spring.kafka.consumer.fetch-min-size&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;524288000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’re expecting Kafka to fetch a minimum of &lt;strong&gt;500 MB&lt;/strong&gt; of data per request. Bold. Ambitious. Legendary.&lt;/p&gt;

&lt;p&gt;But wait… Spring Boot &lt;em&gt;completely ignores it&lt;/em&gt;. Like your gym membership.&lt;/p&gt;

&lt;p&gt;Let’s decode what’s going on, shall we?&lt;/p&gt;




&lt;h2&gt;
  
  
  😤 “Why Is This One Property Not Working?”
&lt;/h2&gt;

&lt;p&gt;That’s the million-dollar (or in this case, 500MB) question.&lt;/p&gt;

&lt;p&gt;Here’s what’s wild — other Kafka consumer properties from &lt;code&gt;application.properties&lt;/code&gt; are working just fine.&lt;/p&gt;

&lt;p&gt;But &lt;code&gt;fetch-min-size&lt;/code&gt;? It's like that one rebellious teenager who refuses to follow the rules.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔍 Let’s Reproduce the Problem
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Your properties probably look like this:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="py"&gt;spring.kafka.bootstrap-servers&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;localhost:9092&lt;/span&gt;
&lt;span class="py"&gt;spring.kafka.consumer.group-id&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;my-group&lt;/span&gt;
&lt;span class="py"&gt;spring.kafka.consumer.auto-offset-reset&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;earliest&lt;/span&gt;
&lt;span class="py"&gt;spring.kafka.consumer.key-deserializer&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;org.apache.kafka.common.serialization.StringDeserializer&lt;/span&gt;
&lt;span class="py"&gt;spring.kafka.consumer.value-deserializer&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;org.apache.kafka.common.serialization.StringDeserializer&lt;/span&gt;
&lt;span class="py"&gt;spring.kafka.consumer.fetch-min-size&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;524288000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And yet… logs, debug prints, everything shows this property isn’t being passed to the Kafka consumer.&lt;/p&gt;

&lt;p&gt;No errors. No warnings. Just &lt;strong&gt;silent betrayal&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 The Real Problem
&lt;/h2&gt;

&lt;p&gt;Brace yourself.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;fetch.min.bytes&lt;/code&gt; is not a recognized Spring Boot Kafka shortcut property.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yeah. That’s why.&lt;/p&gt;

&lt;p&gt;While Spring Boot &lt;strong&gt;maps many Kafka consumer properties automatically&lt;/strong&gt;, it doesn't include &lt;strong&gt;all&lt;/strong&gt; of them with auto-magic.&lt;/p&gt;

&lt;p&gt;Some properties—especially advanced ones like &lt;code&gt;fetch.min.bytes&lt;/code&gt;—&lt;strong&gt;must be set manually&lt;/strong&gt; using the &lt;strong&gt;&lt;code&gt;properties&lt;/code&gt; map&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🛠 The Fix: Do It Yourself (DIY Style)
&lt;/h2&gt;

&lt;p&gt;Update your &lt;code&gt;application.properties&lt;/code&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="py"&gt;spring.kafka.consumer.properties.fetch.min.bytes&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;524288000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes. That extra &lt;code&gt;properties.&lt;/code&gt; prefix tells Spring Boot:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Hey, this isn’t a Spring-managed config, just pass it directly to Kafka’s native consumer config.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And suddenly… it works. 🎉&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Little Kafka Config Lesson
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Kafka Property&lt;/th&gt;
&lt;th&gt;Spring Boot Equivalent&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;group.id&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;spring.kafka.consumer.group-id&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Supported directly&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;auto.offset.reset&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;spring.kafka.consumer.auto-offset-reset&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Supported directly&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;fetch.min.bytes&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;❌ Not mapped by Spring Boot&lt;/td&gt;
&lt;td&gt;Must be used as &lt;code&gt;spring.kafka.consumer.properties.fetch.min.bytes&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;📚 Want to see the full list of what’s supported? Check the &lt;a href="https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.integration" rel="noopener noreferrer"&gt;Spring Kafka docs&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🙋🏻‍♂️ “Why Doesn’t Spring Boot Just Support All Kafka Properties?”
&lt;/h2&gt;

&lt;p&gt;Good question.&lt;/p&gt;

&lt;p&gt;Because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kafka has &lt;strong&gt;dozens of knobs&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Spring Boot tries to keep its abstraction layer clean&lt;/li&gt;
&lt;li&gt;Not every project needs fine-tuning at this level&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So for lesser-used Kafka settings, Spring leaves it to &lt;strong&gt;you, brave dev&lt;/strong&gt;, to add them manually via the &lt;code&gt;properties.&lt;/code&gt; namespace.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 How to Confirm It’s Working
&lt;/h2&gt;

&lt;p&gt;Enable DEBUG logging for Kafka:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="py"&gt;logging.level.org.apache.kafka&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;DEBUG&lt;/span&gt;
&lt;span class="py"&gt;logging.level.org.springframework.kafka&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;DEBUG&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start the app, and look for this beauty in logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Setting fetch.min.bytes to 524288000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see it, go ahead and flex a little 💪.&lt;/p&gt;




&lt;h2&gt;
  
  
  😅 A Word of Caution
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;fetch.min.bytes&lt;/code&gt; of &lt;strong&gt;500 MB&lt;/strong&gt; is huge. If you’re not producing large volumes quickly, your consumer might just sit there... waiting... forever.&lt;/p&gt;

&lt;p&gt;Kafka will &lt;strong&gt;not send data until that threshold is reached or fetch.max.wait.ms times out&lt;/strong&gt; (default: 500ms).&lt;/p&gt;

&lt;p&gt;So unless you’re processing massive data bursts, you might wanna start with a saner value like &lt;code&gt;1048576&lt;/code&gt; (1 MB).&lt;/p&gt;

&lt;p&gt;But hey, who am I to judge your buffer goals? 😎&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;If Kafka consumer properties aren't applying as expected, don't assume they're broken. Instead:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Double-check the &lt;a href="https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html" rel="noopener noreferrer"&gt;Spring Boot Kafka property reference&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;spring.kafka.consumer.properties.&lt;/code&gt; prefix for advanced Kafka configs&lt;/li&gt;
&lt;li&gt;Watch your logs—they usually know what’s wrong (and laugh quietly while you suffer)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔗 Quick Recap
&lt;/h2&gt;

&lt;p&gt;✔️ &lt;code&gt;spring.kafka.consumer.fetch-min-size&lt;/code&gt; ❌&lt;br&gt;&lt;br&gt;
✔️ &lt;code&gt;spring.kafka.consumer.properties.fetch.min.bytes=...&lt;/code&gt; ✅&lt;/p&gt;


&lt;h2&gt;
  
  
  📣 Bonus Tip
&lt;/h2&gt;

&lt;p&gt;If you're ever unsure whether a config is being applied, inject and print the full &lt;code&gt;ConsumerFactory&lt;/code&gt; 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="nd"&gt;@Autowired&lt;/span&gt;
&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;ConsumerFactory&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;?,&lt;/span&gt; &lt;span class="o"&gt;?&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;consumerFactory&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@PostConstruct&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;printKafkaConfigs&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="n"&gt;consumerFactory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getConfigurationProperties&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;It’ll dump all the consumer config Kafka is using. Use it to debug like a boss. 🧠&lt;/p&gt;




&lt;h2&gt;
  
  
  🤘 That’s a Wrap!
&lt;/h2&gt;

&lt;p&gt;Kafka is powerful, but it doesn’t hand-hold you—especially when it comes to advanced configs.&lt;/p&gt;

&lt;p&gt;Now that you know the trick with &lt;code&gt;properties.&lt;/code&gt;, you’ve got one less mysterious bug in your life.&lt;/p&gt;

&lt;p&gt;Got stuck with another Kafka quirk? Hit me up—I’ve probably wrestled with it at 2AM and lived to tell the tale.&lt;/p&gt;

&lt;p&gt;Until next time: &lt;strong&gt;keep producing, keep consuming, and may your partitions never be under-replicated.&lt;/strong&gt; 🫡&lt;/p&gt;

</description>
      <category>java</category>
      <category>kafka</category>
      <category>microservices</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>100 imp interview questions for Java developers</title>
      <dc:creator>Nikhil Soman Sahu</dc:creator>
      <pubDate>Fri, 04 Apr 2025 19:18:44 +0000</pubDate>
      <link>https://dev.to/nikhilxd/100-imp-interview-questions-for-java-developers-5440</link>
      <guid>https://dev.to/nikhilxd/100-imp-interview-questions-for-java-developers-5440</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Core Java&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is the difference between &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;.equals()&lt;/code&gt; in Java?&lt;/li&gt;
&lt;li&gt;Explain the concept of immutability in Java.&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;final&lt;/code&gt; keyword in Java?&lt;/li&gt;
&lt;li&gt;How does Java achieve platform independence?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;String&lt;/code&gt;, &lt;code&gt;StringBuilder&lt;/code&gt;, and &lt;code&gt;StringBuffer&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;Explain the concept of method overloading and overriding.&lt;/li&gt;
&lt;li&gt;What is the use of the &lt;code&gt;super&lt;/code&gt; keyword in Java?&lt;/li&gt;
&lt;li&gt;How do you handle exceptions in Java? Explain &lt;code&gt;try-catch-finally&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;checked&lt;/code&gt; and &lt;code&gt;unchecked&lt;/code&gt; exceptions?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;static&lt;/code&gt; keyword in Java?&lt;/li&gt;
&lt;li&gt;Can you overload the &lt;code&gt;main&lt;/code&gt; method in Java? If yes, how?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;ArrayList&lt;/code&gt; and &lt;code&gt;LinkedList&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;How does Java garbage collection work?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;HashMap&lt;/code&gt; and &lt;code&gt;Hashtable&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;Explain the concept of multithreading in Java.&lt;/li&gt;
&lt;li&gt;What are the different ways to create threads in Java?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;sleep()&lt;/code&gt; and &lt;code&gt;wait()&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;volatile&lt;/code&gt; keyword?&lt;/li&gt;
&lt;li&gt;How does Java support encapsulation?&lt;/li&gt;
&lt;li&gt;What is the difference between an abstract class and an interface?&lt;/li&gt;
&lt;li&gt;Can we instantiate an abstract class? Why or why not?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;compareTo()&lt;/code&gt; and &lt;code&gt;compare()&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is autoboxing and unboxing in Java?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;transient&lt;/code&gt; and &lt;code&gt;volatile&lt;/code&gt; keywords?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;Object&lt;/code&gt; class in Java?&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Collections Framework&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is the difference between &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt;, and &lt;code&gt;Map&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;How does &lt;code&gt;HashSet&lt;/code&gt; ensure uniqueness of elements?&lt;/li&gt;
&lt;li&gt;What is the time complexity of operations in &lt;code&gt;ArrayList&lt;/code&gt; vs &lt;code&gt;LinkedList&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;Iterator&lt;/code&gt; and &lt;code&gt;ListIterator&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;How does &lt;code&gt;TreeSet&lt;/code&gt; maintain sorting order?&lt;/li&gt;
&lt;li&gt;What happens if we add a &lt;code&gt;null&lt;/code&gt; value to a &lt;code&gt;HashMap&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;poll()&lt;/code&gt; and &lt;code&gt;remove()&lt;/code&gt; in &lt;code&gt;Queue&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;Explain the working of &lt;code&gt;ConcurrentHashMap&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;fail-fast&lt;/code&gt; and &lt;code&gt;fail-safe&lt;/code&gt; iterators?&lt;/li&gt;
&lt;li&gt;How does &lt;code&gt;PriorityQueue&lt;/code&gt; work?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;Comparable&lt;/code&gt; and &lt;code&gt;Comparator&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;retainAll()&lt;/code&gt; method in collections?&lt;/li&gt;
&lt;li&gt;How does &lt;code&gt;Vector&lt;/code&gt; differ from &lt;code&gt;ArrayList&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;keySet()&lt;/code&gt; and &lt;code&gt;entrySet()&lt;/code&gt; in &lt;code&gt;Map&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;How do you sort a &lt;code&gt;List&lt;/code&gt; of custom objects?&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Java 8 Features&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What are lambda expressions in Java?&lt;/li&gt;
&lt;li&gt;What is a functional interface? Give examples.&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;forEach&lt;/code&gt; and &lt;code&gt;for-loop&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;Explain the concept of streams in Java.&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;map()&lt;/code&gt; and &lt;code&gt;flatMap()&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What are default methods in interfaces?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;Optional&lt;/code&gt; class?&lt;/li&gt;
&lt;li&gt;How does &lt;code&gt;Stream.collect()&lt;/code&gt; work?&lt;/li&gt;
&lt;li&gt;What are method references in Java?&lt;/li&gt;
&lt;li&gt;What is the difference between intermediate and terminal operations in streams?&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;OOPs Concepts&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is polymorphism? Explain its types.&lt;/li&gt;
&lt;li&gt;What is inheritance? What are its advantages and disadvantages?&lt;/li&gt;
&lt;li&gt;What is the difference between composition and aggregation?&lt;/li&gt;
&lt;li&gt;What is the diamond problem in Java? How is it resolved?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;this&lt;/code&gt; and &lt;code&gt;super&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;abstract&lt;/code&gt; classes and interfaces in Java 8+?&lt;/li&gt;
&lt;li&gt;What is encapsulation? Why is it important?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;private&lt;/code&gt;, &lt;code&gt;protected&lt;/code&gt;, and &lt;code&gt;public&lt;/code&gt; access modifiers?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;toString()&lt;/code&gt; method?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;instanceof&lt;/code&gt; and &lt;code&gt;isInstance()&lt;/code&gt;?&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Advanced Java&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is the difference between &lt;code&gt;JVM&lt;/code&gt;, &lt;code&gt;JRE&lt;/code&gt;, and &lt;code&gt;JDK&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is reflection in Java? Provide an example.&lt;/li&gt;
&lt;li&gt;What is the purpose of annotations in Java?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;ClassNotFoundException&lt;/code&gt; and &lt;code&gt;NoClassDefFoundError&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;String pool&lt;/code&gt; and heap memory?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;ClassLoader&lt;/code&gt; in Java?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;serializable&lt;/code&gt; and &lt;code&gt;externalizable&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;clone()&lt;/code&gt; method?&lt;/li&gt;
&lt;li&gt;What is the difference between shallow copy and deep copy?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;finalize()&lt;/code&gt; method?&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Concurrency and Multithreading&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is the difference between &lt;code&gt;Runnable&lt;/code&gt; and &lt;code&gt;Callable&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;ExecutorService&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is thread pooling? Why is it used?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;synchronized&lt;/code&gt; and &lt;code&gt;ReentrantLock&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;start()&lt;/code&gt; and &lt;code&gt;run()&lt;/code&gt; methods in threads?&lt;/li&gt;
&lt;li&gt;What is thread starvation? How can it be avoided?&lt;/li&gt;
&lt;li&gt;What is a deadlock? How can it be prevented?&lt;/li&gt;
&lt;li&gt;What is the purpose of &lt;code&gt;ThreadLocal&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;notify()&lt;/code&gt; and &lt;code&gt;notifyAll()&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;ForkJoinPool&lt;/code&gt;?&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Spring Framework (if applicable)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is dependency injection? How does Spring implement it?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;@Autowired&lt;/code&gt; and &lt;code&gt;@Qualifier&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;@Component&lt;/code&gt;, &lt;code&gt;@Service&lt;/code&gt;, and &lt;code&gt;@Repository&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;@Transactional&lt;/code&gt; annotation?&lt;/li&gt;
&lt;li&gt;What is Spring Boot? How is it different from Spring Framework?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;application.properties&lt;/code&gt; file?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;singleton&lt;/code&gt; and &lt;code&gt;prototype&lt;/code&gt; scopes in Spring?&lt;/li&gt;
&lt;li&gt;What is AOP (Aspect-Oriented Programming)?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;@Controller&lt;/code&gt; and &lt;code&gt;@RestController&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;DispatcherServlet&lt;/code&gt;?&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Hibernate (if applicable)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is the difference between &lt;code&gt;get()&lt;/code&gt; and &lt;code&gt;load()&lt;/code&gt; in Hibernate?&lt;/li&gt;
&lt;li&gt;What is lazy loading? How does it work?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;SessionFactory&lt;/code&gt; in Hibernate?&lt;/li&gt;
&lt;li&gt;What are the different states of an entity in Hibernate?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;save()&lt;/code&gt; and &lt;code&gt;persist()&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;@Entity&lt;/code&gt; annotation?&lt;/li&gt;
&lt;li&gt;What is HQL (Hibernate Query Language)?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;merge()&lt;/code&gt; and &lt;code&gt;update()&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is the second-level cache in Hibernate?&lt;/li&gt;
&lt;li&gt;What is the purpose of the &lt;code&gt;@Transactional&lt;/code&gt; annotation in Hibernate?&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>java</category>
      <category>tutorial</category>
      <category>interview</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Claude Code: The AI Terminal Sidekick We've Been Waiting For</title>
      <dc:creator>Nikhil Soman Sahu</dc:creator>
      <pubDate>Wed, 02 Apr 2025 05:44:36 +0000</pubDate>
      <link>https://dev.to/nikhilxd/claude-code-the-ai-terminal-sidekick-weve-been-waiting-for-2dfj</link>
      <guid>https://dev.to/nikhilxd/claude-code-the-ai-terminal-sidekick-weve-been-waiting-for-2dfj</guid>
      <description>&lt;p&gt;Hey devs! Just spent my weekend playing with Anthropic's new Claude Code tool, and I HAD to share this gem with you all. For those who haven't heard, it's an AI command line tool that lets you talk to Claude directly from your terminal. Game. Changer.&lt;/p&gt;

&lt;h2&gt;
  
  
  No More Alt-Tabbing to Chat Interfaces
&lt;/h2&gt;

&lt;p&gt;First thing I noticed? I'm staying in my terminal WAY more. We've all been there - coding away, hit a snag, then alt-tab to a browser to ask Claude or search Stack Overflow. With Claude Code, I just type my question right where I'm already working. My flow state actually stays intact!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Instead of leaving your terminal to get help&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;claude-code &lt;span class="s2"&gt;"refactor this function to use async/await instead of promises"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Stuff It Can Actually Do
&lt;/h2&gt;

&lt;p&gt;I've had it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate unit tests for a sketchy module I inherited (saved me hours)&lt;/li&gt;
&lt;li&gt;Help optimize a MongoDB query that was killing our staging environment&lt;/li&gt;
&lt;li&gt;Refactor some legacy jQuery spaghetti into modern React components&lt;/li&gt;
&lt;li&gt;Debug a weird race condition I couldn't reproduce consistently&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The coolest part? It actually understands my codebase context. It's not just spitting out generic Stack Overflow answers.&lt;/p&gt;

&lt;h2&gt;
  
  
  When It Really Saved My Bacon
&lt;/h2&gt;

&lt;p&gt;Friday evening (of course), I was stuck debugging this authentication edge case nobody else wanted to touch. Had a deployment deadline looming, and my brain was fried after a week of meetings. Asked Claude Code to analyze the flow and spot potential issues - it immediately identified a token refresh timing problem I had completely missed.&lt;/p&gt;

&lt;p&gt;Three lines of code later, fixed. Deployment saved. Weekend reclaimed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real Talk: It's Not Perfect
&lt;/h2&gt;

&lt;p&gt;It sometimes gets confused with really complex project structures or highly domain-specific code. And occasionally I need to clarify what I'm asking for. But compared to the back-and-forth of web interfaces, even these interactions feel smoother.&lt;/p&gt;

&lt;h2&gt;
  
  
  Should You Try It?
&lt;/h2&gt;

&lt;p&gt;If you're tired of context-switching between your IDE/terminal and browser windows, absolutely. Especially useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Those repetitive coding tasks nobody wants to do&lt;/li&gt;
&lt;li&gt;Diving into unfamiliar codebases or frameworks&lt;/li&gt;
&lt;li&gt;Late-night debugging sessions when your brain is toast&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Anyone else playing with this tool yet? Drop your experiences in the comments - curious how you're using it and what tasks it's best at handling for you!&lt;/p&gt;

&lt;p&gt;P.S. Check Anthropic's blog for details on the research preview. Not sure when it's going fully public, but worth getting on the waitlist now.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>chatgpt</category>
      <category>ai</category>
      <category>programming</category>
    </item>
    <item>
      <title>Deploying Spring Boot 3.1 on Heroku with Tomcat 10.1</title>
      <dc:creator>Nikhil Soman Sahu</dc:creator>
      <pubDate>Wed, 02 Apr 2025 05:29:28 +0000</pubDate>
      <link>https://dev.to/nikhilxd/deploying-spring-boot-31-on-heroku-with-tomcat-101-2i6k</link>
      <guid>https://dev.to/nikhilxd/deploying-spring-boot-31-on-heroku-with-tomcat-101-2i6k</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Deploying a Spring Boot 3.1 application on Heroku with Tomcat 10.1 might seem tricky at first, but with the right steps, you can get your application running smoothly on a cloud-based platform. In this guide, we’ll walk through the entire process, ensuring a seamless deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Deploy Spring Boot on Heroku?
&lt;/h2&gt;

&lt;p&gt;Heroku provides a simple and scalable cloud platform for deploying applications. Some key advantages include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Free tier available&lt;/strong&gt;: Great for development and testing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simplified deployment&lt;/strong&gt;: Just push your code to Git, and Heroku handles the rest.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: Scale your application with ease as traffic grows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Built-in support for Java&lt;/strong&gt;: Heroku natively supports Java, making it easier to deploy Spring Boot apps.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Prepare Your Spring Boot Application
&lt;/h2&gt;

&lt;p&gt;Before deploying, ensure that your Spring Boot 3.1 application meets these requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uses &lt;strong&gt;Tomcat 10.1&lt;/strong&gt; as the embedded server.&lt;/li&gt;
&lt;li&gt;Configured with PostgreSQL or any other database compatible with Heroku.&lt;/li&gt;
&lt;li&gt;Includes a &lt;code&gt;Procfile&lt;/code&gt; for Heroku execution.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Add Dependencies
&lt;/h3&gt;

&lt;p&gt;Update your &lt;code&gt;pom.xml&lt;/code&gt; with the necessary dependencies for Spring Boot and Tomcat:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.springframework.boot&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;spring-boot-starter-web&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.apache.tomcat.embed&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;tomcat-embed-core&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;10.1.0&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Configure Heroku for Deployment
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Install the Heroku CLI
&lt;/h3&gt;

&lt;p&gt;If you haven’t already, install the Heroku CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://cli-assets.heroku.com/install.sh | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Login to Heroku
&lt;/h3&gt;

&lt;p&gt;Run 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;heroku login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This opens a browser window for authentication.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Create a New Heroku App
&lt;/h3&gt;

&lt;p&gt;In your project root directory, initialize a new Heroku app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku create your-app-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;your-app-name&lt;/code&gt; with a unique name.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Configure the Procfile
&lt;/h2&gt;

&lt;p&gt;Heroku requires a &lt;code&gt;Procfile&lt;/code&gt; to specify the process type. Create a file named &lt;code&gt;Procfile&lt;/code&gt; in your project root and add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;web: java -jar target/your-app.jar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;your-app.jar&lt;/code&gt; with the actual name of your built JAR file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Configure Application Properties
&lt;/h2&gt;

&lt;p&gt;Heroku provides environment variables for configurations. Update your &lt;code&gt;application.properties&lt;/code&gt; or &lt;code&gt;application.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server.port=${PORT}
spring.datasource.url=${JDBC_DATABASE_URL}
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: Deploy to Heroku
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Initialize Git
&lt;/h3&gt;

&lt;p&gt;If your project is not already a Git repository, initialize it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Initial commit"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Deploy to Heroku
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push heroku main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After deployment, Heroku assigns a URL to your app. You can check the status with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku logs &lt;span class="nt"&gt;--tail&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Scale the App
&lt;/h3&gt;

&lt;p&gt;Heroku automatically assigns a free-tier &lt;strong&gt;dyno&lt;/strong&gt; to your application. If needed, scale it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku ps:scale &lt;span class="nv"&gt;web&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 6: Open Your Application
&lt;/h2&gt;

&lt;p&gt;Once deployed, open your application in a browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku open
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should load your Spring Boot 3.1 application running on Tomcat 10.1!&lt;/p&gt;

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

&lt;p&gt;Deploying a Spring Boot 3.1 application on Heroku with Tomcat 10.1 is straightforward. By following these steps, you can leverage Heroku’s cloud infrastructure to run your applications efficiently with minimal setup.&lt;/p&gt;

&lt;p&gt;🚀 &lt;strong&gt;Next Steps:&lt;/strong&gt; Explore Heroku’s PostgreSQL integration, auto-scaling, and log monitoring for a more robust deployment!&lt;/p&gt;




&lt;p&gt;Got questions or need help? Drop a comment below and let's discuss! 🚀&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>springboot</category>
    </item>
    <item>
      <title>How to Host a Web App for Free</title>
      <dc:creator>Nikhil Soman Sahu</dc:creator>
      <pubDate>Wed, 02 Apr 2025 05:04:54 +0000</pubDate>
      <link>https://dev.to/nikhilxd/how-to-host-a-web-app-for-free-532h</link>
      <guid>https://dev.to/nikhilxd/how-to-host-a-web-app-for-free-532h</guid>
      <description>&lt;p&gt;Have you ever built an awesome web app, only to realize that &lt;strong&gt;hosting can be expensive&lt;/strong&gt;? Well, what if I told you that you can &lt;strong&gt;deploy a fully functional, production-ready web app for FREE&lt;/strong&gt;? No gimmicks, no trial periods—just smart choices.&lt;/p&gt;

&lt;p&gt;In this guide, I’ll walk you through the &lt;strong&gt;best free hosting platforms&lt;/strong&gt; for frontends, backends, databases, and even CI/CD. By the end, you’ll have everything you need to launch your web app &lt;strong&gt;without spending a dime&lt;/strong&gt;. 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 Step 1: Choose the Right Hosting for Your App
&lt;/h2&gt;

&lt;p&gt;Not all free hosting services are equal. The best one depends on &lt;strong&gt;what you’re building&lt;/strong&gt;. Here’s a quick breakdown:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;App Type&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Best Free Hosting Option&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Static Sites (HTML, CSS, JS)&lt;/td&gt;
&lt;td&gt;GitHub Pages, Netlify, Cloudflare Pages&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;React, Vue, Angular Apps&lt;/td&gt;
&lt;td&gt;Vercel, Netlify, Cloudflare Pages&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Node.js/Python/Django APIs&lt;/td&gt;
&lt;td&gt;Railway, Render, Fly.io&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Full-Stack Apps&lt;/td&gt;
&lt;td&gt;Railway, Render, Fly.io&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Databases (PostgreSQL, MongoDB)&lt;/td&gt;
&lt;td&gt;NeonDB, Supabase, MongoDB Atlas&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Let’s dive deeper into each option. 🔥&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 &lt;strong&gt;Frontend Hosting (For Static &amp;amp; JS Framework Apps)&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1️⃣ &lt;strong&gt;GitHub Pages (For Static Sites)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Best for&lt;/strong&gt;: Simple static websites, portfolios, documentation.&lt;br&gt;
✅ &lt;strong&gt;Free Features&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Host static files with a custom domain.&lt;/li&gt;
&lt;li&gt;Automatic HTTPS.&lt;/li&gt;
&lt;li&gt;Unlimited bandwidth.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📌 &lt;strong&gt;How to Deploy:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Push your project to a GitHub repo.&lt;/li&gt;
&lt;li&gt;Go to &lt;strong&gt;Settings → Pages&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select the branch and folder to deploy.&lt;/li&gt;
&lt;li&gt;Your site will be live at &lt;code&gt;https://yourusername.github.io/reponame/&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;


&lt;h3&gt;
  
  
  2️⃣ &lt;strong&gt;Vercel (For React, Next.js, Vue)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Best for&lt;/strong&gt;: Frontend frameworks like Next.js, React, Vue, and Svelte.&lt;br&gt;
✅ &lt;strong&gt;Free Features&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automatic CI/CD (just push to GitHub, and it deploys).&lt;/li&gt;
&lt;li&gt;Serverless API support (Edge Functions).&lt;/li&gt;
&lt;li&gt;Global CDN for fast performance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📌 &lt;strong&gt;How to Deploy:&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;npm i &lt;span class="nt"&gt;-g&lt;/span&gt; vercel
vercel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🚀 &lt;strong&gt;Done!&lt;/strong&gt; You’ll get an instant live URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Alternative:&lt;/strong&gt; Netlify (better for Jamstack apps, similar features).&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 &lt;strong&gt;Backend Hosting (For APIs &amp;amp; Full-Stack Apps)&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3️⃣ &lt;strong&gt;Railway.app (For Node.js, Python, Django, Spring Boot)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Best for&lt;/strong&gt;: Full-stack web apps with backend APIs.&lt;br&gt;
✅ &lt;strong&gt;Free Features&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;500 hours/month&lt;/strong&gt; of free runtime (~21 days of continuous usage).&lt;/li&gt;
&lt;li&gt;PostgreSQL and MySQL databases.&lt;/li&gt;
&lt;li&gt;Simple Git-based deployment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📌 &lt;strong&gt;How to Deploy:&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;railway up  &lt;span class="c"&gt;# Automatically deploys backend&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🚀 &lt;strong&gt;Boom! Your backend is live.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Alternatives:&lt;/strong&gt; Render (better uptime), Fly.io (for Dockerized apps).&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 &lt;strong&gt;Free Database Hosting (For Storing App Data)&lt;/strong&gt;
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Database&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Free Tier Features&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;MongoDB Atlas&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;512MB storage, 100 concurrent connections&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Supabase (PostgreSQL)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;500MB database, RESTful API&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;NeonDB (PostgreSQL)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;1GB free, automatic scaling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;PlanetScale (MySQL)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;5GB storage, 10M row reads/month&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;📌 &lt;strong&gt;How to Connect Your App to a Free Database:&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;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;DATABASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"your-free-db-url"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔗 Now your backend can communicate with the database!&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 &lt;strong&gt;CI/CD for Automatic Deployments (No Manual Work!)&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  4️⃣ &lt;strong&gt;GitHub Actions (For Auto-Deployments)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Best for&lt;/strong&gt;: Automating deployments every time you push code.&lt;br&gt;
✅ &lt;strong&gt;Free Features&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unlimited private repositories.&lt;/li&gt;
&lt;li&gt;2,000 minutes/month of free CI/CD.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📌 &lt;strong&gt;Example: Auto-Deploy to Vercel&lt;/strong&gt;&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="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deploy to Vercel&lt;/span&gt;
&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;
&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;deploy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v3&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm install -g vercel&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;vercel --prod&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔄 Every time you push code to &lt;code&gt;main&lt;/code&gt;, your site updates &lt;strong&gt;automatically&lt;/strong&gt;!&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 &lt;strong&gt;Free Domain &amp;amp; SSL (For a Professional Touch)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Want a &lt;strong&gt;custom domain&lt;/strong&gt; (not just &lt;code&gt;yourapp.vercel.app&lt;/code&gt;)?&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;Free Options:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Freenom&lt;/strong&gt; → Free &lt;code&gt;.tk, .ml, .ga&lt;/code&gt; domains.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloudflare&lt;/strong&gt; → Free SSL &amp;amp; DNS management.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;InfinityFree&lt;/strong&gt; → Free cPanel hosting + free subdomain.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📌 &lt;strong&gt;How to Connect a Custom Domain:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Get a free domain from &lt;a href="https://www.freenom.com/" rel="noopener noreferrer"&gt;Freenom&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Use Cloudflare for free HTTPS and DNS management.&lt;/li&gt;
&lt;li&gt;Link it to your hosting provider (Vercel, Netlify, etc.).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now your site looks &lt;strong&gt;100% professional&lt;/strong&gt; with SSL encryption! 🔒✨&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 &lt;strong&gt;Final Free Hosting Stack (Fully Production-Ready!)&lt;/strong&gt;
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;Best Free Option&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Frontend Hosting&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Vercel / Cloudflare Pages&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Backend Hosting&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Railway / Render / Fly.io&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Database&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;NeonDB (PostgreSQL) / MongoDB Atlas&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;CI/CD&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;GitHub Actions / GitLab CI/CD&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Custom Domain&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Freenom + Cloudflare&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🚀 &lt;strong&gt;Final Thoughts: Is This Truly "Production-Ready"?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;✅ &lt;strong&gt;Yes, but&lt;/strong&gt; there are some trade-offs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cold starts&lt;/strong&gt; (some services may sleep after inactivity).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Free limits&lt;/strong&gt; (like compute hours or bandwidth).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database size restrictions&lt;/strong&gt; (good for MVPs, but not for huge traffic apps).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;💡 &lt;strong&gt;Pro Tip&lt;/strong&gt;: Use &lt;strong&gt;Cloudflare caching&lt;/strong&gt; and &lt;strong&gt;serverless functions&lt;/strong&gt; to reduce backend load and improve performance!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Are you ready to deploy your web app for free?&lt;/strong&gt; Drop a comment below if you have any questions! 🚀&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>staticwebapps</category>
      <category>vercel</category>
      <category>netlify</category>
    </item>
    <item>
      <title>Understanding LinkedIn Authwall: How it Works, Benefits, and Implementing it on Your Website</title>
      <dc:creator>Nikhil Soman Sahu</dc:creator>
      <pubDate>Tue, 05 Nov 2024 15:42:07 +0000</pubDate>
      <link>https://dev.to/nikhilxd/understanding-linkedin-authwall-how-it-works-benefits-and-implementing-it-on-your-website-3em1</link>
      <guid>https://dev.to/nikhilxd/understanding-linkedin-authwall-how-it-works-benefits-and-implementing-it-on-your-website-3em1</guid>
      <description>&lt;p&gt;The LinkedIn Authwall is a protective access layer that LinkedIn has implemented to manage the visibility of content and safeguard user information. This feature restricts access to certain content on LinkedIn to only authenticated (logged-in) users. In recent years, it has become a crucial tool for controlling content access on LinkedIn and ensuring a layer of privacy for its users. This article will dive into how LinkedIn Authwall works, its benefits, and how similar mechanisms can be implemented on your own website.&lt;/p&gt;




&lt;h3&gt;
  
  
  What is LinkedIn Authwall?
&lt;/h3&gt;

&lt;p&gt;The LinkedIn Authwall is a security mechanism that serves as an "authentication wall," preventing anonymous users from accessing specific pages or content. LinkedIn restricts certain profile and feed information behind this authwall, meaning visitors who are not logged in cannot see the content without first creating an account or logging in.&lt;/p&gt;

&lt;p&gt;This approach is widely used in several scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Viewing LinkedIn profiles.&lt;/li&gt;
&lt;li&gt;Accessing posts and comments.&lt;/li&gt;
&lt;li&gt;Reading in-depth articles from LinkedIn News.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The LinkedIn Authwall can be considered a type of “soft paywall” or “sign-up gate,” commonly used by social media platforms and content providers to increase engagement and control content distribution.&lt;/p&gt;




&lt;h3&gt;
  
  
  How Does LinkedIn Authwall Work?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Request Interception:&lt;/strong&gt; When an anonymous user (not logged in) tries to access protected content, LinkedIn’s backend intercepts the request. The platform assesses if the user is authenticated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Authentication Check:&lt;/strong&gt; The LinkedIn server checks if there’s a valid session for the user (indicating they’re logged in). If not, the server redirects the user to the LinkedIn login or registration page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Session Validation:&lt;/strong&gt; Upon successful login, LinkedIn generates a session cookie for the user. This cookie grants them access to the previously restricted content for that browsing session.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Re-authentication After Timeout:&lt;/strong&gt; To prevent abuse, the authwall can enforce a re-authentication process if the session expires or if the user logs out. This ensures that sensitive information is only accessible to verified users.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Benefits of LinkedIn Authwall
&lt;/h3&gt;

&lt;p&gt;The LinkedIn Authwall has several benefits, both for LinkedIn as a platform and for its users:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Privacy Protection:&lt;/strong&gt; Authwall provides a layer of privacy, protecting users' data from being scraped or accessed by anonymous visitors. Only authenticated users can access certain information, reducing unauthorized data collection.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;User Engagement:&lt;/strong&gt; By requiring users to log in, LinkedIn encourages greater engagement. Once users are logged in, they’re more likely to interact with content, add connections, or engage with posts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Collection:&lt;/strong&gt; LinkedIn gathers essential metrics from logged-in users, such as browsing behavior, search terms, and interaction patterns. These insights can be used to enhance personalization, ad targeting, and platform improvements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Security:&lt;/strong&gt; Authwall prevents automated bots from accessing user information, which reduces spam and improves the overall security of user data on the platform.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Growth in User Base:&lt;/strong&gt; Requiring logins to view certain content can incentivize new users to sign up. LinkedIn has grown its user base partly by creating valuable content that users need to be logged in to view.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Implementing an Authwall on Your Website
&lt;/h3&gt;

&lt;p&gt;If you’re interested in implementing an authwall on your website to protect specific content and increase user engagement, here are some steps and considerations:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. &lt;strong&gt;Identify Content to Protect&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Determine what content should be available to only authenticated users. For example:

&lt;ul&gt;
&lt;li&gt;User profiles&lt;/li&gt;
&lt;li&gt;Articles, reports, or premium resources&lt;/li&gt;
&lt;li&gt;Community forums or comment sections&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Sensitive data or subscription-based content is often a prime candidate for authwall protection.&lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. &lt;strong&gt;Set Up User Authentication&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Implement a robust authentication system. This can include:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sign-Up/Login Form:&lt;/strong&gt; Allow users to create an account or log in to access restricted content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OAuth Integration:&lt;/strong&gt; Use OAuth for a secure and convenient login process with other platforms (e.g., Google, Facebook).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Use session tokens or cookies to track authenticated users.&lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. &lt;strong&gt;Redirect Unauthenticated Users&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;When an unauthenticated user requests protected content, intercept the request and redirect them to a login or registration page.&lt;/li&gt;
&lt;li&gt;After successful login, redirect the user back to their desired content.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4. &lt;strong&gt;Session Management and Security&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Ensure that user sessions are properly managed, with secure session tokens to prevent unauthorized access.&lt;/li&gt;
&lt;li&gt;Consider using techniques like session expiration and multi-factor authentication for added security.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  5. &lt;strong&gt;UX Considerations&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Implement a smooth UX flow for the authwall. Offer a clear message explaining why the user needs to log in.&lt;/li&gt;
&lt;li&gt;If using a soft paywall approach, consider allowing users to view limited content before requiring login.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example Code for Implementing an Authwall in Node.js (Express)
&lt;/h4&gt;

&lt;p&gt;Here’s a simple example of how you could implement an authwall for a Node.js-based website using Express.&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express-session&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Middleware to check if the user is authenticated&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;authWall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/login&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="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Setting up session middleware&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;session&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-secret-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;resave&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="na"&gt;saveUninitialized&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}));&lt;/span&gt;

&lt;span class="c1"&gt;// Login route&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/login&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="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Please log in to access this content&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="c1"&gt;// Protected route (with authwall)&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/protected-content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;authWall&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;You have accessed protected content&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="c1"&gt;// Simulate login (for demonstration purposes)&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/login&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="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John Doe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt; &lt;span class="c1"&gt;// Mock user session&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/protected-content&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="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Server running on http://localhost:3000&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;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;authWall&lt;/code&gt; middleware checks if the user session exists. If not, it redirects the user to the login page.&lt;/li&gt;
&lt;li&gt;If the user is logged in, they are allowed to access protected content.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  6. &lt;strong&gt;Monitor User Engagement&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Track metrics like login frequency, content views, and user retention to understand how effective the authwall is in driving engagement.&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;The LinkedIn Authwall serves as an effective mechanism to protect user privacy, increase engagement, and manage access to content. By limiting content access to authenticated users, LinkedIn successfully enhances user interaction and improves data security.&lt;/p&gt;

&lt;p&gt;By applying a similar authwall mechanism on your website, you can protect sensitive content, encourage users to register, and foster a more engaged audience. While implementing an authwall requires thoughtful planning and technical implementation, the benefits in terms of security, privacy, and user experience make it a worthwhile addition to many types of websites.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>opensource</category>
      <category>java</category>
    </item>
    <item>
      <title>Mastering Encapsulation in Java: A Comprehensive Guide with Examples</title>
      <dc:creator>Nikhil Soman Sahu</dc:creator>
      <pubDate>Thu, 24 Oct 2024 05:20:02 +0000</pubDate>
      <link>https://dev.to/nikhilxd/mastering-encapsulation-in-java-a-comprehensive-guide-with-examples-4imn</link>
      <guid>https://dev.to/nikhilxd/mastering-encapsulation-in-java-a-comprehensive-guide-with-examples-4imn</guid>
      <description>&lt;h3&gt;
  
  
  A Detailed Guide to Java Encapsulation
&lt;/h3&gt;

&lt;p&gt;Encapsulation is one of the four fundamental OOP (Object-Oriented Programming) principles in Java, alongside inheritance, polymorphism, and abstraction. Encapsulation refers to bundling the data (attributes) and the methods that manipulate that data (behavior) into a single unit or class. In addition to bundling, encapsulation also involves restricting direct access to some of an object’s components, which is typically achieved through &lt;strong&gt;access modifiers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this article, we'll explore the concept of encapsulation in Java, its importance, practical examples, and how to implement it in your code effectively.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. &lt;strong&gt;What is Encapsulation?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Encapsulation in Java can be understood as the technique of hiding the internal details of an object and only exposing selected information to the outside world. It helps protect the internal state of an object from unintended or harmful changes by ensuring that the data cannot be accessed directly but can only be modified through well-defined methods.&lt;/p&gt;

&lt;p&gt;Encapsulation ensures &lt;strong&gt;data hiding&lt;/strong&gt;, which means restricting access to some of the class's variables and methods from outside the class, preventing accidental or malicious tampering with the object's state.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Key Components of Encapsulation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To implement encapsulation in Java, we generally use two main components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Private Fields&lt;/strong&gt;: These are the attributes or instance variables of a class, marked &lt;code&gt;private&lt;/code&gt; to restrict direct access.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Public Methods&lt;/strong&gt;: These methods are the interface to the class’s private fields. Typically, we use &lt;em&gt;getter&lt;/em&gt; and &lt;em&gt;setter&lt;/em&gt; methods to read and modify the values of the private fields.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Encapsulation in Action: A Practical Example&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Consider a real-world scenario where we want to manage the details of a &lt;code&gt;Student&lt;/code&gt; class. Here's how encapsulation can be used to protect the student's data:&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;class&lt;/span&gt; &lt;span class="nc"&gt;Student&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// Private fields (Data hiding)&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;age&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;grade&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Constructor&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Student&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;age&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;grade&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;age&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;grade&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;grade&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Public getter for 'name'&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

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

    &lt;span class="c1"&gt;// Public getter for 'age'&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;getAge&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;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Public setter for 'age' with a validation&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;setAge&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;age&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;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&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;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;age&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;"Please provide a valid age."&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="c1"&gt;// Public getter for 'grade'&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;getGrade&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;grade&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Public setter for 'grade'&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;setGrade&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;grade&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;grade&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;grade&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// A method to display student details&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;displayStudentInfo&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;"Name: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", Age: "&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;age&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", Grade: "&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;grade&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;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Private Fields&lt;/strong&gt;: The &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;age&lt;/code&gt;, and &lt;code&gt;grade&lt;/code&gt; fields are private, which means they cannot be accessed directly from outside the class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Public Getter and Setter Methods&lt;/strong&gt;: To access or modify the values of these fields, we provide public methods (&lt;code&gt;getName()&lt;/code&gt;, &lt;code&gt;setName()&lt;/code&gt;, &lt;code&gt;getAge()&lt;/code&gt;, &lt;code&gt;setAge()&lt;/code&gt;, etc.).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validation&lt;/strong&gt;: Encapsulation also allows us to validate or control the data before modifying the fields. For instance, in the &lt;code&gt;setAge()&lt;/code&gt; method, the age is checked for a valid positive value before being set.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Usage of Encapsulation:
&lt;/h3&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;class&lt;/span&gt; &lt;span class="nc"&gt;Main&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;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="c1"&gt;// Create an instance of Student&lt;/span&gt;
        &lt;span class="nc"&gt;Student&lt;/span&gt; &lt;span class="n"&gt;student&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;Student&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"A"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Access the student's details via public methods&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;"Student Name: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setAge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Updates the age after validation&lt;/span&gt;
        &lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;displayStudentInfo&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Attempting invalid data modification&lt;/span&gt;
        &lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setAge&lt;/span&gt;&lt;span class="o"&gt;(-&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Will prompt the validation failure message&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;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Student Name: Alice
Name: Alice, Age: 22, Grade: A
Please provide a valid age.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. &lt;strong&gt;Advantages of Encapsulation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Encapsulation provides several significant benefits:&lt;/p&gt;

&lt;h4&gt;
  
  
  4.1 &lt;strong&gt;Control Over Data&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Encapsulation allows you to control how the data is accessed and modified. This is crucial for maintaining a clean, error-free state of the object. In the example above, the &lt;code&gt;setAge()&lt;/code&gt; method includes a validation to ensure the age cannot be negative.&lt;/p&gt;

&lt;h4&gt;
  
  
  4.2 &lt;strong&gt;Improved Security&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Since the internal implementation of a class is hidden, it helps protect sensitive data from unauthorized access or modifications. Only specific parts of the code are exposed through public methods, making the class more secure.&lt;/p&gt;

&lt;h4&gt;
  
  
  4.3 &lt;strong&gt;Easy Maintenance and Flexibility&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;By using getter and setter methods, the internal workings of the class can be changed without affecting the external code. For example, you can change how the age is calculated internally without altering the code that uses the &lt;code&gt;getAge()&lt;/code&gt; method.&lt;/p&gt;

&lt;h4&gt;
  
  
  4.4 &lt;strong&gt;Loose Coupling&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Encapsulation ensures that classes interact with each other through well-defined interfaces. This reduces dependencies between different parts of the application and makes the code more modular, which facilitates easier debugging and unit testing.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. &lt;strong&gt;Encapsulation and Java Access Modifiers&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Encapsulation is tightly associated with Java's access modifiers, which help define the visibility of class members (fields and methods).&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Access Modifier&lt;/th&gt;
&lt;th&gt;Class&lt;/th&gt;
&lt;th&gt;Package&lt;/th&gt;
&lt;th&gt;Subclass&lt;/th&gt;
&lt;th&gt;World&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;private&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;default&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;protected&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;public&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Private&lt;/strong&gt;: The field/method is only accessible within the same class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Default (Package-private)&lt;/strong&gt;: Accessible within the same package but not outside.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Protected&lt;/strong&gt;: Accessible within the same package and subclasses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Public&lt;/strong&gt;: Accessible from any class in any package.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6. &lt;strong&gt;Common Mistakes When Implementing Encapsulation&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  6.1 &lt;strong&gt;Exposing Fields Through Public Access&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Developers often make the mistake of declaring fields &lt;code&gt;public&lt;/code&gt;, which violates the principle of encapsulation. Always prefer &lt;code&gt;private&lt;/code&gt; fields with public getter/setter methods instead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Bad practice&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;Employee&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="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// Should be private&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;       &lt;span class="c1"&gt;// Should be private&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  6.2 &lt;strong&gt;Not Validating Inputs in Setter Methods&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Without validations, encapsulation can become meaningless. Setter methods should always ensure that the data being set is valid.&lt;/p&gt;

&lt;h4&gt;
  
  
  6.3 &lt;strong&gt;Using Only Getters/Setters Without Logic&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Simply having getters and setters without any business logic or validation does not fully leverage the power of encapsulation. &lt;/p&gt;

&lt;h3&gt;
  
  
  7. &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Encapsulation is a vital concept in Java that enhances security, maintains control over data, and improves the modularity of code. It allows you to manage how data is exposed and manipulated, providing a mechanism to protect the integrity of an object’s state. By combining private fields with public getter and setter methods, you can create robust, maintainable, and secure Java applications.&lt;/p&gt;

&lt;p&gt;Mastering encapsulation, along with the other OOP principles like inheritance, abstraction, and polymorphism, will help you design better object-oriented systems that are scalable and easier to maintain.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>java</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Spring Boot Caching Simplified: How to Use JetCache Effectively</title>
      <dc:creator>Nikhil Soman Sahu</dc:creator>
      <pubDate>Mon, 21 Oct 2024 16:49:31 +0000</pubDate>
      <link>https://dev.to/nikhilxd/spring-boot-caching-simplified-how-to-use-jetcache-effectively-1ndb</link>
      <guid>https://dev.to/nikhilxd/spring-boot-caching-simplified-how-to-use-jetcache-effectively-1ndb</guid>
      <description>&lt;p&gt;Caching is a powerful technique that can drastically improve application performance by reducing the need to retrieve data from a slow data store like a database. JetCache is a Java-based caching library that integrates seamlessly with Spring Boot, providing annotations, easy configuration, and multi-level caching support (local + remote). In this article, we will explore how to use JetCache in a Spring Boot application, covering its key features and practical examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why JetCache?
&lt;/h2&gt;

&lt;p&gt;JetCache stands out for the following reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ease of Use&lt;/strong&gt;: It provides simple annotations like &lt;code&gt;@Cached&lt;/code&gt; for caching methods.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support for Multi-Level Caching&lt;/strong&gt;: You can configure both local (in-memory) and remote (Redis) caches easily.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Auto Configuration with Spring Boot&lt;/strong&gt;: JetCache integrates easily with Spring Boot's auto-configuration features.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Out-of-the-Box Integration&lt;/strong&gt;: It supports various cache providers such as Redis, Caffeine, and even custom implementations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Features of JetCache
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Declarative Caching&lt;/strong&gt;: Use annotations like &lt;code&gt;@Cached&lt;/code&gt;, &lt;code&gt;@CacheInvalidate&lt;/code&gt;, and &lt;code&gt;@CacheUpdate&lt;/code&gt; for caching behavior.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-Level Cache&lt;/strong&gt;: It allows using both local and remote cache providers for efficient caching strategies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support for Key Generation&lt;/strong&gt;: JetCache provides automatic or custom key generation for cache entries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TTL (Time to Live) Settings&lt;/strong&gt;: Set expiration time for cache entries on both local and remote levels.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s now dive into how to integrate JetCache into a Spring Boot application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Set Up the Spring Boot Project
&lt;/h2&gt;

&lt;p&gt;To get started, create a new Spring Boot project with the necessary dependencies. You can use Spring Initializr or manually add the following dependencies to your &lt;code&gt;pom.xml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;com.github.alicp.jetcache&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;jetcache-starter-redis-lettuce&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- For Redis support --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;2.7.14&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.springframework.boot&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;spring-boot-starter-data-redis&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;com.github.ben-manes.caffeine&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;caffeine&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- For Local Cache --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Configure JetCache in &lt;code&gt;application.yml&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;spring&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;none&lt;/span&gt;

&lt;span class="na"&gt;jetcache&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;statIntervalMinutes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;  &lt;span class="c1"&gt;# Statistics output interval&lt;/span&gt;
  &lt;span class="na"&gt;areaInCacheName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="na"&gt;local&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;limit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;  &lt;span class="c1"&gt;# Maximum number of entries in local cache&lt;/span&gt;
      &lt;span class="na"&gt;expireAfterWriteInMillis&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;60000&lt;/span&gt;  &lt;span class="c1"&gt;# TTL for local cache&lt;/span&gt;
  &lt;span class="na"&gt;remote&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;redis&lt;/span&gt;
      &lt;span class="na"&gt;keyConvertor&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;fastjson&lt;/span&gt;
      &lt;span class="na"&gt;ttlInMillis&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;300000&lt;/span&gt;  &lt;span class="c1"&gt;# 5 minutes TTL for Redis cache&lt;/span&gt;
      &lt;span class="na"&gt;jedis&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;localhost&lt;/span&gt;
        &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6379&lt;/span&gt;
        &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;  &lt;span class="c1"&gt;# Add password if Redis requires authentication&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Create a Service with Caching Enabled
&lt;/h3&gt;

&lt;p&gt;Let’s create a simple service that fetches user data, simulating a database query, and cache the result.&lt;/p&gt;

&lt;h4&gt;
  
  
  User Entity
&lt;/h4&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;class&lt;/span&gt; &lt;span class="nc"&gt;User&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;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Constructor, Getters, and Setters&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;User&lt;/span&gt;&lt;span class="o"&gt;(&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="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// getters and setters&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  UserService
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;com.alicp.jetcache.anno.Cached&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.stereotype.Service&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@Service&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;UserService&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// Simulate a database call&lt;/span&gt;
    &lt;span class="nd"&gt;@Cached&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"userCache-"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"#id"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expire&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;localExpire&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;60&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;User&lt;/span&gt; &lt;span class="nf"&gt;getUserById&lt;/span&gt;&lt;span class="o"&gt;(&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="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;simulateSlowService&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;User&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"User "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Invalidate the cache entry for the given ID&lt;/span&gt;
    &lt;span class="nd"&gt;@CacheInvalidate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"userCache-"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"#id"&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;invalidateUserCache&lt;/span&gt;&lt;span class="o"&gt;(&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="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// This method will remove the user from the cache&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Simulate a slow response (e.g., a database call)&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;simulateSlowService&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// Simulate delay&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;InterruptedException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalStateException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&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;p&gt;In this service:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;@Cached&lt;/code&gt; annotation is used to cache the result of &lt;code&gt;getUserById&lt;/code&gt;. The key for the cache is the &lt;code&gt;id&lt;/code&gt;, and the cache entry will expire after 5 minutes in Redis and 1 minute in local memory.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;@CacheInvalidate&lt;/code&gt; annotation allows us to remove a specific entry from the cache.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 4: Use the Service in a Controller
&lt;/h3&gt;

&lt;p&gt;Let’s expose this service via a REST controller to fetch and invalidate cached user data.&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="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.web.bind.annotation.GetMapping&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.web.bind.annotation.PathVariable&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.web.bind.annotation.RestController&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@RestController&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;UserController&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt; &lt;span class="n"&gt;userService&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;UserController&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;UserService&lt;/span&gt; &lt;span class="n"&gt;userService&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;userService&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;userService&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/user/{id}"&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;User&lt;/span&gt; &lt;span class="nf"&gt;getUserById&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@PathVariable&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="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;userService&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getUserById&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/user/{id}/invalidate"&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;invalidateCache&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@PathVariable&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="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;userService&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;invalidateUserCache&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Cache for User ID "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" invalidated."&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;h3&gt;
  
  
  Step 5: Test the Caching Behavior
&lt;/h3&gt;

&lt;p&gt;When you run the application, access the following endpoints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GET /user/1&lt;/strong&gt;: The first call will simulate a slow service and take 3 seconds to return. The result will be cached.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GET /user/1&lt;/strong&gt; (subsequent call): This call will return the cached result instantly from the local cache (if within 1 minute) or from Redis (if within 5 minutes).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GET /user/1/invalidate&lt;/strong&gt;: This endpoint invalidates the cached data for the user with ID &lt;code&gt;1&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 6: Monitor the Cache
&lt;/h3&gt;

&lt;p&gt;JetCache provides built-in statistics to monitor cache hits and misses. By default, it logs cache statistics every 5 minutes. You can configure this interval or manually output statistics using &lt;code&gt;CacheMonitor&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  JetCache Annotations
&lt;/h2&gt;

&lt;p&gt;Let’s dive deeper into some of the key JetCache annotations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;@Cached&lt;/code&gt;: Caches the result of a method. Parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;name&lt;/code&gt;: Prefix for cache key names.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;key&lt;/code&gt;: SpEL expression to specify cache keys.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;expire&lt;/code&gt;: TTL for remote cache in seconds.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;localExpire&lt;/code&gt;: TTL for local cache in seconds.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;code&gt;@CacheInvalidate&lt;/code&gt;: Removes an entry from the cache. Parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;name&lt;/code&gt;: Prefix for the cache key name.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;key&lt;/code&gt;: SpEL expression to specify the cache key to invalidate.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;code&gt;@CacheUpdate&lt;/code&gt;: Updates an existing cache entry. You can use this for methods that modify data and should refresh the cache.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Multi-Level Caching with JetCache
&lt;/h2&gt;

&lt;p&gt;JetCache supports both local and remote caches. Here’s a quick summary of how multi-level caching works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Local Cache&lt;/strong&gt;: Stored in memory (e.g., using Caffeine). Local cache is typically faster but has limited size.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remote Cache&lt;/strong&gt;: Stored in external services like Redis. Remote caches are slower but can store much larger datasets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JetCache uses local cache first. If a cache miss occurs, it will check the remote cache (e.g., Redis). This setup offers a good balance between speed and capacity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices for Using JetCache
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Avoid Over-Caching&lt;/strong&gt;: Cache only data that is expensive to retrieve and doesn’t change frequently.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set Reasonable Expirations&lt;/strong&gt;: Choose appropriate TTLs for both local and remote caches to avoid stale data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monitor Cache Usage&lt;/strong&gt;: JetCache provides statistics to help you monitor cache performance. Use them to optimize your cache settings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consider Cache Size&lt;/strong&gt;: Especially for local caches, ensure you have limits in place to avoid memory overflow.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;JetCache provides a simple yet powerful way to integrate caching into your Spring Boot application. With easy-to-use annotations, support for multi-level caching, and robust integration with popular cache providers like Redis, JetCache can significantly improve your application's performance.&lt;/p&gt;

&lt;p&gt;By following the steps in this guide, you can set up caching in your Spring Boot applications quickly and efficiently. Whether you’re caching small lookups in local memory or large datasets in Redis, JetCache has you covered.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Further Reading&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/alibaba/jetcache" rel="noopener noreferrer"&gt;JetCache Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://spring.io/guides/gs/caching/" rel="noopener noreferrer"&gt;Spring Boot Caching Guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>springboot</category>
      <category>springsecurity</category>
      <category>webdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Deleting Duplicate Data from MySQL</title>
      <dc:creator>Nikhil Soman Sahu</dc:creator>
      <pubDate>Mon, 23 Sep 2024 16:57:24 +0000</pubDate>
      <link>https://dev.to/nikhilxd/deleting-duplicate-data-from-mysql-10bk</link>
      <guid>https://dev.to/nikhilxd/deleting-duplicate-data-from-mysql-10bk</guid>
      <description>&lt;p&gt;Hey there, 👋 Welcome to another blog post. Today, we’ll tackle something every database engineer faces at some point—deleting duplicate data in MySQL. This is a crucial skill, especially when managing large datasets where data cleanliness is vital.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why Should We Remove Duplicates?
&lt;/h4&gt;

&lt;p&gt;Imagine you’re managing a user database for a website. If users sign up multiple times due to some glitch or error, you’ll end up with duplicates. This can mess up your reports, slow down queries, and increase storage costs. So, let’s get our hands dirty and see how to remove these duplicates!&lt;/p&gt;




&lt;h3&gt;
  
  
  Setting Up the Scenario
&lt;/h3&gt;

&lt;p&gt;Let’s start with a simple &lt;strong&gt;&lt;code&gt;users&lt;/code&gt;&lt;/strong&gt; table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="n"&gt;AUTO_INCREMENT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="nb"&gt;TIMESTAMP&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="k"&gt;CURRENT_TIMESTAMP&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And let’s insert some duplicate data to simulate the real-world problem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'john.doe@example.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'John Doe'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'jane.smith@example.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Jane Smith'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'john.doe@example.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'John Doe'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'mary.jane@example.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Mary Jane'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'jane.smith@example.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Jane Smith'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if we run a simple query to check the data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll notice there are duplicate emails. Let’s work on cleaning that up!&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 1: Identifying Duplicates
&lt;/h3&gt;

&lt;p&gt;Before we delete anything, we need to identify which rows are duplicates. One way to find duplicate entries is by using the &lt;code&gt;GROUP BY&lt;/code&gt; clause in MySQL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;
&lt;span class="k"&gt;HAVING&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query shows you any email addresses that appear more than once.&lt;/p&gt;

&lt;p&gt;What other ways could duplicates sneak into a table? It’s not always about emails—what else should we look out for? Comment below with your thoughts!&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 2: Deleting Duplicates, the Safe Way
&lt;/h3&gt;

&lt;p&gt;Deleting rows from a database always requires caution. In MySQL, one common trick to delete duplicate rows while keeping one copy is using a &lt;strong&gt;subquery&lt;/strong&gt; combined with &lt;strong&gt;&lt;code&gt;ROW_NUMBER()&lt;/code&gt;&lt;/strong&gt;. But since MySQL (before version 8.0) doesn’t support window functions, we’ll use a more classic approach with a &lt;strong&gt;temporary table&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here’s how to safely delete duplicates:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create a Temporary Table&lt;/strong&gt; that holds the unique rows.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TEMPORARY&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;temp_users&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;MIN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Delete the Duplicates&lt;/strong&gt; from the original table.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;IN&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;temp_users&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Verify the Result.&lt;/strong&gt; Let’s make sure only unique entries remain:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Boom! 🎉 You’ve removed the duplicates, leaving only one copy of each email.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 3: Another Method for MySQL 8.0+
&lt;/h3&gt;

&lt;p&gt;If you’re using &lt;strong&gt;MySQL 8.0 or later&lt;/strong&gt;, you have access to the &lt;code&gt;ROW_NUMBER()&lt;/code&gt; function, which makes this process even easier. Let’s check it out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;RankedUsers&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ROW_NUMBER&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;rn&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="k"&gt;IN&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;RankedUsers&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;rn&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we assign a row number (&lt;code&gt;rn&lt;/code&gt;) to each duplicate based on their &lt;code&gt;email&lt;/code&gt;. Rows with &lt;code&gt;rn &amp;gt; 1&lt;/code&gt; are the duplicates and get deleted.&lt;/p&gt;




&lt;h3&gt;
  
  
  Common Pitfalls to Avoid
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Accidental Deletion:&lt;/strong&gt; Always run a &lt;code&gt;SELECT&lt;/code&gt; query to identify duplicates before jumping to &lt;code&gt;DELETE&lt;/code&gt;. I recommend testing on a small subset of data before running it on the entire table.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Handling More Complex Duplicates:&lt;/strong&gt; Sometimes duplicates aren’t exact matches. For instance, &lt;code&gt;john.doe@example.com&lt;/code&gt; vs. &lt;code&gt;JOHN.DOE@EXAMPLE.COM&lt;/code&gt;. Case sensitivity can trip you up, so always normalize data before deduplication.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Final Thoughts: Keep it Clean!
&lt;/h3&gt;

&lt;p&gt;Data quality is key to any successful project. Removing duplicates keeps your database lean and your queries fast. The methods I shared here are good starting points, but always adapt to your specific use case.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Interactive Question:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;What strategies do you use to prevent duplicates from entering your database in the first place? Share your best practices below!&lt;/p&gt;

</description>
      <category>database</category>
      <category>sql</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Spring Security: Protecting Your App from Everyone (Including You!)</title>
      <dc:creator>Nikhil Soman Sahu</dc:creator>
      <pubDate>Mon, 16 Sep 2024 18:00:11 +0000</pubDate>
      <link>https://dev.to/nikhilxd/spring-security-protecting-your-app-from-everyone-including-you-1023</link>
      <guid>https://dev.to/nikhilxd/spring-security-protecting-your-app-from-everyone-including-you-1023</guid>
      <description>&lt;p&gt;If you've ever spent an afternoon battling with Spring Security, you might feel like the framework was built for one purpose: to protect your app from everyone, even yourself. In fact, it’s almost as if Spring Security operates on the core philosophy of “Hey, let’s make sure no one can access this, especially the guy who built it.”&lt;/p&gt;

&lt;p&gt;So buckle up, as we dive into a sarcastic journey through the world of Spring Security, where permissions are denied, roles are confused, and the developer is the ultimate intruder.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 1: The Setup – Inviting Chaos
&lt;/h3&gt;

&lt;p&gt;You start with a basic Spring Boot project, full of hope and optimism. “I’ll just add Spring Security for, you know, &lt;em&gt;security&lt;/em&gt;,” you think innocently. A few clicks later, you include the Spring Security dependency. Congratulations, your application is now as secure as Fort Knox—and by that, I mean, &lt;strong&gt;no one’s getting in.&lt;/strong&gt; Not your users, not your admin, and definitely not you.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.springframework.boot&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;spring-boot-starter-security&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You see that? You just installed a &lt;strong&gt;force field&lt;/strong&gt; around your app. Who needs access anyway?&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 2: Access Denied – The Default Security Config
&lt;/h3&gt;

&lt;p&gt;Spring Security’s default configuration is kind of like a bouncer at a nightclub. He doesn’t care who you are—if you’re not on the list, you’re not getting in. In this case, there &lt;em&gt;is&lt;/em&gt; no list, so you’re out by default.&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;@Override&lt;/span&gt;
&lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HttpSecurity&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;http&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;authorizeRequests&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;anyRequest&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;authenticated&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;and&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;formLogin&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;permitAll&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;The above configuration means your entire app is locked down until authenticated. Even the home page. Yes, the home page! Because why should you have access to your own home, right? Spring Security seems to believe that every route is sacred, and even you, the developer, are not worthy.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 3: The Password – Only a Minor Speed Bump
&lt;/h3&gt;

&lt;p&gt;Now that Spring has locked you out of your app, how do you get back in? You open your console and there it is—a randomly generated password printed out just for you. Good luck remembering this 32-character monstrosity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Using default security password: 9a80989c-78bf-44a5-b96e-8b5d582f7de9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Feeling secure? Because I’m feeling locked out. At this point, it feels like Spring Security is more about &lt;strong&gt;security theater&lt;/strong&gt; than actual functionality. But hey, at least it’s not “admin123.”&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 4: Configuring User Roles – The Power Struggle
&lt;/h3&gt;

&lt;p&gt;Let's say you want to create an admin role and a user role. Seems simple enough, right? Oh, but this is Spring Security we’re talking about. First, you have to create the roles in the database. Then, you need to grant permissions to your URLs based on these roles. And guess what? Even after you do all that, you'll probably find that no one—&lt;em&gt;not even your admin&lt;/em&gt;—can actually access the admin page.&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;@Override&lt;/span&gt;
&lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HttpSecurity&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;http&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;authorizeRequests&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;antMatchers&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/admin/**"&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;hasRole&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"ADMIN"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;antMatchers&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/user/**"&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;hasRole&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"USER"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;and&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;formLogin&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;permitAll&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;You’ve now implemented role-based access control (RBAC), which is supposed to give you fine-grained control over who can do what. But in reality, you’ve created a hierarchical mess where not even &lt;em&gt;you&lt;/em&gt; are sure what your app is doing anymore.&lt;/p&gt;

&lt;p&gt;Want to see something fun? Try assigning roles manually in the database and &lt;em&gt;forget&lt;/em&gt; to include the “ROLE_” prefix before the role name. Now, nobody has access to anything. Welcome to your own security dungeon.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 5: Customizing Authentication – Because Defaults Are Boring
&lt;/h3&gt;

&lt;p&gt;Feeling brave? Want to customize your authentication process? You’ll quickly learn that Spring Security is very protective of its defaults. Change the login page, and you might accidentally break your entire authentication process. Add OAuth2 into the mix, and you’ll spend the next week wondering why your app now authenticates you &lt;em&gt;somewhere&lt;/em&gt;, but you’re not quite sure &lt;em&gt;where.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;and&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;formLogin&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;loginPage&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/custom-login"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;failureUrl&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/login-error"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code changes the default login page to a custom one. Seems easy, right? Until you realize that, despite doing everything correctly, your custom login page throws a &lt;code&gt;403 Forbidden&lt;/code&gt; error. Why? Because you, the developer, have no right to be trusted with something as crucial as a login form.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 6: Debugging Spring Security – Good Luck with That
&lt;/h3&gt;

&lt;p&gt;One of the best parts about Spring Security is debugging it. When something goes wrong—and trust me, it will—you'll be met with error messages that look like they were generated by a random error generator.&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="n"&gt;org&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;springframework&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;security&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;access&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;AccessDeniedException&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Access&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt; &lt;span class="n"&gt;denied&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Access is denied. To what? Why? Who knows! You can stare at your configuration for hours, try every combination of roles and permissions, and the answer is always the same: &lt;strong&gt;Access is denied.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At this point, you’re probably questioning your career choices and wondering if securing your app is really worth the effort. Maybe just having no security at all isn’t such a bad idea...&lt;/p&gt;




&lt;h3&gt;
  
  
  Conclusion: Embrace the Chaos
&lt;/h3&gt;

&lt;p&gt;Spring Security is undoubtedly powerful. It can protect your app from malicious actors, unauthorized users, and, of course, yourself. But be warned: implementing it will test your patience, your sanity, and your will to keep pushing forward.&lt;/p&gt;

&lt;p&gt;The next time you encounter an &lt;code&gt;AccessDeniedException&lt;/code&gt;, just remember—it’s not personal. Spring Security just wants to protect you from the real danger... you.&lt;/p&gt;

</description>
      <category>java</category>
      <category>springboot</category>
      <category>springsecurity</category>
      <category>docker</category>
    </item>
    <item>
      <title>Java 8 Features: A Comprehensive Guide</title>
      <dc:creator>Nikhil Soman Sahu</dc:creator>
      <pubDate>Mon, 16 Sep 2024 17:11:57 +0000</pubDate>
      <link>https://dev.to/nikhilxd/java-8-features-a-comprehensive-guide-2e7c</link>
      <guid>https://dev.to/nikhilxd/java-8-features-a-comprehensive-guide-2e7c</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0i4abce45vrdd8fy96yx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0i4abce45vrdd8fy96yx.jpg" alt="Image description" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Java 8, released in March 2014, brought significant improvements and new features to the Java programming language. This version introduced functional programming concepts, enhanced the Java API, and provided developers with powerful tools to write more efficient and concise code. In this article, we'll explore the key features of Java 8 and how they can benefit your development process.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Lambda Expressions
&lt;/h2&gt;

&lt;p&gt;Lambda expressions are perhaps the most significant feature introduced in Java 8. They provide a clear and concise way to represent one method interface using an expression. Lambda expressions let you treat functionality as a method argument, or code as data.&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 java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Before Java 8&lt;/span&gt;
&lt;span class="nc"&gt;Runnable&lt;/span&gt; &lt;span class="n"&gt;runnable&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;Runnable&lt;/span&gt;&lt;span class="o"&gt;()&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="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;run&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;"Hello from thread"&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="c1"&gt;// With Lambda in Java 8&lt;/span&gt;
&lt;span class="nc"&gt;Runnable&lt;/span&gt; &lt;span class="n"&gt;runnable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;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;"Hello from thread"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Functional Interfaces
&lt;/h2&gt;

&lt;p&gt;Functional interfaces are interfaces that contain only one abstract method. They can have multiple default methods. Java 8 introduced the &lt;code&gt;@FunctionalInterface&lt;/code&gt; annotation to mark functional interfaces.&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 java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@FunctionalInterface&lt;/span&gt;
&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Converter&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;F&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="no"&gt;T&lt;/span&gt; &lt;span class="nf"&gt;convert&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;F&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;Converter&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&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;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;converter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;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;valueOf&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;from&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;converted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;converter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;convert&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"123"&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="n"&gt;converted&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;    &lt;span class="c1"&gt;// 123&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Method References
&lt;/h2&gt;

&lt;p&gt;Method references provide easy-to-read lambda expressions for methods that already have a name. They're shorthand for lambdas calling only that specific method.&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 java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;...;&lt;/span&gt;
&lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;Person:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;compareByAge&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Stream API
&lt;/h2&gt;

&lt;p&gt;The Stream API is a major addition to Java 8. It allows for functional-style operations on streams of elements. A Stream represents a sequence of elements on which one or more operations can be performed.&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 java"&gt;&lt;code&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;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;asList&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Bob"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Charlie"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"David"&lt;/span&gt;&lt;span class="o"&gt;);&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;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;filteredNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;filter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;startsWith&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"C"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;collect&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Collectors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toList&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Optional Class
&lt;/h2&gt;

&lt;p&gt;The Optional class is a container object which may or may not contain a non-null value. It's a way of replacing null with a more robust solution.&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 java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;optional&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ifPresent&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;-&amp;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="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;()));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Default Methods
&lt;/h2&gt;

&lt;p&gt;Default methods enable new functionality to be added to existing interfaces without breaking older implementations of these interfaces.&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 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;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;print&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;"I am a vehicle!"&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;
  
  
  7. New Date and Time API
&lt;/h2&gt;

&lt;p&gt;Java 8 introduced a new date and time API under the package &lt;code&gt;java.time&lt;/code&gt;. This new API is more intuitive and addresses the shortcomings of the old java.util.Date and java.util.Calendar.&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 java"&gt;&lt;code&gt;&lt;span class="nc"&gt;LocalDate&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;now&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;"Current date: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. Nashorn JavaScript Engine
&lt;/h2&gt;

&lt;p&gt;Java 8 comes with a new JavaScript engine called Nashorn. It's a lightweight high-performance JavaScript runtime that runs on top of the JVM.&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 java"&gt;&lt;code&gt;&lt;span class="nc"&gt;ScriptEngineManager&lt;/span&gt; &lt;span class="n"&gt;manager&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;ScriptEngineManager&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="nc"&gt;ScriptEngine&lt;/span&gt; &lt;span class="n"&gt;engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;manager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getEngineByName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"nashorn"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;eval&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"print('Hello, Nashorn!');"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  9. Base64 Encode Decode
&lt;/h2&gt;

&lt;p&gt;Java 8 now has inbuilt encoder and decoder for Base64 encoding.&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 java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;encodedString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Base64&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getEncoder&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;encodeToString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, World!"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getBytes&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="n"&gt;encodedString&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Java 8 brought a paradigm shift in Java programming with its functional programming features and API improvements. By leveraging these features, developers can write more readable, maintainable, and efficient code. Whether you're working on a new project or maintaining legacy code, understanding and utilizing Java 8 features can significantly enhance your productivity and the quality of your software.&lt;/p&gt;

&lt;p&gt;As Java continues to evolve, mastering these features will prepare you for future advancements in the language and keep your skills sharp in the ever-changing landscape of software development.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>java</category>
    </item>
  </channel>
</rss>
