<?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 Hemanth Turubatla on Medium]]></title>
        <description><![CDATA[Stories by Hemanth Turubatla on Medium]]></description>
        <link>https://medium.com/@turubatlahemanth2002?source=rss-343e3dcba01e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*8G5DSk8hUZ3XUAZ4</url>
            <title>Stories by Hemanth Turubatla on Medium</title>
            <link>https://medium.com/@turubatlahemanth2002?source=rss-343e3dcba01e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 18:10:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@turubatlahemanth2002/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[Make Your Java Cleaner: Understanding Method References (::)]]></title>
            <link>https://medium.com/@turubatlahemanth2002/make-your-java-cleaner-understanding-method-references-d86831ef3ce6?source=rss-343e3dcba01e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d86831ef3ce6</guid>
            <category><![CDATA[information-technology]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[java-8-feature]]></category>
            <dc:creator><![CDATA[Hemanth Turubatla]]></dc:creator>
            <pubDate>Sun, 20 Jul 2025 23:33:00 GMT</pubDate>
            <atom:updated>2025-07-20T23:33:00.608Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Method references</em></strong> are special types of <a href="https://medium.com/@turubatlahemanth2002/mastering-java-8-lambda-expressions-simplifying-code-with-functional-programming-f4ab5dab7a4d">lambda expressions</a> that execute only one method.</p><pre><br>object::methodName</pre><p>🔍 Types of Method References</p><p>Java supports four types of method references:</p><p><strong>1.Reference to a Static Method</strong>: Refers to a static method of a class.<br><strong>Syntax :- ClassName::staticMethodName</strong></p><pre>List&lt;String&gt; names = Arrays.asList(&quot;Alice&quot;, &quot;Bob&quot;, &quot;Charlie&quot;);<br>names.forEach(System.out::println);</pre><p>2.<strong>Reference to an Instance Method of a Particular Object</strong>: Refers to an instance method of a specific object.<br><strong>Syntax :- objectReference::instanceMethodName</strong></p><pre>StringBuilder sb = new StringBuilder();<br>Consumer&lt;String&gt; appender = sb::append;<br>appender.accept(&quot;Hello&quot;);<br>System.out.println(sb); // Output: Hello</pre><p>3. <strong>Reference to an Instance Method of an Arbitrary Object of a Particular Type</strong>: Refers to an instance method of an arbitrary object of a specific type.<br><strong>Syntax :- ClassName::instanceMethodName</strong></p><pre>List&lt;String&gt; names = Arrays.asList(&quot;Alice&quot;, &quot;Bob&quot;, &quot;Charlie&quot;);<br>names.sort(String::compareToIgnoreCase);</pre><p>4. <strong>Reference to a Constructor</strong>: Refers to a constructor.<br><strong>Syntax :- ClassName::new</strong></p><pre>// Using method reference to create a new ArrayList<br>Supplier&lt;List&lt;String&gt;&gt; listSupplier = ArrayList::new;<br><br>// Creating a new List instance<br>List&lt;String&gt; list = listSupplier.get();<br><br>list.add(&quot;Apple&quot;);<br>list.add(&quot;Banana&quot;);<br>list.add(&quot;Cherry&quot;);<br><br>System.out.println(&quot;List: &quot; + list);<br><br>/* OUTPUT = List: [&quot;Apple&quot;,&quot;Banana&quot;, &quot;Cherry&quot;] */</pre><blockquote>Implementing All Four Types of Method References</blockquote><pre>import java.util.Arrays;<br>import java.util.List;<br>import java.util.function.Supplier;<br><br>public class MethodReferenceDemo {<br><br>    // 1. Static Method Reference<br>    public static int add(int a, int b) {<br>        return a + b;<br>    }<br><br>    // 2. Instance Method Reference of a Particular Object<br>    public String greet(String name) {<br>        return &quot;Hello, &quot; + name;<br>    }<br><br>    // 3. Instance Method Reference of an Arbitrary Object of a Particular Type<br>    public static void main(String[] args) {<br>        // List of names<br>        List&lt;String&gt; names = Arrays.asList(&quot;Alice&quot;, &quot;Bob&quot;, &quot;Charlie&quot;);<br><br>        // 1. Static Method Reference<br>        int sum = MethodReferenceDemo.add(5, 3);<br>        System.out.println(&quot;Sum: &quot; + sum);<br><br>        // 2. Instance Method Reference of a Particular Object<br>        MethodReferenceDemo demo = new MethodReferenceDemo();<br>        names.forEach(name -&gt; System.out.println(demo.greet(name)));<br><br>        // 3. Instance Method Reference of an Arbitrary Object of a Particular Type<br>        names.forEach(String::toUpperCase);<br><br>        // 4. Constructor Reference<br>        Supplier&lt;String&gt; supplier = String::new;<br>        String str = supplier.get();<br>        System.out.println(&quot;New String: &quot; + str);<br>    }<br>}</pre><ol><li><strong>Static Method Reference</strong>: This refers to a static method of a class. In the code, MethodReferenceDemo::add is a reference to the static method add in the MethodReferenceDemo class. The add method takes two integers and returns their sum. This method is invoked directly using MethodReferenceDemo.add(5, 3), resulting in the output Sum: 8.</li><li><strong>Instance Method Reference of a Particular Object</strong>: This refers to an instance method of a particular object. In the code, demo::greet is a reference to the instance method greet of the demo object. The greet method takes a string (name) and returns a greeting message. This method is invoked using names.forEach(name -&gt; System.out.println(demo.greet(name))), resulting in the <br>output:Hello, Alice <br> Hello, Bob <br>Hello, Charlie</li><li><strong>Instance Method Reference of an Arbitrary Object of a Particular Type</strong>: This refers to an instance method of an arbitrary object of a particular type. In the code, String::toUpperCase is a reference to the toUpperCase method of the String class. The toUpperCase method converts a string to uppercase. This method is invoked using names.forEach(String::toUpperCase), resulting in the output:ALICE BOB CHARLIE</li><li><strong>Constructor Reference</strong>: This refers to a constructor of a class. In the code, String::new is a reference to the constructor of the String class. The constructor creates a new empty string. This constructor is invoked using Supplier&lt;String&gt; supplier = String::new; String str = supplier.get();, resulting in the output: New String:</li></ol><p>These method references provide a concise and readable way to express instances where a method is passed as an argument to a higher-order function. They eliminate the need for explicit lambda expressions, making the code more readable and maintainable. This approach enhances code clarity and reduces verbosity.</p><h3>✅ Summary</h3><ul><li><strong>Static Method Reference:</strong> Refers to a static method of a class.</li><li><strong>Instance Method Reference of a Particular Object:</strong> Refers to an instance method of a specific object.</li><li><strong>Instance Method Reference of an Arbitrary Object of a Particular Type:</strong> Refers to an instance method of an arbitrary object of a particular type.</li><li><strong>Constructor Reference:</strong> Refers to a constructor to create new objects.</li></ul><p>These method references provide a concise and readable way to express instances where a method is passed as an argument to a higher-order function.</p><p>Thank You for reading…!<br>Wishing you happy coding…!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d86831ef3ce6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Java 8 Lambda Expressions: Simplifying Code with Functional Programming]]></title>
            <link>https://medium.com/@turubatlahemanth2002/mastering-java-8-lambda-expressions-simplifying-code-with-functional-programming-f4ab5dab7a4d?source=rss-343e3dcba01e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4ab5dab7a4d</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[features]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Hemanth Turubatla]]></dc:creator>
            <pubDate>Sun, 15 Dec 2024 06:07:28 GMT</pubDate>
            <atom:updated>2024-12-15T06:07:28.756Z</atom:updated>
            <content:encoded><![CDATA[<h3>What are Lambda Expressions?</h3><p>Lambda expressions in Java allow you to pass code around as a data value. Simply put, it is a way to represent one method interface using an expression. Lambdas provide a clear and concise way to implement functional interfaces (interfaces with a single abstract method).</p><p>A lambda expression consists of three parts:</p><ol><li><strong>Argument list</strong>: The parameters passed to the method (optional if none).</li><li><strong>Arrow token (</strong><strong>-&gt;)</strong>: Separates the parameters from the body.</li><li><strong>Body</strong>: The expression or block of code that is executed.</li></ol><p><strong>Syntax of a Lambda Expression:</strong></p><pre>(parameter) -&gt; { statements; }</pre><h3>Define the Functional Interface</h3><p>First, we’ll define a <a href="https://medium.com/@turubatlahemanth2002/exploring-functional-interfaces-in-java-8-3ac4999a5fa6">functional interface</a> Calculator with a single abstract method operate(). This method will take two integers as input and return the result of an arithmetic operation.</p><pre>@FunctionalInterface<br>interface Calculator {<br>    // Single abstract method<br>    int operate(int a, int b);<br>}</pre><h3><strong>Implementing Lambda Expression</strong></h3><p><strong>I</strong>n this example, we use <strong>lambda expressions</strong> to implement the Calculator functional interface for performing various arithmetic operations (addition, subtraction, multiplication, and division). Here&#39;s how we can assign each lambda expression to a Calculator variable and use it to perform the respective operation.</p><pre>public class CalculatorExample {<br>    public static void main(String[] args) {<br>        // Lambda expression implementing the &#39;operate&#39; method<br>        Calculator addition = (a, b) -&gt; a + b;  // Adds two numbers<br>        System.out.println(&quot;Addition: &quot; + addition.operate(5, 3)); // Output: 8<br><br>        // Lambda expression for subtraction<br>        Calculator subtraction = (a, b) -&gt; a - b; // Subtracts b from a<br>        System.out.println(&quot;Subtraction: &quot; + subtraction.operate(5, 3)); // Output: 2<br><br>        // Lambda expression for multiplication<br>        Calculator multiplication = (a, b) -&gt; a * b; // Multiplies two numbers<br>        System.out.println(&quot;Multiplication: &quot; + multiplication.operate(5, 3)); // Output: 15<br><br>        // Lambda expression for division<br>        Calculator division = (a, b) -&gt; a / b; // Divides a by b<br>        System.out.println(&quot;Division: &quot; + division.operate(6, 3)); // Output: 2<br><br>        }<br>}</pre><h3>Summary</h3><p>This blog explores how to use <strong>lambda expressions</strong> in Java to implement a simple calculator that performs arithmetic operations like addition, subtraction, multiplication, and division. By using <strong>functional interfaces</strong>, we can define operations inline, making the code concise and readable.</p><p>Key points include:</p><ul><li><strong>Functional Interface</strong>: The Calculator interface defines a method operate(int a, int b) for arithmetic operations.</li><li><strong>Lambda Expressions</strong>: We implement the operate() method for each operation (addition, subtraction, multiplication, division) using lambda expressions.</li><li><strong>Benefits</strong>: Lambda expressions reduce boilerplate code, improve readability, and offer flexibility for modifying operations.</li></ul><p>In conclusion, lambda expressions simplify Java code, making it more efficient, concise, and easier to maintain.</p><p>Thank You for reading…!<br>Wishing you happy coding…!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4ab5dab7a4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Functional Interfaces in Java 8]]></title>
            <link>https://medium.com/@turubatlahemanth2002/exploring-functional-interfaces-in-java-8-3ac4999a5fa6?source=rss-343e3dcba01e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ac4999a5fa6</guid>
            <category><![CDATA[functionalinterface]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Hemanth Turubatla]]></dc:creator>
            <pubDate>Mon, 14 Oct 2024 17:31:23 GMT</pubDate>
            <atom:updated>2024-10-14T17:31:23.358Z</atom:updated>
            <content:encoded><![CDATA[<p>Java 8 introduced functional interfaces, a concept that allows you to use lambda expressions and functional programming techniques. In this blog, we’ll dive into what functional interfaces are, their accepted methods, and provide code snippets to illustrate how they work.</p><h3>What is a Functional Interface?</h3><p>A <strong>functional interface</strong> is an interface with exactly one abstract method. This characteristic allows instances of functional interfaces to be created using lambda expressions or method references. It can contain multiple default and static methods.</p><p><strong>Default Methods</strong>: Default methods allow a functional interface to provide concrete implementations that can be inherited by implementing classes.</p><p><strong>Static Methods</strong>: Static methods belong to the interface and can be called directly without creating an instance of the interface.</p><pre>@FunctionalInterface<br>interface Calculator {<br>    int calculate(int a, int b); // Abstract method for calculation<br><br>    // Default method to add two numbers<br>    default int add(int a, int b) {<br>        return a + b;<br>    }<br><br>    // Static method to subtract two numbers<br>    static int subtract(int a, int b) {<br>        return a- b;<br>    }<br>}</pre><h3>Implementing functional interface</h3><p>we implement the Calculator functional interface using a lambda expression, allowing us to define the behavior of the calculate method inline. Here&#39;s how you can do it:</p><pre>public class Main {<br>    public static void main(String[] args) {<br>        // Lambda expression implementing the calculate method<br>        Calculator solve = (a, b) -&gt; a * b; // The lambda takes two integers and returns their product<br><br>        // Using the calculate method<br>        System.out.println(&quot;Calculate (5 * 3): &quot; + solve.calculate(5, 3)); // Output: 15<br><br>        // Using default method<br>        System.out.println(&quot;Add (5 + 3): &quot; + solve.add(5, 3)); // Output: 8<br><br>        // Using static method<br>        System.out.println(&quot;Subtract (5 - 3): &quot; + Calculator.subtract(5, 3)); // Output: 2<br>    }<br>}</pre><h3>Conclusion</h3><p>In this exploration of the Java functional interface Calculator, we have demonstrated how to leverage the power of lambda expressions to implement functionality in a concise and readable manner. The Calculator interface defines a single abstract method, calculate, alongside default and static methods that enhance its utility.</p><p>By using a lambda expression, we created an instance of Calculator that performs multiplication, showcasing how functional programming can simplify code and improve readability. Additionally, we utilized default methods to perform addition and static methods for subtraction, illustrating the versatility of interfaces in Java.</p><p>This approach not only fosters cleaner code but also encourages the use of functional programming concepts, making your Java applications more modular and easier to maintain. Overall, the combination of functional interfaces, lambda expressions, and method references empowers developers to write elegant and efficient Java code, paving the way for more modern programming practices.</p><p>Thank you for reading…!<br>Wishing you happy coding…!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ac4999a5fa6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>