<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Prakash Karuppusamy on Medium]]></title>
        <description><![CDATA[Stories by Prakash Karuppusamy on Medium]]></description>
        <link>https://medium.com/@prakashbtech87?source=rss-d0b23dd03035------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1b9F82yscov2lRKZZ9cJ8A.jpeg</url>
            <title>Stories by Prakash Karuppusamy on Medium</title>
            <link>https://medium.com/@prakashbtech87?source=rss-d0b23dd03035------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 16:39:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prakashbtech87/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Java 25 Features Explained]]></title>
            <link>https://prakashbtech87.medium.com/java-25-features-explained-9bde8425b396?source=rss-d0b23dd03035------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bde8425b396</guid>
            <category><![CDATA[java25]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-development]]></category>
            <category><![CDATA[jdk-25]]></category>
            <dc:creator><![CDATA[Prakash Karuppusamy]]></dc:creator>
            <pubDate>Wed, 24 Dec 2025 11:51:57 GMT</pubDate>
            <atom:updated>2025-12-24T11:51:57.408Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*qOMtBwL3FHP2fdmoKkFNaw.jpeg" /></figure><h3>🌱 INTRODUCTION: WHY JAVA 25 MATTERS (READ THIS FIRST)</h3><p>Java has been around for <strong>more than 25 years</strong>.</p><p>It is trusted by banks, telecom companies, airlines, governments, and large enterprises because it is:</p><ul><li>Stable</li><li>Secure</li><li>Scalable</li></ul><p>But there was <strong>one big problem</strong>.</p><p>👉 <strong>Java was powerful, but not friendly.</strong></p><h3>❌ The Old Java Problem</h3><p><em>If you were a beginner:</em></p><ul><li>You had to write <strong>too much boilerplate</strong></li><li>You had to understand <strong>threads, synchronization, memory</strong> early</li><li>Even a simple “Hello World” looked scary</li></ul><p><em>If you were an experienced developer:</em></p><ul><li>Thread management was complex</li><li>Context passing was unsafe</li><li>Performance tuning required deep JVM knowledge</li></ul><p>So Java slowly gained a reputation of being:</p><blockquote><em>“Good for companies, but hard for humans”</em></blockquote><h3>🎯 WHAT JAVA 25 IS TRYING TO DO ?</h3><p>Java 25 is part of a <strong>long-term transformation</strong> of Java (started around Java 17–21).</p><p>The goals are very clear:</p><p>✅ Make Java <strong>easy for beginners</strong></p><p>✅ Make concurrency <strong>safe by default</strong></p><p>✅ Improve performance <strong>without changing your code</strong></p><p>✅ Reduce accidental complexity</p><p>✅ Let developers focus on <strong>business logic, not plumbing</strong></p><p>Java 25 does <strong>NOT</strong> try to be a new language.</p><p>Instead, it <strong>removes pain</strong> from existing Java.</p><p>Think of Java 25 as:</p><blockquote><em>“The same Java you trust — but finally friendly”</em></blockquote><h3>📋 JAVA 25 FEATURES EXPLAINED</h3><p>1️⃣ <strong>Compact Source Files &amp; Instance Main Methods (JEP 512)</strong></p><p>2️⃣ <strong>Flexible Constructor Bodies (JEP 508)</strong></p><p>3️⃣ <strong>Compact Object Headers (JEP 457)</strong></p><p>4️⃣ <strong>Stable Values (Preview, JEP 502)</strong></p><p>5️⃣ <strong>Scoped Values (JEP 506)</strong></p><p>6️⃣ <strong>Structured Concurrency (JEP 505)</strong></p><p>7️⃣ <strong>Pattern Matching for Primitives</strong></p><p>8️⃣ <strong>Vector API &amp; Float16 Enhancements</strong></p><p>9️⃣ <strong>AOT Method Profiling &amp; JFR Improvements</strong></p><p>🔟 <strong>Cryptography &amp; PEM Support (JEP 470)</strong></p><h3>1️⃣ Compact Source Files &amp; Instance Main Methods (JEP 512)</h3><p>Before Java 25, Java forced <strong>enterprise rules</strong> even for <strong>tiny programs</strong>.</p><p>You always needed:</p><ul><li>A public class</li><li>A public static void main</li><li>File name matching class name</li></ul><p>This made sense for large systems,</p><p>but <strong>not for learning, demos, or interviews</strong>.</p><p>Java 25 introduces <strong>Compact Source Files</strong>:</p><ul><li>No class required</li><li>No static main</li><li>Compiler understands intent automatically</li></ul><p>This makes Java feel <strong>modern and welcoming</strong>.</p><h3>🧠 Analogy</h3><p>Earlier Java:</p><blockquote><em>You must fill a </em><strong><em>full passport form</em></strong><em> just to enter a local office.</em></blockquote><p>Java 25:</p><blockquote><em>Show your </em><strong><em>ID and walk in</em></strong><em>.</em></blockquote><h3>Before Java 25</h3><pre>// PROBLEM BEFORE JAVA 25:<br>// Too much boilerplate for simple logic<br><br>public class HelloWorld {<br>    public static void main(String[] args) {<br>        System.out.println(&quot;Hello Java&quot;);<br>    }<br>}</pre><h3>After Java 25</h3><pre>// JAVA 25 POWER:<br>// No class, no static main<br>// Focus only on logic<br><br>void main() {<br>    System.out.println(&quot;Hello Java 25&quot;);<br>}</pre><h3>🎯 Use cases</h3><ol><li>Teaching Java to freshers</li><li>Writing quick demos or interview programs</li></ol><h3>2️⃣ Flexible Constructor Bodies (JEP 508)</h3><p>Constructors create objects.</p><p>Before Java 25, constructors had a <strong>dangerous limitation</strong>:</p><blockquote><em>You had to assign fields </em><strong><em>before validating inputs</em></strong></blockquote><p>This could create <strong>invalid objects temporarily</strong>, which is bad design.</p><p>Java 25 allows:</p><ul><li>Validation</li><li>Normalization</li><li>Pre-processing</li><li><strong>before</strong> assigning fields</li></ul><p>This makes object creation <strong>safe and clean</strong>.</p><h3>🧠 Analogy</h3><p>Earlier:</p><blockquote><em>Pay first → then check product</em></blockquote><p>Now:</p><blockquote><em>Check product → then pay</em></blockquote><p>Before Java 25</p><pre>class User {<br><br>    String name;<br><br>    User(String name) {<br>        // PROBLEM:<br>        // Forced assignment before validation<br>        this.name = name;<br><br>        if (name == null || name.isBlank()) {<br>            throw new IllegalArgumentException(&quot;Invalid name&quot;);<br>        }<br>    }<br><br>    public static void main(String[] args) {<br>        new User(&quot; &quot;);<br>    }<br>}</pre><p>After Java 25</p><pre>class User {<br><br>    String name;<br><br>    User(String name) {<br>        // JAVA 25 POWER:<br>        // Validation before assignment<br>        name = name.strip();<br><br>        if (name.isEmpty()) {<br>            throw new IllegalArgumentException(&quot;Name cannot be empty&quot;);<br>        }<br><br>        this.name = name;<br>    }<br><br>    public static void main(String[] args) {<br>        new User(&quot; Prakash &quot;);<br>        System.out.println(&quot;User created safely&quot;);<br>    }<br>}</pre><h3>🎯 Use cases</h3><ol><li>Domain model validation</li><li>Clean object construction</li></ol><h3>3️⃣ Compact Object Headers (JEP 457)</h3><p>Every Java object carries:</p><ul><li>Your fields</li><li>Hidden JVM metadata (object header)</li></ul><p>Earlier, headers were <strong>large</strong>, wasting memory.</p><p>Java 25 <strong>shrinks object headers internally</strong>:</p><ul><li>No code change</li><li>Less memory</li><li>Better cache usage</li></ul><p>This is a <strong>silent but powerful improvement</strong>.</p><h3>🧠 Analogy</h3><p>Earlier:</p><blockquote><em>Big labels on every parcel</em></blockquote><p>Now:</p><blockquote><em>Smaller labels → more parcels per truck</em></blockquote><h3>Before Java 25</h3><pre>// PROBLEM:<br>// Larger object headers = more memory usage<br><br>class Point {<br>    int x;<br>    int y;<br>}<br><br>void main() {<br>    Point[] points = new Point[1_000_000];<br>    for (int i = 0; i &lt; points.length; i++) {<br>        points[i] = new Point();<br>    }<br>    System.out.println(&quot;Points created&quot;);<br>}</pre><h3>After Java 25</h3><pre>// JAVA 25 POWER:<br>// Same code, less memory, better performance<br><br>class Point {<br>    int x;<br>    int y;<br>}<br><br>void main() {<br>    Point[] points = new Point[1_000_000];<br>    for (int i = 0; i &lt; points.length; i++) {<br>        points[i] = new Point();<br>    }<br>    System.out.println(&quot;Points created efficiently&quot;);<br>}</pre><h3>🎯 Use cases</h3><ol><li>High-scale systems</li><li>Memory-sensitive applications</li></ol><h3>4️⃣ Stable Values (Preview — JEP 502)</h3><blockquote><em>⚠️ </em><strong><em>Preview Feature</em></strong></blockquote><blockquote><em>Run with: — enable-preview</em></blockquote><p>Many values:</p><ul><li>Are expensive to compute</li><li>Never change after first load</li><li>Must be thread-safe</li></ul><p>Earlier, developers wrote <strong>complex synchronization code</strong>.</p><p>Stable Values provide:</p><ul><li>Lazy initialization</li><li>Thread safety</li><li>JVM optimization</li></ul><h3>🧠 Analogy</h3><blockquote><em>First person sets Wi-Fi → everyone uses it</em></blockquote><h3>Before Java 25</h3><pre>class Config {<br><br>    static String region;<br><br>    static synchronized String region() {<br>        // PROBLEM:<br>        // Manual synchronization<br>        if (region == null) {<br>            region = &quot;INDIA&quot;;<br>        }<br>        return region;<br>    }<br><br>    public static void main(String[] args) {<br>        System.out.println(region());<br>    }<br>}</pre><h3>After Java 25</h3><pre>import jdk.incubator.stablevalue.StableValue;<br><br>class Config {<br><br>    // JAVA 25 POWER:<br>    // Lazy + thread-safe + optimized<br>    static final StableValue&lt;String&gt; REGION =<br>            StableValue.of(() -&gt; &quot;INDIA&quot;);<br><br>    static String region() {<br>        return REGION.get();<br>    }<br><br>    public static void main(String[] args) {<br>        System.out.println(region());<br>    }<br>}</pre><h3>🎯 Use cases</h3><ol><li>Application configuration</li><li>Feature flags</li></ol><h3>5️⃣ SCOPED VALUES (JEP 506)</h3><p>In real-world applications (web apps, microservices), we often need to pass <strong>context data</strong> such as:</p><ul><li>Request ID</li><li>User ID</li><li>Tenant ID</li><li>Correlation ID</li></ul><p>Before Java 25, developers used <strong>ThreadLocal</strong> for this.</p><p>❌ Problems with ThreadLocal:</p><ul><li>Data can <strong>leak across requests</strong></li><li>Must be manually cleaned</li><li>Dangerous with <strong>virtual threads</strong></li><li>Hard to debug memory leaks</li></ul><p>Java 25 introduces <strong>Scoped Values</strong>:</p><ul><li>Immutable (cannot be changed)</li><li>Exists only inside a defined scope</li><li>Automatically cleaned</li><li>Safe with modern concurrency</li></ul><p>This makes context passing <strong>safe by design</strong>.</p><h3>🧠 Analogy</h3><p>Earlier:</p><blockquote><em>You borrow an office key and forget to return it.</em></blockquote><p>Now:</p><blockquote><em>You get a </em><strong><em>visitor badge</em></strong><em> that expires automatically when you leave.</em></blockquote><h3>Before Java 25</h3><pre>// PROBLEM BEFORE JAVA 25:<br>// ThreadLocal data can leak if not removed properly<br><br>class OldContext {<br><br>    static ThreadLocal&lt;String&gt; REQUEST_ID = new ThreadLocal&lt;&gt;();<br><br>    public static void main(String[] args) {<br><br>        REQUEST_ID.set(&quot;REQ-101&quot;);<br>        handleRequest();<br><br>        // If developer forgets remove(), data may leak<br>        // REQUEST_ID.remove();<br>    }<br><br>    static void handleRequest() {<br>        System.out.println(&quot;Handling request &quot; + REQUEST_ID.get());<br>    }<br>}</pre><h3>After Java 25</h3><pre>import java.lang.scopedvalue.ScopedValue;<br><br>class NewContext {<br><br>    static final ScopedValue&lt;String&gt; REQUEST_ID =<br>            ScopedValue.newInstance();<br><br>    public static void main(String[] args) {<br><br>        // JAVA 25 POWER:<br>        // Value exists only inside this scope<br>        ScopedValue.where(REQUEST_ID, &quot;REQ-101&quot;)<br>                .run(NewContext::handleRequest);<br>    }<br><br>    static void handleRequest() {<br>        System.out.println(&quot;Handling request &quot; + REQUEST_ID.get());<br>    }<br>}</pre><p><strong>Benefit:</strong></p><p>✔ No memory leaks</p><p>✔ Safe with virtual threads</p><p>✔ Automatic cleanup</p><h3>🎯 Use cases</h3><ol><li>Request tracing in microservices</li><li>Security context propagation</li></ol><h3>6️⃣ STRUCTURED CONCURRENCY (JEP 505)</h3><p>Modern applications often call <strong>multiple services in parallel</strong>:</p><ul><li>User service</li><li>Order service</li><li>Payment service</li></ul><p>Before Java 25</p><ul><li>Threads were started independently</li><li>Error handling was scattered</li><li>Cancellation was manual</li><li>Code became fragile</li></ul><p>Structured Concurrency treats <strong>multiple threads as one unit of work</strong>:</p><ul><li>If one fails → others stop</li><li>Errors propagate cleanly</li><li>Code becomes readable and safe</li></ul><h3>🧠 Analogy</h3><p>Earlier:</p><blockquote><em>Tourists roam independently</em></blockquote><p>Now:</p><blockquote><em>A tour guide manages the entire group</em></blockquote><h3>Before Java 25</h3><pre>// PROBLEM BEFORE JAVA 25:<br>// Manual thread management and error handling<br><br>class OldConcurrency {<br><br>    public static void main(String[] args) throws Exception {<br><br>        Thread t1 = new Thread(() -&gt; {<br>            System.out.println(&quot;Fetching user&quot;);<br>        });<br><br>        Thread t2 = new Thread(() -&gt; {<br>            System.out.println(&quot;Fetching orders&quot;);<br>        });<br><br>        t1.start();<br>        t2.start();<br><br>        t1.join();<br>        t2.join();<br>    }<br>}</pre><h3>After Java 25</h3><pre>import java.util.concurrent.StructuredTaskScope;<br><br>class NewConcurrency {<br><br>    public static void main(String[] args) throws Exception {<br><br>        // JAVA 25 POWER:<br>        // Threads treated as one logical task<br>        try (var scope =<br>                     new StructuredTaskScope.ShutdownOnFailure()) {<br><br>            scope.fork(() -&gt; {<br>                System.out.println(&quot;Fetching user&quot;);<br>                return null;<br>            });<br><br>            scope.fork(() -&gt; {<br>                System.out.println(&quot;Fetching orders&quot;);<br>                return null;<br>            });<br><br>            scope.join();<br>            scope.throwIfFailed();<br>        }<br>    }<br>}</pre><p><strong>Benefit:</strong></p><p>✔ Clean error handling</p><p>✔ Automatic cancellation</p><p>✔ Readable concurrency</p><h3>🎯 Use cases</h3><ol><li>API aggregation services</li><li>Parallel database or service calls</li></ol><h3>7️⃣ PATTERN MATCHING FOR PRIMITIVES</h3><p>Earlier, Java switch statements:</p><ul><li>Worked mainly with constants</li><li>Became messy with conditions</li><li>Required multiple if-else blocks</li></ul><p>Java 25 extends <strong>pattern matching to primitive types</strong>, allowing:</p><ul><li>Conditions inside switch</li><li>Cleaner and safer decision logic</li><li>Less boilerplate</li></ul><h3>🧠 Analogy</h3><p>Earlier:</p><blockquote><em>You check items one by one manually</em></blockquote><p>Now:.</p><blockquote><em>Automatic sorting machine does it cleanly</em></blockquote><h3>Before Java 25</h3><pre>// PROBLEM BEFORE JAVA 25:<br>// Too many if-else conditions<br><br>class OldPattern {<br><br>    static String check(int n) {<br>        if (n == 0) return &quot;Zero&quot;;<br>        if (n &gt; 0) return &quot;Positive&quot;;<br>        return &quot;Negative&quot;;<br>    }<br><br>    public static void main(String[] args) {<br>        System.out.println(check(-10));<br>    }<br>}</pre><h3>After Java 25</h3><pre>class NewPattern {<br><br>    static String check(int n) {<br><br>        // JAVA 25 POWER:<br>        // Pattern matching with primitives<br>        return switch (n) {<br>            case 0 -&gt; &quot;Zero&quot;;<br>            case int i when i &gt; 0 -&gt; &quot;Positive&quot;;<br>            default -&gt; &quot;Negative&quot;;<br>        };<br>    }<br><br>    void main() {<br>        System.out.println(check(-10));<br>    }<br>}</pre><h3>🎯 Use cases</h3><ol><li>Validation logic</li><li>Cleaner business rules</li></ol><h3>8️⃣ VECTOR API &amp; FLOAT16 ENHANCEMENTS</h3><p>Modern CPUs can process <strong>multiple numbers in a single instruction</strong> (SIMD).</p><p>Earlier Java:</p><ul><li>Processed numbers one-by-one</li><li>Could not fully use CPU power</li></ul><p>Java 25 improves Vector API and Float16 support:</p><ul><li>Enables bulk processing</li><li>Improves math-heavy workloads</li><li>Ideal for analytics and ML</li></ul><h3>🧠 Analogy</h3><p>Earlier:</p><blockquote><em>Calculator (one number at a time)</em></blockquote><p>Now:</p><blockquote><em>Spreadsheet (thousands at once)</em></blockquote><h3>Before Java 25</h3><pre>// PROBLEM BEFORE JAVA 25:<br>// One-by-one processing<br><br>class OldMath {<br><br>    public static void main(String[] args) {<br><br>        float[] values = {1, 2, 3, 4};<br><br>        for (int i = 0; i &lt; values.length; i++) {<br>            values[i] *= 2;<br>        }<br><br>        System.out.println(&quot;Processed normally&quot;);<br>    }<br>}</pre><h3>After Java 25</h3><pre>import jdk.incubator.vector.*;<br><br>class VectorDemo {<br><br>    static final VectorSpecies&lt;Float&gt; SPECIES =<br>            FloatVector.SPECIES_PREFERRED;<br><br>    public static void main(String[] args) {<br><br>        float[] values = {1, 2, 3, 4};<br><br>        // JAVA 25 POWER:<br>        // Multiple values processed in one CPU instruction<br>        int i = 0;<br>        for (; i &lt; SPECIES.loopBound(values.length); i += SPECIES.length()) {<br>            var v = FloatVector.fromArray(SPECIES, values, i);<br>            v.mul(2).intoArray(values, i);<br>        }<br><br>        System.out.println(&quot;Vector processing completed&quot;);<br>    }<br>}</pre><h3>🎯 Use cases</h3><ol><li>Financial calculations</li><li>Machine learning / analytics</li></ol><h3>9️⃣ AOT METHOD PROFILING &amp; JFR IMPROVEMENTS</h3><p>The JVM normally:</p><ul><li>Starts cold</li><li>Learns performance slowly</li></ul><p>Java 25 allows <strong>Ahead-Of-Time (AOT) profiling</strong>:</p><ul><li>JVM saves profiling data</li><li>Reuses it in next runs</li><li>Faster startup and stable performance</li></ul><h3>🧠 Analogy</h3><blockquote><em>Food app remembers your favorite order</em></blockquote><h3>Before Java 25</h3><ul><li>Cold startup every time</li><li>Slower warm-up</li></ul><h3>After Java 25</h3><pre># JAVA 25 POWER:<br># JVM reuses profiling data for faster startup<br><br>java -XX:+UnlockExperimentalVMOptions \<br>     -XX:+UseAOTProfiling \<br>     -jar app.jar</pre><h3>🎯 Use cases</h3><ol><li>Faster microservice startup</li><li>Production performance tuning</li></ol><h3>🔟 CRYPTOGRAPHY &amp; PEM SUPPORT (JEP 470)</h3><p>PEM is the <strong>standard format</strong> for:</p><ul><li>Private keys</li><li>Certificates</li><li>TLS configuration</li></ul><p>Before Java 25:</p><ul><li>Manual parsing</li><li>External libraries</li><li>Error-prone code</li></ul><p>Java 25 adds <strong>native PEM support</strong>, making security code:</p><ul><li>Simpler</li><li>Safer</li><li>More standard-compliant</li></ul><h3>🧠 Analogy</h3><p>Earlier:</p><blockquote><em>Everyone used different locks</em></blockquote><p>Now:</p><blockquote><em>One standard lock for all</em></blockquote><h3>Before Java 25</h3><ul><li>Custom parsing</li><li>Third-party dependencies</li></ul><h3>After Java 25</h3><pre>// JAVA 25 POWER:<br>// Native support for PEM encoding/decoding<br><br>Pem.encodePrivateKey(privateKey, outputStream);<br>Pem.encodeCertificate(certificate, outputStream);</pre><h3>🎯 Use cases</h3><ol><li>TLS configuration in microservices</li><li>Certificate management in DevOps</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bde8425b396" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prompting Techniques: A Simple Guide for Beginners]]></title>
            <link>https://prakashbtech87.medium.com/prompting-techniques-a-simple-guide-for-beginners-48192cd22891?source=rss-d0b23dd03035------2</link>
            <guid isPermaLink="false">https://medium.com/p/48192cd22891</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[prompt-techniques]]></category>
            <category><![CDATA[prompt-engineering]]></category>
            <dc:creator><![CDATA[Prakash Karuppusamy]]></dc:creator>
            <pubDate>Fri, 19 Dec 2025 14:26:14 GMT</pubDate>
            <atom:updated>2025-12-19T14:26:14.727Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G2TL6E_365wB5YkM5B-acg.png" /></figure><p><em>Clear definitions and simple examples for beginners</em></p><p>AI models have become powerful tools, but the real skill lies in how we communicate with them. Good prompting isn’t about magic words. It’s about clarity, structure, and teaching the model what you want.</p><p>This guide explains the most important prompting techniques in simple terms, with three examples for each. Anyone new to AI should be able to read this and immediately feel confident trying them.</p><h3>1. Zero‑Shot Prompting</h3><p><strong>Definition:</strong><br> Asking the model to do a task without giving any examples. You rely solely on clear instructions.</p><p><strong>Examples:</strong></p><ol><li>“Explain cloud computing in simple terms.”</li><li>“Write a summary of this email in two lines.”</li><li>“List the main differences between 4G and 5G.”</li></ol><h3>2. Few‑Shot Prompting</h3><p><strong>Definition:</strong><br> You show a few examples so the model understands the pattern before answering your request.</p><p><strong>Examples:</strong><br> 1. Example: “hi → Hello!”<br> Example: “thanks → You’re welcome!”<br> Now respond to: “good morning”</p><p>2. Example: “Rewrite polite: send me details → Please share the details.”<br> Rewrite: “give me update.”</p><p>3.Example: “1 + 1 = 2”<br> Example: “2 + 2 = 4”<br> Solve: “3 + 5 = ?”</p><h3>3. Meta Prompting</h3><p><strong>Definition:</strong><br> You tell the model <em>how</em> to think or approach the problem, not just what to output.</p><p><strong>Examples:</strong></p><ol><li>“Think like a teacher and break the explanation into steps.”</li><li>“Act like a reviewer. Check my answer and highlight mistakes.”</li><li>“Explain your reasoning before giving the final answer.”</li></ol><h3>4. Self‑Consistency Prompting</h3><p><strong>Definition:</strong><br> Ask the model to produce multiple reasoning paths and then choose the most reliable answer.</p><p><strong>Examples:</strong></p><ol><li>“Give three different ways to solve this and pick the best final answer.”</li><li>“Think through the problem with multiple approaches and choose the most logical one.”</li><li>“Generate several solutions and explain why one is better.”</li></ol><h3>5. General Knowledge Prompting</h3><p><strong>Definition:</strong><br> Ask the model to use basic facts or real‑world understanding to improve accuracy.</p><p><strong>Examples:</strong></p><ol><li>“Using your general knowledge of telecom networks, explain how roaming works.”</li><li>“Based on common cybersecurity practices, describe how data breaches occur.”</li><li>“Explain how GPS works using everyday knowledge.”</li></ol><h3>6. Prompt Chaining</h3><p><strong>Definition:</strong><br> Breaking a large task into smaller, connected prompts. This improves clarity and quality.</p><p><strong>Examples:</strong></p><ol><li>“Step 1: Summarize the document. Step 2: Turn it into bullet points. Step 3: Create a presentation draft.”</li><li>“First explain the concept. Then give examples. Then write a short FAQ.”</li><li>“Outline the problem first. Then propose solutions. Then choose the best one.”</li></ol><h3>7. Tree of Thoughts</h3><p><strong>Definition:</strong><br> The model explores multiple reasoning branches, like exploring options in a decision tree.</p><p><strong>Examples:</strong></p><ol><li>“Give three different paths to solve this and show the pros and cons.”</li><li>“Think through the problem using different possible approaches before deciding.”</li><li>“Explore multiple solution branches and explain which leads to the best outcome.”</li></ol><h3>8. Retrieval-Augmented Generation (RAG)</h3><p><strong>Definition:</strong><br> The model retrieves information from external sources or documents before generating an answer. This improves correctness.</p><p><strong>Examples:</strong></p><ol><li>“Using the attached PDF, summarize the findings.”</li><li>“Based on the two documents provided, compare the security issues.”</li><li>“Search the knowledge base and answer this question accurately.”</li></ol><h3>9. Automatic Reasoning and Tool Use</h3><p><strong>Definition:</strong><br> The model decides which tools (like search, calculator, code, or data analysis) to use to solve a task.</p><p><strong>Examples:</strong></p><ol><li>“Calculate the growth trend from this dataset and provide a chart.”</li><li>“Find the fastest route time and present a comparison table.”</li><li>“Analyze this CSV file and highlight anomalies.”</li></ol><h3>10. Automatic Prompt Engineer (APE)</h3><p><strong>Definition:</strong><br> You ask the model to rewrite or optimize your prompt so it becomes more effective.</p><p><strong>Examples:</strong></p><ol><li>“Rewrite my prompt to make it clearer and stronger.”</li><li>“Improve this prompt to get more accurate answers.”</li><li>“Optimize this prompt for creativity and detail.”</li></ol><h3>11. Active‑Prompt</h3><p><strong>Definition:</strong><br> The model creates multiple prompt variations, tests them, and selects the highest‑quality prompt.</p><p><strong>Examples:</strong></p><ol><li>“Generate three versions of this prompt and pick the one that produces the best result.”</li><li>“Create variations of my prompt and identify the most accurate one.”</li><li>“Give alternate prompts and choose the one that works best for reasoning tasks.”</li></ol><h3>12. Directional Stimulus Prompting</h3><p><strong>Definition:</strong><br> You guide the model’s thinking by giving hints or cues that steer the answer in a certain direction.</p><p><strong>Examples:</strong></p><ol><li>“While comparing cloud providers, focus on cost, speed, and security.”</li><li>“Explain the solution with emphasis on performance and scalability.”</li><li>“Describe the problem considering reliability and user impact.”</li></ol><h3>Closing Thoughts</h3><p>Good prompting isn’t complicated — it’s intentional. When you understand these techniques and apply them thoughtfully, you get clearer, more reliable, and more useful output from any AI model.</p><p>For beginners, start with Zero‑shot and Few‑shot. As you grow more comfortable, try Prompt Chaining, Meta prompting, and Tree of Thoughts. Advanced users can explore RAG, Active-Prompt, and Automatic Prompt Engineering.</p><p>With consistent practice, prompting becomes less of a technique and more of a mindset: think clearly, guide the model well, and always refine the output :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48192cd22891" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RAG Explained: Why AI Needs to Take an “Open-Book” Test :)]]></title>
            <link>https://prakashbtech87.medium.com/rag-explained-why-ai-needs-to-take-an-open-book-test-3de7340c972e?source=rss-d0b23dd03035------2</link>
            <guid isPermaLink="false">https://medium.com/p/3de7340c972e</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <dc:creator><![CDATA[Prakash Karuppusamy]]></dc:creator>
            <pubDate>Fri, 12 Dec 2025 16:39:35 GMT</pubDate>
            <atom:updated>2025-12-12T16:39:35.889Z</atom:updated>
            <content:encoded><![CDATA[<h3>RAG Explained: Why AI Needs to Take an “Open-Book” Test :)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jfVvkYe9DTqmNMfS6wplEg.jpeg" /></figure><p>Everyone is talking about Generative AI, but there is a major problem with standard Large Language Models (LLMs) like ChatGPT or Gemini: <strong>They can hallucinate, and their knowledge is frozen in time.</strong></p><p>If you ask a standard AI model about news that happened this morning, or about your private company data, it will either guess (hallucinate) or tell you it doesn’t know.</p><p>This is where <strong>RAG (Retrieval-Augmented Generation)</strong> changes the game.</p><p>The Simple Analogy: The Exam</p><p>Imagine you are taking a very difficult exam on “World History.”</p><ul><li><strong>Standard AI (LLM):</strong> This is a student taking the test <strong>from memory</strong>. They are brilliant and have read every book in the library, but they last visited the library in 2023. If the test asks about an event from 2024, they will fail or make something up.</li><li><strong>RAG:</strong> This is a student taking an <strong>Open-Book Exam</strong>. They have the same brain, but they are allowed to use a textbook to look up the specific answer before writing it down.</li></ul><p><strong>RAG is simply giving the AI an open textbook (your data) to look at before it answers.</strong></p><h3>How It Works (The 3 Steps)</h3><p>The name “Retrieval-Augmented Generation” sounds complex, but it describes the three steps the system takes:</p><ol><li><strong>Retrieval (The Search):</strong> When you ask a question, the system doesn’t go straight to the AI. First, it searches through your specific database (like your company PDFs, recent news, or website data) to find paragraphs relevant to your question.</li><li><strong>Augmented (The Context):</strong> The system takes your question and “augments” it (adds to it) by stapling the information it found in step 1.</li></ol><ul><li><em>Original Prompt:</em> “What is the company vacation policy?”</li><li><em>Augmented Prompt:</em> “Using the attached HR Handbook PDF, answer the user’s question: What is the company vacation policy?”</li></ul><p><strong>3. Generation (The Answer):</strong> The LLM now receives the question <em>plus</em> the answer key. It uses its language skills to generate a grammatically correct, human-like answer based <em>only</em> on the facts provided.</p><h3>A Real-World Example</h3><p>Let’s say you are building a chatbot for a fictional company, <strong>“TechCorp.”</strong></p><p><strong>The User asks:</strong> <em>“Does TechCorp cover dental insurance?”</em></p><h4>Without RAG:</h4><p>The AI relies on its general training data. It might say:</p><blockquote>“Most tech companies offer dental insurance, but I don’t know about TechCorp specifically.”<em> (This is useless to the user).</em></blockquote><h4>With RAG:</h4><ol><li><strong>Retrieve:</strong> The system searches the “TechCorp Employee Benefits PDF” and finds the phrase: <em>All full-time employees are eligible for Delta Dental coverage.</em></li><li><strong>Augment:</strong> It sends the AI: <em>“Context: All full-time employees are eligible for Delta Dental coverage. Question: Does TechCorp cover dental insurance?”</em></li><li><strong>Generate:</strong> The AI answers:</li></ol><blockquote>“Yes, TechCorp offers dental insurance through Delta Dental for all full-time employees.”</blockquote><h3>Why RAG Wins</h3><ol><li><strong>Accuracy:</strong> It drastically reduces hallucinations because the AI is grounded in facts you provide.</li><li><strong>Up-to-Date:</strong> You don’t need to retrain the AI model (which costs millions) to learn new info. You just update the document it “reads” from.</li><li><strong>Data Privacy:</strong> You can keep your data secure in your database and only send small snippets to the LLM for processing.</li></ol><h3>Summary</h3><p>RAG bridges the gap between the AI’s <strong>reasoning capabilities</strong> and your <strong>proprietary data</strong>. It turns the AI from a creative writer into a factual analyst.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3de7340c972e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NotebookLM by Google]]></title>
            <link>https://prakashbtech87.medium.com/notebooklm-by-google-0ce46a9c2bc7?source=rss-d0b23dd03035------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ce46a9c2bc7</guid>
            <category><![CDATA[notebooklm]]></category>
            <category><![CDATA[google-notebooklm]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Prakash Karuppusamy]]></dc:creator>
            <pubDate>Sat, 06 Dec 2025 03:24:37 GMT</pubDate>
            <atom:updated>2025-12-06T03:24:37.763Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*qsE8_5-MUBBX5CXynOL_FA.jpeg" /></figure><p><strong>NotebookLM</strong> is Google’s AI-powered research and writing assistant.</p><p>Think of it like a <strong>smart notebook</strong> that understands your documents and helps you learn, summarize, and create content from them.</p><p>You upload anything — PDFs, notes, links, articles — and NotebookLM:</p><ul><li><strong>Reads everything for you</strong></li><li><strong>Explains concepts in simple terms</strong></li><li><strong>Creates summaries, notes, and study guides</strong></li><li><strong>Answers questions from your documents</strong></li><li><strong>Helps you write articles, blogs, and ideas based on your content</strong></li></ul><p>Demo:</p><ol><li>Go to <a href="https://notebooklm.google/">https://notebooklm.google/</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p3DMmi5-tmY53X2KOOzgqQ.png" /></figure><p>2 . Click Try NotbookLM</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*9bsbgCJkwXAMS85oWDyVZQ.png" /></figure><p>3. We can now see available Notebooks as follows</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ejug0ERzGAAt8VBXIgbhFw.png" /></figure><p>4. Click on Create new notebook</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*C_Gh92n-TwzG06QszFuD7g.png" /></figure><p>5. Now it will ask for sources</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NQT7BL8icJGNy1DhRqkP7Q.png" /></figure><p>6. Lets try the Link feature</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*KH0VnlHBDr_4di0PiKt0bA.png" /></figure><p>7. Lets try to invoke <a href="http://www.codingbat.com/">http://www.codingbat.com/</a> link and understand what it does</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eAd_0t9bK6lxu5DEDd-UWQ.png" /></figure><p>8. Now click insert button. The moment we click insert, it will read the website and provide summary for us to save our time.</p><p>Here any valid web link we can provide here and get the info about it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wL67fHqddJkE3pD2cWBjfw.png" /></figure><p>9. We can also ask question about this website</p><p>Question : What is the purpose of Website and what one can gain from this website. Explain in less then 300 characters and for that we get the answers based on the prompt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*F1uK_-vBgOsZqVnlS0xs7A.png" /></figure><p>10. Similarly we can upload any file and ask question against that document.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ce46a9c2bc7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TOON ( Token Oriented Object Notation )]]></title>
            <link>https://prakashbtech87.medium.com/toon-token-oriented-object-notation-4113c2e7d8df?source=rss-d0b23dd03035------2</link>
            <guid isPermaLink="false">https://medium.com/p/4113c2e7d8df</guid>
            <category><![CDATA[json]]></category>
            <category><![CDATA[toon]]></category>
            <category><![CDATA[token]]></category>
            <dc:creator><![CDATA[Prakash Karuppusamy]]></dc:creator>
            <pubDate>Fri, 28 Nov 2025 16:30:04 GMT</pubDate>
            <atom:updated>2025-11-28T16:48:38.141Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3QN1eBq9IDCnMD6jygsQGg.png" /></figure><p>This is a file type and helpful to talk to AI</p><p>Prompting techniques for AI are evolving rapidly, with new methods emerging almost weekly. We are going to dive deep into a powerful new file type and prompting technique called <strong>TOON (Token Oriented Object Notation)</strong>.If you plan to talk to Generative AI (GenAI), mastering the TOON technique is highly recommended. This file type creates an object notation that is specific to tokens</p><p>To understand why TOON is so useful, we must look at how prompting has evolved.</p><p><strong>The Evolution of AI Prompting Techniques</strong></p><p>AI maintenance is becoming very costly for startups and developers due to increasing token usage. Because of this, developers have continuously worked to reduce tokens and increase accuracy.</p><p><strong>1. Plain Text Prompting (The Old Way)</strong></p><p>Just a couple of years ago, we wrote prompts in plain text. This involved giving the AI detailed instructions, including a Role, Task, Context, Example, and Report (like the RTCER formula).</p><p>• <strong>Cost:</strong> Very expensive. A detailed prompt could easily reach up to <strong>1000 tokens</strong>.</p><p>• <strong>Accuracy:</strong> Low, typically only <strong>40% to 50%</strong>. To get the right output, often multiple iterations were needed.</p><p><strong>2. JSON Prompting (A Better Way)</strong></p><p>JSON (JavaScript Object Notation) was developed to improve cost and accuracy. It uses the same core formula as plain text but condenses the information into a concise file type. JSON formats data using <strong>key-value pairs</strong> enclosed in open curly braces. For example, the key might be “Role,” and the value might be “You are an expert in X”.</p><p>• <strong>Accuracy:</strong> Much higher, <strong>over 70%</strong>.</p><p>• <strong>Token Usage:</strong> Reduced. If plain text used 1000 tokens, JSON might use around <strong>700 tokens</strong>. However, token usage was still considered high.</p><p><strong>3. POML (Prompt Object Markup Language)</strong></p><p>POML, often using XML tags, was another technique that emerged. Developed by Microsoft, it used tags like &lt;role&gt; to define parameters.</p><p>• <strong>Token Usage:</strong> Further reduced (e.g., around <strong>600 tokens</strong>).</p><p>• <strong>Accuracy:</strong> Around <strong>70% to 75%</strong>.</p><ul><li><strong>Challenge:</strong> It tended to lead to confusion and <strong>hallucination</strong> when dealing with complex data inside the XML tags</li></ul><p>Introducing TOON: The New Best Technique</p><p>After POML, the latest technique is <strong>TOON (Token Oriented Object Notation)</strong>. The most critical aspect of TOON is its ability to reduce tokens.</p><p>When both input and output tokens are reduced, it helps save costs.</p><p><strong>Key Benefits of TOON</strong></p><p>1. <strong>Massive Token Reduction:</strong> TOON uses <strong>30% to 60% fewer tokens compared to JSON</strong>. If JSON uses 700 tokens, TOON might use only <strong>300 to 500 tokens</strong>.</p><p>2. <strong>Optimized for LLMs:</strong> TOON is specifically designed to be comprehensible and optimized for Large Language Models (LLMs).</p><p>3. <strong>High Accuracy:</strong> TOON is highly accurate, generally estimated to be around <strong>75% to 80%</strong>. One comparison suggested TOON reached close to <strong>74%</strong> accuracy, slightly higher than JSON’s 70%.</p><p>4. <strong>Human Readable:</strong> It is a human-readable data serialization format that is very clean and easy to understand and debug.</p><p><strong>How TOON Saves Tokens (The Structure)</strong></p><p>Unlike JSON, which relies on repeating curly braces and keys for every entry, TOON is <strong>indentation-based</strong> and uses white spaces (similar to YAML). TOON allows you to declare the keys once and then stream all the subsequent values.</p><p>A Practical Example (JSON vs. TOON)</p><p>Consider defining data for a list of users (ID, Name, Role).</p><p><strong>1. JSON Structure:</strong> In a sample data set defining two users, the JSON structure required <strong>51 tokens</strong>. The keys (ID, Name, Role) are repeated within the curly braces for each user.</p><p><strong>2. TOON Structure:</strong> TOON lists the keys (ID, Name, Role) first. Then, you simply list the values one after the other for each user (e.g., “1 Prakash Engineer,” “2 Ram DBA”). There are no open curly braces required.</p><p>• Using the same user data set, the TOON conversion resulted in only <strong>24 tokens</strong>, achieving a <strong>50% reduction</strong> in token usage. One source noted a <strong>53% reduction</strong>. A reduction of 35% was noted in a real-world salary example.</p><p><strong>Implementation</strong></p><p>Because of its advantages, TOON is expected to rule the field.</p><p>While many GenAI models can already provide output in the TOON format, developers can also convert existing data (like JSON) into TOON within their Python scripts using the <strong>pydoonformat</strong> package.</p><p><strong>Conclusion:</strong></p><p>TOON is currently the <strong>best method of prompting</strong>. It is very fast, reduces tokens in both input and output, and helps save costs, all while maintaining high accuracy.</p><p>Example 1:</p><p>Below is the TOON format for creating High Quality Image</p><pre>masterpiece, best quality, ultra-detailed, absurdres, 8k, intricate details, cinematic lighting, depth of field, sharp focus, <br>[subject: 1girl/1boy/etc], [character description: age appearance, beautiful detailed face, large expressive eyes, long flowing hair, etc], [hair color/style: silver hair, twintails with ribbons, etc], [eye color: heterochromia, glowing emerald eyes, etc], <br>[outfit: highly detailed magical girl outfit, frilly dress, thighhighs, garterbelt, etc], [pose/action: dynamic fighting pose, floating in air, gentle smile, looking at viewer, etc], <br>[expression: blushing, confident smirk, teary-eyed, etc], <br>[background: vibrant cyberpunk city night, blooming cherry blossom garden, starry galaxy sky, detailed fantasy castle interior, etc], <br>[art style: anime key visual, studio trigger style, detailed anime shading, illya-style, makoto shinkai background, etc], <br>[additional effects: sparkling particles, lens flare, god rays, bokeh, glowing runes, etc], <br>&lt;negative prompt if needed: lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry&gt;</pre><p>Lets use the above prompt in Google Nano Banana</p><p>It took just 12 sec to generate the high quality image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yXM6dNqaFPaxnEJmZPZIfA.png" /></figure><p>Few more examples:</p><p>Example 2</p><p>Toon Format:</p><pre>person<br>    name &quot;Prakash&quot;<br>    age 30<br>    skills<br>        &quot;Java&quot;<br>        &quot;Spring Boot&quot;<br>        &quot;Microservices&quot;</pre><p>Json Format:</p><pre>{<br>  &quot;person&quot;: {<br>    &quot;name&quot;: &quot;Prakash&quot;,<br>    &quot;age&quot;: 30,<br>    &quot;skills&quot;: [<br>      &quot;Java&quot;,<br>      &quot;Spring Boot&quot;,<br>      &quot;Microservices&quot;<br>    ]<br>  }<br>}</pre><p>Example 3:</p><p>JSON format</p><pre>{<br>  &quot;users&quot;: [<br>    {&quot;id&quot;: 1, &quot;name&quot;: &quot;Alice&quot;, &quot;role&quot;: &quot;admin&quot;},<br>    {&quot;id&quot;: 2, &quot;name&quot;: &quot;Bob&quot;, &quot;role&quot;: &quot;user&quot;}<br>  ]<br>}</pre><p>TOON format</p><pre>users[2]{id,name,role}:<br>  1,Alice,admin<br>  2,Bob,user</pre><p>Sources : <a href="https://github.com/meetrais/JSON-to-TOON">https://github.com/meetrais/JSON-to-TOON</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4113c2e7d8df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Antigravity Demo to start with :)]]></title>
            <link>https://prakashbtech87.medium.com/google-antigravity-demo-to-start-with-16bc4db7f3cf?source=rss-d0b23dd03035------2</link>
            <guid isPermaLink="false">https://medium.com/p/16bc4db7f3cf</guid>
            <category><![CDATA[google]]></category>
            <category><![CDATA[gemini-3-pro]]></category>
            <category><![CDATA[antigravity]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Prakash Karuppusamy]]></dc:creator>
            <pubDate>Wed, 19 Nov 2025 18:22:03 GMT</pubDate>
            <atom:updated>2025-11-19T18:22:03.221Z</atom:updated>
            <content:encoded><![CDATA[<h3>Google Antigravity- Demo to start with :)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I4mphyHV86KEFdamKk7kng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*96IZAQS7pNnOGrpg2-CsLw.png" /></figure><p>Step 1 :Download using <a href="https://antigravity.google/download">https://antigravity.google/download</a></p><p>Step 2: Choose the OS based on the requirement</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XCCF8db8Fhi4QrLzz-YvNw.png" /></figure><p>Step 3: Install</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*Wu17M_P0VxyKRC43LPuUFw.png" /></figure><p>Step 4:</p><p>Open and choose Google account</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vQ19_i7KM-99eQLOa9E26w.png" /></figure><p>Step 5:</p><p>Click Open Folder and create a folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BygU3GWS09WQx4Mgn1g0gA.png" /></figure><p>Step 6:</p><p>Trust the project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*04joo3RxT2vKOm0oYcLHhw.png" /></figure><p>Step 7</p><p>Give requirement as “Create a very good landing page for GEN AI topics leraning site”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oSexcFkMpeyZ4Xc8MiwlSA.png" /></figure><p>Step 8 :</p><p>Choose as Planning mode</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BKLE9HIXswtL1Zsc1zXuQg.png" /></figure><p>Step 9:</p><p>Cick proceed and the necessary files and structure will be created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a10IintsbzZD--DF8tpODQ.png" /></figure><p>Step 10<br>Install Antigravity extension</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z0Q3pNqQX9fs2LP_dJ6vkg.png" /></figure><p>Step 11:</p><p>The website is ready</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LuZZY1nBOqzbpWG4zeX-fw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-0ry1rIw--WOehqvHPBNIA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SnfQiKscKvjWvL7NpiaCkQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fgB48JDZr7cx-d1UvHdmRw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16bc4db7f3cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java 24 Feature — Virtual Threads]]></title>
            <link>https://prakashbtech87.medium.com/java-24-feature-virtual-threads-7ac4f638e8c8?source=rss-d0b23dd03035------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ac4f638e8c8</guid>
            <category><![CDATA[java24]]></category>
            <category><![CDATA[java-virtual-threads]]></category>
            <category><![CDATA[virtual-threads]]></category>
            <dc:creator><![CDATA[Prakash Karuppusamy]]></dc:creator>
            <pubDate>Sun, 03 Aug 2025 07:56:05 GMT</pubDate>
            <atom:updated>2025-08-03T07:56:05.512Z</atom:updated>
            <content:encoded><![CDATA[<h3>Java 24 Feature — Virtual Threads</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NsN7pAVsxCYOgz2o-UlxCQ.png" /></figure><h3>What is Virtual Thread ?</h3><p>Virtual Threads are a new type of lightweight thread introduced in <strong>Java 21 (as preview)</strong> and finalized in <strong>Java 24</strong>. Unlike traditional <strong>Platform Threads</strong> (which are tied directly to OS threads and are heavyweight), Virtual Threads are <strong>managed by the Java Virtual Machine (JVM)</strong> — not the operating system.</p><h3>Highlights</h3><ul><li><strong>You can create thousands of virtual threads</strong> without crashing your system.</li><li>Perfect for apps that wait a lot (like API calls, DB queries).</li><li>Helps you write <strong>simple blocking code</strong> without performance loss.</li><li>They use <strong>very little memory</strong> and <strong>start fast</strong> — ideal for microservices and concurrent apps.</li></ul><h4>GitHub Link <a href="https://github.com/prakashbtech87/PrakashJavaRepository/tree/main/src/main/java/com/prakash/version/java24/threads">https://github.com/prakashbtech87/PrakashJavaRepository/tree/main/src/main/java/com/prakash/version/java24/threads</a></h4><h3>Demo Goal</h3><p>We’re going to:</p><ol><li>Run 10,000 threads using <strong>platform threads</strong> (the old way)</li><li>Run 10,000 tasks using <strong>virtual threads</strong> (Java 24 way)</li><li>Measure time taken by each</li><li>Compare performance</li></ol><h3>PlatformThreadDemo</h3><p><strong>Role:</strong> Creates <strong>10,000 traditional threads</strong>.</p><pre>package com.prakash.version.java24.threads;<br><br>/**<br> * Demonstrates traditional platform threads (pre-Java 24)<br> * Creates 10,000 platform threads, each printing a message<br> */<br>public class PlatformThreadDemo {<br>    <br>    private static final int THREAD_COUNT = 10_000;<br>    <br>    public void runDemo() {<br>        long startTime = System.currentTimeMillis();<br>        <br>        for (int i = 1; i &lt;= THREAD_COUNT; i++) {<br>            final int threadNum = i;<br>            Thread thread = new Thread(() -&gt; {<br>                System.out.println(&quot;Platform Thread &quot; + threadNum + &quot;: Hello from &quot; + Thread.currentThread());<br>            });<br>            thread.start();<br>            <br>            // Add a small delay to prevent overwhelming the system<br>            try {<br>                Thread.sleep(1);<br>            } catch (InterruptedException e) {<br>                Thread.currentThread().interrupt();<br>                break;<br>            }<br>        }<br>        <br>        long endTime = System.currentTimeMillis();<br>        System.out.println(&quot;\nPlatform Threads Demo completed in &quot; + (endTime - startTime) + &quot; ms&quot;);<br>    }<br>}</pre><h3>VirtualThreadDemo</h3><p><strong>Role:</strong> Creates <strong>10,000 lightweight virtual threads</strong> (using Java 24 style)</p><pre>package com.prakash.version.java24.threads;<br><br>import java.util.concurrent.TimeUnit;<br><br>/**<br> * Demonstrates true virtual threads (JDK 25) using {@code Thread.startVirtualThread()}.<br> * Creates 10,000 virtual-thread tasks, each printing a message.<br> */<br>public class VirtualThreadDemo {<br>    <br>    private static final int THREAD_COUNT = 10_000;<br>    <br>    public void runDemo() {<br>        long startTime = System.currentTimeMillis();<br><br>        for (int i = 1; i &lt;= THREAD_COUNT; i++) {<br>            int threadNum = i;<br>            Thread.startVirtualThread(() -&gt;<br>                    System.out.println(&quot;Virtual Thread &quot; + threadNum + &quot;: Hello from &quot; + Thread.currentThread())<br>            );//<br>        }<br><br>        long endTime = System.currentTimeMillis();<br>        System.out.println(&quot;\nVirtual Threads demo completed in &quot; + (endTime - startTime) + &quot; ms&quot;);<br>    }<br>}</pre><h3>✅ Class:</h3><h3>ThreadComparisonDemo</h3><p><strong>Role:</strong> Acts as the <strong>controller</strong> for running and timing both demos.</p><pre>package com.prakash.version.java24.threads;<br><br>/**<br> * Compares performance between platform threads and virtual threads<br> */<br>public class ThreadComparisonDemo {<br>    <br>    public static void main(String[] args) {<br>        System.out.println(&quot;=== Starting Thread Performance Comparison ===\n&quot;);<br>        <br>        try {<br>            // Run Platform Thread Demo<br>            System.out.println(&quot;🚀 Starting Platform Threads Demo...&quot;);<br>            PlatformThreadDemo platformDemo = new PlatformThreadDemo();<br>            long platformStart = System.currentTimeMillis();<br>            platformDemo.runDemo();<br>            long platformEnd = System.currentTimeMillis();<br>            long platformDuration = platformEnd - platformStart;<br>            <br>            // Add a small delay between demos<br>            Thread.sleep(2000);<br>            <br>            // Run Virtual Thread Demo<br>            System.out.println(&quot;\n🚀 Starting Virtual Threads Demo...&quot;);<br>            VirtualThreadDemo virtualDemo = new VirtualThreadDemo();<br>            long virtualStart = System.currentTimeMillis();<br>            virtualDemo.runDemo();<br>            long virtualEnd = System.currentTimeMillis();<br>            long virtualDuration = virtualEnd - virtualStart;<br>            <br>            // Print comparison results<br>            System.out.println(&quot;\n=== Performance Comparison Results ===&quot;);<br>            System.out.printf(&quot;Platform Threads: %d ms%n&quot;, platformDuration);<br>            System.out.printf(&quot;Virtual Threads:  %d ms%n&quot;, virtualDuration);<br>            if (virtualDuration &gt; 0) {<br>                System.out.printf(&quot;Improvement:      %.2fx faster%n&quot;, <br>                               (double)platformDuration / virtualDuration);<br>            } else {<br>                System.out.println(&quot;Virtual threads completed too quickly to measure improvement&quot;);<br>            }<br>        } catch (InterruptedException e) {<br>            Thread.currentThread().interrupt();<br>            System.err.println(&quot;Thread comparison was interrupted&quot;);<br>        } catch (Exception e) {<br>            System.err.println(&quot;An error occurred during thread comparison: &quot; + e.getMessage());<br>            e.printStackTrace();<br>        }<br>    }<br>}</pre><pre>Output: <br><br>Lightweight Tasks Demo completed in 1103 ms<br><br>=== Performance Comparison Results ===<br>Platform Threads: 13457 ms<br>Virtual Threads:  162 ms<br>Improvement:      83.07x faster</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WsoCHawsinw4p-CnAN8cPg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2rC1goy6pA36xRfNILsePw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ac4f638e8c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PrakashAI — Spring AI with Ollama and Microsoft Phi-3]]></title>
            <link>https://prakashbtech87.medium.com/prakashai-spring-ai-with-ollama-and-microsoft-phi-3-1f5b1a31de47?source=rss-d0b23dd03035------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f5b1a31de47</guid>
            <category><![CDATA[spring-ai]]></category>
            <category><![CDATA[phi-3]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Prakash Karuppusamy]]></dc:creator>
            <pubDate>Sun, 13 Jul 2025 15:53:10 GMT</pubDate>
            <atom:updated>2025-07-13T15:53:10.214Z</atom:updated>
            <content:encoded><![CDATA[<h3>PrakashAI — Spring AI with Ollama and Microsoft Phi-3</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nONgUQ4cfYMMfj4ljdiw8Q.png" /></figure><p>Here i try to explore AI feature using Sprinboot.</p><h4><strong><em>Step 1 :</em></strong> Install Ollama</h4><p>Refer this blog for installing the same <a href="https://medium.com/@prakashbtech87/prakash-with-ollama-mistral-50b5456ab4a2">https://medium.com/@prakashbtech87/prakash-with-ollama-mistral-50b5456ab4a2</a></p><h4>Step 2: Create Springboot Project</h4><p>I am using IntelliJ Idea and create new project using below option</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eV1832kNMda9McMmnrr9sQ.png" /></figure><h4>Step 3: Refer the code for this usecase in below github</h4><p>GitHub Repo :<a href="https://github.com/prakashbtech87/springboot-ai-demo">https://github.com/prakashbtech87/springboot-ai-demo</a></p><h4>Step 4: Create RestController named HelloController</h4><p>ChatClient used to talk to AI via code.</p><p>This Spring Boot controller class is a simple REST API implementation that integrates with <strong>Spring AI</strong> to communicate with an AI model. The class is annotated with @RestController, making it a web controller where each method returns data (rather than rendering a view). It exposes a single endpoint /hello, which is mapped using the @GetMapping annotation.</p><p>The controller depends on a ChatClient, which is a Spring AI component used to interact with an AI model such as OpenAI, Azure OpenAI, or Ollama. This dependency is injected via constructor injection, following best practices in Spring to enable loose coupling and better testability.</p><p>Inside the hello() method, a prompt message is defined as a string: “Myself Prakash Karuppusamy and exploring Spring AI”. This message is wrapped into a PromptTemplate — a utility class that helps in structuring and formatting prompts to be sent to the AI. Once the prompt is created using the create() method, the controller calls the AI model by invoking chatClient.call() with the generated prompt content.</p><p>The AI response returned from this method is a plain text message generated by the AI based on the input prompt. This response is directly returned to the client as the output of the /hello API call.</p><p>In summary, this code sets up a basic integration of Spring Boot with Spring AI to send a fixed message to an AI model and return its response, demonstrating how easily developers can build intelligent applications using Spring AI components.</p><pre>package com.prakash.ai;<br><br>import org.springframework.ai.chat.ChatClient;<br>import org.springframework.ai.chat.prompt.Prompt;<br>import org.springframework.ai.chat.prompt.PromptTemplate;<br>import org.springframework.web.bind.annotation.GetMapping;<br>import org.springframework.web.bind.annotation.RestController;<br><br>/**<br> * @author prakashkaruppusamy<br> */<br>@RestController<br>public class HelloController {<br><br>    private final ChatClient chatClient;<br><br>    public HelloController(ChatClient chatClient) {<br>        this.chatClient = chatClient;<br>    }<br><br>    @GetMapping(&quot;/hello&quot;)<br>    public String hello() {<br>        String message = &quot;Myself Prakash Karuppusamy and exploring Spring AI&quot;;<br>        PromptTemplate promptTemplate = new PromptTemplate(message);<br>        Prompt prompt = promptTemplate.create();<br>        return chatClient.call(prompt.getContents());<br>    }<br></pre><h4>Step 5: Download phi3</h4><pre>ollama run phi3</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7k_rR8G_lkUDTjC8WuCI2g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LUU5d7TeqMRs8Nrctzs25A.png" /></figure><p>Mention that in the properties file once downloaded</p><pre>spring.application.name=springboot-ai-demo<br><br>spring.ai.ollama.chat.options.model=phi3</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nxVcAgETENzS2QrUhu2dcg.png" /></figure><h4>Step 6: Install Httpie using homebrew</h4><p>The command brew install httpie is used to install <strong>HTTPie</strong>, a powerful and user-friendly command-line HTTP client, using <strong>Homebrew</strong> on macOS (or Linux).</p><ul><li><strong>brew</strong>: This is the command-line tool for <strong>Homebrew</strong>, which is a popular package manager for macOS. It simplifies the installation of software and libraries.</li><li><strong>install</strong>: This tells Homebrew to download and install the specified package.</li><li><strong>httpie</strong>: This is the name of the package. <strong>HTTPie</strong> is a modern alternative to curl, designed for making HTTP requests and testing RESTful APIs. It offers a more readable output and easier syntax.</li></ul><pre>brew install httpie</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SF6ZKw6PtgS4yPNjN9846Q.png" /></figure><h4>Step 7: Hit the api using below command in terminal</h4><pre> http GET :8080/hello<br></pre><p>Now it is trying to call the API</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MZYfBa20cywQfpVVTham3w.png" /></figure><p>Our Prompt is now responding</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MdKbiuaM1oW7NvXEWhOSKA.png" /></figure><h4>Step 8: Talking to Spring AI via Postman</h4><pre>http://localhost:8080/hello</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eLswqxedJxUKIU5UC2u5Kw.png" /></figure><h4>Step 9: Now lets try using prompt</h4><p>The PromptController class is a REST controller in a Spring Boot application that leverages <strong>Spring AI</strong> to handle AI-based interactions through HTTP endpoints. The controller is mapped to the base path /api/ai using the @RequestMapping annotation. It uses a ChatClient — a core component of Spring AI — to send prompts to an AI model and return the responses.</p><p>The class defines three endpoints. The first, /chat, is a POST endpoint that accepts a prompt as a raw string in the request body and sends it to the AI model via chatClient.call(prompt). This makes it a generic and dynamic entry point to interact with the AI by sending custom messages. The second endpoint, /health, is a simple GET request that returns a static string confirming the service is up, useful for health checks and monitoring. The third endpoint, /trending, is a GET request that sends a predefined message to the AI asking for the top 5 trending travel destinations for August 2024. The prompt is carefully structured to ask for concise results with brief reasoning, and the AI’s response is returned as a plain string.</p><p>Overall, this controller demonstrates how to expose AI capabilities in a RESTful format using Spring Boot and Spring AI, enabling dynamic and predefined interactions with AI models over HTTP.</p><pre>package com.prakash.ai;<br><br>import org.springframework.ai.chat.ChatClient;<br>import org.springframework.web.bind.annotation.*;<br><br>/**<br> * @author prakashkaruppusamy<br> */<br>@RestController<br>@RequestMapping(&quot;/api/ai&quot;)<br>public class PromptController {<br><br>    private final ChatClient chatClient;<br><br>    public PromptController(ChatClient chatClient) {<br>        this.chatClient = chatClient;<br>    }<br><br>    @PostMapping(&quot;/chat&quot;)<br>    public String chat(@RequestBody String prompt) {<br>        return chatClient.call(prompt);<br>    }<br><br>    @GetMapping(&quot;/health&quot;)<br>    public String health() {<br>        return &quot;AI Service is up and running!&quot;;<br>    }<br><br>    @GetMapping(&quot;/trending&quot;)<br>    public String getTrendingDestinations() {<br>        String message = &quot;&quot;&quot;<br>        I would like to know the top 5 trending destinations to visit in August 2024.<br>        Please provide a concise response with just the destination names and a brief reason why they&#39;re trending.<br>        &quot;&quot;&quot;;<br>        <br>        return chatClient.call(message);<br>    }<br>}</pre><h4>Step 10: Postman Response</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zsLRvHWRBT2QaGj-Lkm6iQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f5b1a31de47" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prakash  with Ollama + Mistral]]></title>
            <link>https://prakashbtech87.medium.com/prakash-with-ollama-mistral-50b5456ab4a2?source=rss-d0b23dd03035------2</link>
            <guid isPermaLink="false">https://medium.com/p/50b5456ab4a2</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[mistral-ai]]></category>
            <category><![CDATA[ollama]]></category>
            <dc:creator><![CDATA[Prakash Karuppusamy]]></dc:creator>
            <pubDate>Sun, 06 Jul 2025 16:03:15 GMT</pubDate>
            <atom:updated>2025-07-06T16:03:15.347Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*1QeZk9y3LY2Pl1ssfwA13Q.png" /></figure><p>Here i am trying to do my own AI model using Ollama.</p><h3>What is Ollama?</h3><p><strong>Ollama</strong> is a free tool that lets you run ChatGPT-like AI models <strong>offline</strong> on your laptop.</p><ul><li>✅ Works great on <strong>MacBook Pro with M1/M2/M3 chips</strong></li><li>✅ You don’t need internet once the model is downloaded</li><li>✅ You can chat with models like <strong>Mistral, LLaMA 3, Gemma</strong>, etc.</li><li>✅ You use it through the <strong>Terminal</strong> (command-line)</li></ul><p><a href="https://ollama.com/">Ollama · Run AI models locally and in the cloud</a></p><h3>🔧 How to Use Ollama (Step-by-Step)</h3><h3>✅ Step 1: Install Ollama</h3><ol><li>Visit 👉 <a href="https://ollama.com/">https://ollama.com</a></li><li>Click <strong>Download for macOS (Apple Silicon)</strong></li><li>Open the downloaded file and install it like any normal app</li></ol><h3>✅ Step 2: Run a model (like Mistral)</h3><ol><li>Open the <strong>Terminal</strong> app on your Mac</li><li>Type the following command and press Enter</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UWkexY8pJzphHGfDNqbJ4A.png" /></figure><p>type below in browser to verify Ollama is running</p><p><a href="http://localhost:11434/">http://localhost:11434/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kgbfV8jY4lIwvpwwMCGJQw.png" /></figure><h3>🔹 1.Mistral AI (Company)</h3><p><strong>Mistral AI</strong> is a <strong>French startup</strong> that builds <strong>open-weight large language models (LLMs)</strong> — similar to OpenAI’s GPT or Meta’s LLaMA.</p><ul><li>Founded in <strong>2023</strong> by ex-employees of Meta and Google DeepMind.</li><li>Known for focusing on <strong>open-source</strong>, efficient models.</li><li>Their models are optimized to run faster and with lower compute than some larger models.</li></ul><h3>🔹 2.Mistral (Model)</h3><p>Mistral has released <strong>language models</strong> named after the company:</p><h4>✅ Examples:</h4><ul><li><strong>Mistral 7B</strong> — A 7 billion parameter model released in late 2023. Small but powerful.</li><li><strong>Mixtral 8x7B</strong> — A <strong>Mixture of Experts (MoE)</strong> model. It has 8 expert models, but only 2 are used at a time for any given input (which makes it efficient).</li></ul><h4>🔍 Features:</h4><ul><li>Open-source (weights available for use/research).</li><li>Competitive with or better than models like LLaMA 2.</li><li>Can be fine-tuned and used on-premise (no cloud lock-in).</li></ul><p>Code :</p><p>Python:</p><pre>import ollama<br><br>while True:<br>    question = input(&quot;Ask something (or type &#39;exit&#39; to quit): &quot;)<br><br>    if question.lower() in [&#39;exit&#39;, &#39;quit&#39;]:<br>        print(&quot;Goodbye! 👋&quot;)<br>        break<br><br>    response = ollama.generate(model=&#39;mistral&#39;, prompt=question)<br><br>    print(&quot;Answer:&quot;, response[&#39;response&#39;])</pre><p>Output :</p><pre>/Users/prakashkaruppusamy/MacDrive/PythonWorkspace/PrakashAIMode/.venv/bin/python /Users/prakashkaruppusamy/MacDrive/PythonWorkspace/PrakashAIMode/prakashChatGPT.py <br>Ask something (or type &#39;exit&#39; to quit): what is capital of Tamilnadu<br>Answer:  The capital of Tamil Nadu, a state in Southern India, is Chennai (formerly known as Madras). Chennai is the largest city in Tamil Nadu and one of the four metropolitan cities in India. It serves as an important center for commerce, arts, culture, and education in South India.<br>Ask something (or type &#39;exit&#39; to quit): </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BQgvBBzin9nzdCPrvWzVMQ.png" /></figure><p>Java version:</p><p>Code Link : <a href="https://github.com/prakashbtech87/PrakashJavaRepository/blob/main/src/main/java/com/prakash/ai/OllamaChat.java">https://github.com/prakashbtech87/PrakashJavaRepository/blob/main/src/main/java/com/prakash/ai/OllamaChat.java</a></p><pre>package com.prakash.ai;<br><br>/**<br> * @author prakashkaruppusamy<br> */<br><br>import java.io.*;<br>import java.net.*;<br>import java.util.Scanner;<br><br>public class OllamaChat {<br>    public static void main(String[] args) {<br>        Scanner scanner = new Scanner(System.in);<br><br>        while (true) {<br>            System.out.print(&quot;Ask something (or type &#39;exit&#39; to quit): &quot;);<br>            String question = scanner.nextLine();<br><br>            if (question.equalsIgnoreCase(&quot;exit&quot;) || question.equalsIgnoreCase(&quot;quit&quot;)) {<br>                System.out.println(&quot;Goodbye! 👋&quot;);<br>                break;<br>            }<br><br>            try {<br>                // Prepare request to Ollama local server<br>                URL url = new URL(&quot;http://localhost:11434/api/generate&quot;);<br>                HttpURLConnection conn = (HttpURLConnection) url.openConnection();<br><br>                conn.setRequestMethod(&quot;POST&quot;);<br>                conn.setRequestProperty(&quot;Content-Type&quot;, &quot;application/json&quot;);<br>                conn.setDoOutput(true);<br><br>                // Request JSON payload<br>                String jsonInput = String.format(<br>                        &quot;{\&quot;model\&quot;: \&quot;mistral\&quot;, \&quot;prompt\&quot;: \&quot;%s\&quot;}&quot;, question.replace(&quot;\&quot;&quot;, &quot;\\\&quot;&quot;)<br>                );<br><br>                // Send request<br>                try (OutputStream os = conn.getOutputStream()) {<br>                    byte[] input = jsonInput.getBytes(&quot;utf-8&quot;);<br>                    os.write(input, 0, input.length);<br>                }<br><br>                // Read response<br>                try (BufferedReader br = new BufferedReader(<br>                        new InputStreamReader(conn.getInputStream(), &quot;utf-8&quot;))) {<br><br>                    StringBuilder responseBuilder = new StringBuilder();<br>                    String line;<br>                    while ((line = br.readLine()) != null) {<br>                        // Ollama streams multiple JSON lines<br>                        if (line.contains(&quot;\&quot;response\&quot;&quot;)) {<br>                            int start = line.indexOf(&quot;\&quot;response\&quot;:\&quot;&quot;) + 12;<br>                            int end = line.indexOf(&quot;\&quot;&quot;, start);<br>                            String answer = line.substring(start, end);<br>                            System.out.print(answer);<br>                        }<br>                    }<br><br>                    System.out.println(); // line break after full answer<br>                }<br><br>                conn.disconnect();<br><br>            } catch (Exception e) {<br>                System.out.println(&quot;Error while connecting to Ollama: &quot; + e.getMessage());<br>            }<br>        }<br><br>        scanner.close();<br>    }<br>}</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xNgPJGLOYW1MpoMzQDEwIg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50b5456ab4a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java SOLID Design Principles]]></title>
            <link>https://prakashbtech87.medium.com/java-solid-design-principles-9406ac987763?source=rss-d0b23dd03035------2</link>
            <guid isPermaLink="false">https://medium.com/p/9406ac987763</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[design-principles]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Prakash Karuppusamy]]></dc:creator>
            <pubDate>Sat, 28 Jun 2025 13:43:39 GMT</pubDate>
            <atom:updated>2025-06-28T13:43:39.680Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IiKqQN1IXYOb03UouzChwA.png" /></figure><p>Github Link : <a href="https://github.com/prakashbtech87/PrakashJavaRepository/tree/main/src/main/java/com/design/solid">https://github.com/prakashbtech87/PrakashJavaRepository/tree/main/src/main/java/com/design/solid</a></p><h3>S –Single Responsibility Principle (SRP)</h3><blockquote>A class should have only one reason to change, meaning it should have only one responsibility or job.</blockquote><h3>O –Open/Closed Principle (OCP)</h3><blockquote>Software components should be open for extension but closed for modification — new functionality should be added without changing existing code.</blockquote><h3>L –Liskov Substitution Principle (LSP)</h3><blockquote>Objects of a subclass should be substitutable for their parent class without affecting the correctness of the program.</blockquote><h3>I –Interface Segregation Principle (ISP)</h3><blockquote>Clients should not be forced to depend on interfaces they do not use.</blockquote><blockquote><em>→ Split large interfaces into smaller, more specific ones so classes only implement what they need.</em></blockquote><h3>D –Dependency Inversion Principle (DIP)</h3><blockquote>High-level modules should not depend on low-level modules. Both should depend on abstractions.</blockquote><blockquote><em>→ Code should depend on </em><strong><em>interfaces, not concrete implementations</em></strong><em>.</em></blockquote><p>SRP — With Violation (❌ Multiple Responsibilities in One Class)</p><pre>package com.design.solid.s1srpviolation;<br><br>/**<br> * SRP Violation Example - Single class doing too many things<br> */<br>public class SRPViolation {<br>    public static void main(String[] args) {<br>        Employee employee = new Employee(&quot;Prakash&quot;, 500000);<br>        System.out.println(&quot;Salary: &quot; + employee.calculateSalary());<br>        employee.generateReport();<br>    }<br>}<br><br>class Employee {<br>    private final String name;<br>    private final double baseSalary;<br><br>    public Employee(String name, double baseSalary) {<br>        this.name = name;<br>        this.baseSalary = baseSalary;<br>    }<br><br>    // ✅ Business logic<br>    public double calculateSalary() {<br>        return baseSalary * 1.6;<br>    }<br><br>    // ❌ Reporting logic – not employee&#39;s job<br>    public void generateReport() {<br>        System.out.println(&quot;Generating report for employee: &quot; + name);<br>    }<br>}</pre><blockquote><em>❌ </em><strong><em>Violation</em></strong><em>: Employee class has </em><strong><em>more than one reason to change</em></strong><em> — salary logic and report logic are tightly coupled.ok</em></blockquote><h3>✅ SRP — Without Violation (Separation of Responsibilities)</h3><pre>package com.design.solid.s1srpsafe;<br><br>/**<br> * SRP Safe Example - One responsibility per class<br> */<br>public class SRPSafe {<br>    public static void main(String[] args) {<br>        Employee employee = new Employee(&quot;Prakash&quot;, 500000);<br>        SalaryCalculator salaryCalculator = new SalaryCalculator();<br>        ReportGenerator reportGenerator = new ReportGenerator();<br><br>        System.out.println(&quot;Salary: &quot; + salaryCalculator.calculateSalary(employee));<br>        reportGenerator.generateReport(employee);<br>    }<br>}<br><br>class Employee {<br>    private final String name;<br>    private final double baseSalary;<br><br>    public Employee(String name, double baseSalary) {<br>        this.name = name;<br>        this.baseSalary = baseSalary;<br>    }<br><br>    public String getName() {<br>        return name;<br>    }<br><br>    public double getBaseSalary() {<br>        return baseSalary;<br>    }<br>}<br><br>class SalaryCalculator {<br>    public double calculateSalary(Employee employee) {<br>        return employee.getBaseSalary() * 1.6;<br>    }<br>}<br><br>class ReportGenerator {<br>    public void generateReport(Employee employee) {<br>        System.out.println(&quot;Generating report for: &quot; + employee.getName());<br>    }<br>}</pre><blockquote><em>✅ </em><strong><em>Clean SRP</em></strong><em>:</em></blockquote><blockquote><em>Each class now has </em><strong><em>exactly one responsibility</em></strong><em>:</em></blockquote><ul><li>Employee — holds data</li><li>SalaryCalculator — handles salary logic</li><li>ReportGenerator — handles reporting</li></ul><h3>💥 OCP — With Violation (❌ Hardcoded if-else , not extensible)</h3><pre>package com.design.solid.s2ocpviolation;<br><br>/**<br> * OCP Violation Example – Modifying code for new shape<br> */<br>public class OCPViolation {<br>    public static void main(String[] args) {<br>        AreaCalculator calculator = new AreaCalculator();<br>        System.out.println(&quot;Circle Area: &quot; + calculator.calculateArea(&quot;circle&quot;, 5, 0, 0));<br>        System.out.println(&quot;Rectangle Area: &quot; + calculator.calculateArea(&quot;rectangle&quot;, 0, 4, 6));<br>    }<br>}<br><br>class AreaCalculator {<br>    public double calculateArea(String shape, double radius, double length, double breadth) {<br>        if (shape.equals(&quot;circle&quot;)) {<br>            return Math.PI * radius * radius;<br>        } else if (shape.equals(&quot;rectangle&quot;)) {<br>            return length * breadth;<br>        }<br>        // ❌ Adding a new shape like triangle means modifying this method<br>        return 0;<br>    }<br>}</pre><blockquote><em>❌ </em><strong><em>Violation</em></strong><em>: Every new shape requires modifying AreaCalculator — breaks the </em><strong><em>“closed for modification”</em></strong><em> part of OCP.</em></blockquote><h3>✅ OCP — Without Violation (✔️ Open for Extension via Polymorphism)</h3><pre>package com.design.solid.s2ocpsafe;<br><br>/**<br> * OCP Safe Example – Easily extendable with new shapes<br> */<br>public class OCPSafe {<br>    public static void main(String[] args) {<br>        Shape circle = new Circle(5);<br>        Shape rectangle = new Rectangle(4, 6);<br><br>        AreaCalculator calculator = new AreaCalculator();<br>        System.out.println(&quot;Circle Area: &quot; + calculator.calculateArea(circle));<br>        System.out.println(&quot;Rectangle Area: &quot; + calculator.calculateArea(rectangle));<br>    }<br>}<br><br>interface Shape {<br>    double calculateArea();<br>}<br><br>class Circle implements Shape {<br>    private final double radius;<br><br>    public Circle(double radius) {<br>        this.radius = radius;<br>    }<br><br>    @Override<br>    public double calculateArea() {<br>        return Math.PI * radius * radius;<br>    }<br>}<br><br>class Rectangle implements Shape {<br>    private final double length;<br>    private final double breadth;<br><br>    public Rectangle(double length, double breadth) {<br>        this.length = length;<br>        this.breadth = breadth;<br>    }<br><br>    @Override<br>    public double calculateArea() {<br>        return length * breadth;<br>    }<br>}<br><br>class AreaCalculator {<br>    public double calculateArea(Shape shape) {<br>        return shape.calculateArea();<br>    }<br>}</pre><blockquote><em>✅ </em><strong><em>OCP Safe</em></strong><em>: You can add a new shape (like Triangle) by </em><strong><em>extending</em></strong><em> the code with a new class.</em></blockquote><blockquote><em>No need to change existing logic in AreaCalculator.</em></blockquote><h3>💥 LSP — With Violation (❌ Subclass breaks expected behavior)</h3><pre>package com.design.solid.s3lspviolation;<br><br>/**<br> * LSP Violation Example – Penguin breaks the contract of Bird<br> */<br>public class LSPViolation {<br>    public static void main(String[] args) {<br>        Bird sparrow = new Sparrow();<br>        Bird penguin = new Penguin();<br><br>        sparrow.fly();     // ✅ Works fine<br>        penguin.fly();     // ❌ Throws runtime exception<br>    }<br>}<br><br>class Bird {<br>    public void fly() {<br>        System.out.println(&quot;Bird is flying...&quot;);<br>    }<br>}<br><br>class Sparrow extends Bird {<br>    @Override<br>    public void fly() {<br>        System.out.println(&quot;Sparrow flying...&quot;);<br>    }<br>}<br><br>class Penguin extends Bird {<br>    @Override<br>    public void fly() {<br>        throw new UnsupportedOperationException(&quot;Penguins can&#39;t fly&quot;);<br>    }<br>}</pre><blockquote><em>❌ </em><strong><em>Violation</em></strong><em>: Penguin inherits fly() from Bird, but can’t actually fly — </em><strong><em>this breaks the Liskov Substitution Principle</em></strong><em>.</em></blockquote><h3>✅ LSP — Without Violation (✔️ No broken expectations)</h3><pre>package com.design.solid.s3lspsafe;<br><br>/**<br> * LSP Safe Example – Behavior is properly segregated<br> */<br>public class LSPSafe {<br>    public static void main(String[] args) {<br>        Bird sparrow = new Sparrow();<br>        Bird penguin = new Penguin();<br><br>        sparrow.makeSound();<br>        penguin.makeSound();<br><br>        FlyingBird flyingBird = new Sparrow(); // ✅ Only Sparrow flies<br>        flyingBird.fly();<br>    }<br>}<br><br>// ✅ Base class with only shared behavior<br>abstract class Bird {<br>    abstract void makeSound();<br>}<br><br>// ✅ Interface for flying capability<br>interface FlyingBird {<br>    void fly();<br>}<br><br>class Sparrow extends Bird implements FlyingBird {<br>    @Override<br>    public void makeSound() {<br>        System.out.println(&quot;Chirp chirp...&quot;);<br>    }<br><br>    @Override<br>    public void fly() {<br>        System.out.println(&quot;Sparrow flying...&quot;);<br>    }<br>}<br><br>class Penguin extends Bird {<br>    @Override<br>    public void makeSound() {<br>        System.out.println(&quot;Penguin honks...&quot;);<br>    }<br>}</pre><blockquote><em>✅ </em><strong><em>LSP Safe</em></strong><em>:</em></blockquote><blockquote><em>Bird only defines common behavior (makeSound).</em></blockquote><blockquote><em>Only birds that can fly implement FlyingBird.</em></blockquote><blockquote><em>This ensures </em><strong><em>no false promises</em></strong><em> — and full compliance with LSP.</em></blockquote><h3>✅ Interface Segregation Principle (ISP)</h3><h3>💥 ISP — With Violation (❌ One fat interface for all)</h3><pre>package com.design.solid.s4ispviolation;<br><br>/**<br> * ISP Violation Example – One interface forces unused methods<br> */<br>public class ISPViolation {<br>    public static void main(String[] args) {<br>        Worker human = new Human();<br>        human.work();<br>        human.eat();<br><br>        Worker robot = new Robot();<br>        robot.work();<br>        robot.eat(); // ❌ Throws exception<br>    }<br>}<br><br>interface Worker {<br>    void work();<br>    void eat();<br>}<br><br>class Human implements Worker {<br>    @Override<br>    public void work() {<br>        System.out.println(&quot;Human is working&quot;);<br>    }<br><br>    @Override<br>    public void eat() {<br>        System.out.println(&quot;Human is eating&quot;);<br>    }<br>}<br><br>class Robot implements Worker {<br>    @Override<br>    public void work() {<br>        System.out.println(&quot;Robot is working&quot;);<br>    }<br><br>    @Override<br>    public void eat() {<br>        throw new UnsupportedOperationException(&quot;Robot does not eat&quot;);<br>    }<br>}</pre><blockquote><em>❌ </em><strong><em>Violation</em></strong><em>: Robot is </em><strong><em>forced to implement</em></strong><em> an eat() method it doesn’t need.</em></blockquote><h3>✅ ISP — Without Violation (✔️ Split interfaces by responsibility)</h3><pre>package com.design.solid.s4ispsafe;<br><br>/**<br> * ISP Safe Example – Separate interfaces for eat and work<br> */<br>public class ISPSafe {<br>    public static void main(String[] args) {<br>        Workable robot = new Robot();<br>        robot.work();<br><br>        Human human = new Human();<br>        human.work();<br>        human.eat();<br>    }<br>}<br><br>interface Workable {<br>    void work();<br>}<br><br>interface Eatable {<br>    void eat();<br>}<br><br>class Human implements Workable, Eatable {<br>    @Override<br>    public void work() {<br>        System.out.println(&quot;Human is working&quot;);<br>    }<br><br>    @Override<br>    public void eat() {<br>        System.out.println(&quot;Human is eating&quot;);<br>    }<br>}<br><br>class Robot implements Workable {<br>    @Override<br>    public void work() {<br>        System.out.println(&quot;Robot is working&quot;);<br>    }<br>}</pre><blockquote><em>✅ </em><strong><em>Safe ISP</em></strong><em>: Interfaces are small and focused.</em></blockquote><blockquote><em>Each class implements only what it needs — </em><strong><em>no extra burden</em></strong><em>.</em></blockquote><h3>✅ Dependency Inversion Principle (DIP)</h3><h3>💥 DIP — With Violation (❌ High-level class depends on low-level class directly)</h3><pre>package com.design.solid.s5dipviolation;<br><br>/**<br> * DIP Violation Example – Tight coupling to low-level class<br> */<br>public class DIPViolation {<br>    public static void main(String[] args) {<br>        Computer computer = new Computer();<br>        computer.start();<br>    }<br>}<br><br>class Computer {<br>    private WiredKeyBoard keyBoard = new WiredKeyBoard(); // ❌ Concrete dependency<br><br>    public void start() {<br>        keyBoard.connect();<br>    }<br>}<br><br>class WiredKeyBoard {<br>    public void connect() {<br>        System.out.println(&quot;Wired keyboard connected&quot;);<br>    }<br>}</pre><blockquote><em>❌ </em><strong><em>Violation</em></strong><em>: Computer is tightly coupled to a </em><strong><em>specific keyboard</em></strong><em>.</em></blockquote><blockquote><em>Difficult to switch to another type (e.g. wireless).</em></blockquote><h3>✅ DIP — Without Violation (✔️ Depend on abstraction, not concrete)</h3><pre>package com.design.solid.s5dipsafe;<br><br>/**<br> * DIP Safe Example – High-level depends on abstraction<br> */<br>public class DIPSafe {<br>    public static void main(String[] args) {<br>        KeyBoard wired = new WiredKeyBoard();<br>        KeyBoard wireless = new WirelessKeyBoard();<br><br>        Computer pc1 = new Computer(wired);<br>        Computer pc2 = new Computer(wireless);<br><br>        pc1.start();<br>        pc2.start();<br>    }<br>}<br><br>interface KeyBoard {<br>    void connect();<br>}<br><br>class WiredKeyBoard implements KeyBoard {<br>    @Override<br>    public void connect() {<br>        System.out.println(&quot;Wired keyboard connected&quot;);<br>    }<br>}<br><br>class WirelessKeyBoard implements KeyBoard {<br>    @Override<br>    public void connect() {<br>        System.out.println(&quot;Wireless keyboard connected&quot;);<br>    }<br>}<br><br>class Computer {<br>    private final KeyBoard keyBoard;<br><br>    public Computer(KeyBoard keyBoard) {<br>        this.keyBoard = keyBoard;<br>    }<br><br>    public void start() {<br>        keyBoard.connect();<br>    }<br>}</pre><blockquote><em>✅ </em><strong><em>DIP Safe</em></strong><em>: Computer depends on KeyBoard interface — not concrete types.</em></blockquote><blockquote><em>You can inject any implementation — </em><strong><em>loose coupling, high flexibility</em></strong><em>.</em></blockquote><h3>Summary :</h3><h3>✅S — Single Responsibility Principle (SRP)</h3><ul><li>📌 <strong>One class → One job</strong></li><li>🔧 <em>Change for one reason only</em></li><li>👨‍🏫 <strong>Layman Example</strong>: A teacher should teach, not cook lunch. Cooking is the chef’s job.</li></ul><h3>✅O — Open/Closed Principle (OCP)</h3><ul><li>📌 <strong>Open for extension, closed for modification</strong></li><li>➕ <em>Add new, don’t touch old</em></li><li>🧩 <strong>Layman Example</strong>: Add new plug points in a board, but don’t break the board every time.</li></ul><h3>✅L — Liskov Substitution Principle (LSP)</h3><ul><li>📌 <strong>Child class should fully replace parent class</strong></li><li>🚫 <em>No surprise behavior</em></li><li>🐧 <strong>Layman Example</strong>: A flying bird toy should not explode if replaced with a penguin toy — penguins can’t fly, so don’t promise it!</li></ul><h3>✅I — Interface Segregation Principle (ISP)</h3><ul><li>📌 <strong>Small, focused interfaces</strong></li><li>✂️ <em>Don’t force extra work</em></li><li>🤖 <strong>Layman Example</strong>: A robot doesn’t need a lunch break. Don’t force it to implement eat().</li></ul><h3>✅D — Dependency Inversion Principle (DIP)</h3><ul><li>📌 <strong>Depend on abstractions, not implementations</strong></li><li>🔌 <em>Plug-in and swap easily</em></li><li>⌨️ <strong>Layman Example</strong>: A computer should work with <strong>any keyboard</strong> — wired or wireless — as long as it supports the common plug/interface.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9406ac987763" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>