<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java &#8211; MaXEster Technologies  | Technical Blog</title>
	<atom:link href="https://www.maxester.com/blog/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.maxester.com/blog</link>
	<description>Tutorials, Examples and Implementation code for Developers Help</description>
	<lastBuildDate>Mon, 17 Feb 2025 09:17:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.22</generator>
	<item>
		<title>Method Reference In Java 8.</title>
		<link>https://www.maxester.com/blog/2020/01/03/method-reference-in-java-8/</link>
		<comments>https://www.maxester.com/blog/2020/01/03/method-reference-in-java-8/#respond</comments>
		<pubDate>Fri, 03 Jan 2020 07:37:19 +0000</pubDate>
		<dc:creator><![CDATA[Birjesh Gupta]]></dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Lambda Expression]]></category>
		<category><![CDATA[Method Reference]]></category>

		<guid isPermaLink="false">https://www.maxester.com/blog/?p=817</guid>
		<description><![CDATA[<p>One of the most welcome changes in Java 8 was the introduction of&#160;Lambda Expression and Method Reference In java 8.. Method references in java are a special type of lambda expressions. because they&#8217;re often used to create simple lambda expressions&#8230;</p>
<p><a href="https://www.maxester.com/blog/2020/01/03/method-reference-in-java-8/" class="btn-more">Read More<span class="arrow-more">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://www.maxester.com/blog/2020/01/03/method-reference-in-java-8/">Method Reference In Java 8.</a> appeared first on <a rel="nofollow" href="https://www.maxester.com/blog">MaXEster Technologies  | Technical Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[
<p> One of the most welcome changes in Java 8 was the introduction of&nbsp;Lambda Expression and Method Reference In java 8..</p>



<p>Method references in java are a special type of lambda expressions. because they&#8217;re often used to create simple lambda expressions by referencing existing methods. </p>



<center>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Fads -->
<ins class="adsbygoogle fads"
     style="display:inline-block;"
     data-ad-client="ca-pub-3804472713147276"
     data-ad-slot="1267368188"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</center>




<p> It is compact and easy form of lambda expression. Each time when you are using lambda expression to just referring a method, you can replace your lambda expression with method reference. </p>



<p>So in this , we are explaining method reference in java concept in detail. </p>



<h2>Types of method reference in java.</h2>



<ol><li> Method Reference to a static method. </li><li> Reference to a instance method. </li><li> Reference to a constructor. </li></ol>



<h3>1. Method Reference to a static method.</h3>



<p><em><strong>syntax :-</strong></em> <br></p>



<pre class="wp-block-preformatted"><strong>ContainingClass::staticMethodName</strong></pre>



<h4>Example:-</h4>



<center>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Fads -->
<ins class="adsbygoogle fads"
     style="display:inline-block;"
     data-ad-client="ca-pub-3804472713147276"
     data-ad-slot="1267368188"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</center>




<p> In the below example, we have defined a functional interface and referring a static method to it&#8217;s functional method max(). </p>



<pre class="wp-block-code"><code>interface Maxester{  
    void max();  
}  
public class MethodReference {  
    public static void welcome(){  
        System.out.println("Welcome, this is static method.");  
    }  
    public static void main(String[] args) {  
        // Referring static method  
        Maxester maxester = MethodReference::welcome;  
        // Calling interface method  
        maxester.max();  
    }  
}  </code></pre>



<p><strong>Output:-</strong></p>



<p>Welcome, this is static method.</p>



<h3>2.  Reference to a instance method.</h3>



<p><strong><em>syntax</em>:-</strong></p>



<pre class="wp-block-preformatted"><strong> containingObject::instanceMethodName </strong></pre>



<h4><strong>Example</strong>:-</h4>



<p> In the below example, we are referring non-static methods. we can refer methods by class object and also an anonymous object. </p>



<pre class="wp-block-code"><code>interface Maxester{  
    void max();  
}  
public class InstanceMethodReference {  
    public void welcome(){  
        System.out.println("Welcome, this is instance method.");  
    }  
    public static void main(String[] args) {  
        InstanceMethodReference methodReference = new InstanceMethodReference(); // Creating object  
        // Referring non-static method using reference  
            Maxester maxester = methodReference::welcome;  
        // Calling interface method  
            Maxester.max();  
            // Referring non-static method using anonymous object  
            Maxester maxester_first = new InstanceMethodReference()::welcome; // You can use anonymous object also  
            // Calling interface method  
            maxester_first.max();  
    }  
}  
</code></pre>



<p><strong>Output</strong>:-</p>



<p>Welcome, this is instance method.</p>



<p>Welcome, this is instance method. </p>



<center>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Fads -->
<ins class="adsbygoogle fads"
     style="display:inline-block;"
     data-ad-client="ca-pub-3804472713147276"
     data-ad-slot="1267368188"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</center>




<h3>3. Reference to a constructor.</h3>



<p><strong><em>syntax</em></strong>:-</p>



<pre class="wp-block-preformatted"><strong> ClassName::new</strong></pre>



<h4>Example:-</h4>



<pre class="wp-block-code"><code>Interface Maxester{
      NewMaxester max(String value);
}
class NewMaxester{
      NewMaxester(String value){
         System.out.prinln(value);
     }
}
public class ConstrutorRefrenceMethod{
      public static void main(String[] args){
             Maxester maxester = NewMaxester::new;
             maxester.max("Welcome to maxester constructor");
        }
}</code></pre>



<p><strong><em>output</em></strong>:-</p>



<p> Welcome to maxester constructor. </p>



<p><strong><em>External Link:-</em></strong></p>



<p>You can also read much more about Method Reference from below link.</p>



<p><a href="https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html">https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html</a></p>



<p>So i hope, This will be helpful for you.</p>



<p>ThankYou.</p>



<p></p>
<p>The post <a rel="nofollow" href="https://www.maxester.com/blog/2020/01/03/method-reference-in-java-8/">Method Reference In Java 8.</a> appeared first on <a rel="nofollow" href="https://www.maxester.com/blog">MaXEster Technologies  | Technical Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.maxester.com/blog/2020/01/03/method-reference-in-java-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Can we Overload the main() method in Java?</title>
		<link>https://www.maxester.com/blog/2019/12/19/can-we-overload-the-main-method-in-java/</link>
		<comments>https://www.maxester.com/blog/2019/12/19/can-we-overload-the-main-method-in-java/#comments</comments>
		<pubDate>Thu, 19 Dec 2019 09:15:45 +0000</pubDate>
		<dc:creator><![CDATA[Birjesh Gupta]]></dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">https://www.maxester.com/blog/?p=795</guid>
		<description><![CDATA[<p>One of the common doubts among Java beginners while learning to overload and overriding is, whether it&#8217;s possible to overload main() in Java? Can you overload the main() method in Java? How will JVM find if you change the signature&#8230;</p>
<p><a href="https://www.maxester.com/blog/2019/12/19/can-we-overload-the-main-method-in-java/" class="btn-more">Read More<span class="arrow-more">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://www.maxester.com/blog/2019/12/19/can-we-overload-the-main-method-in-java/">Can we Overload the main() method in Java?</a> appeared first on <a rel="nofollow" href="https://www.maxester.com/blog">MaXEster Technologies  | Technical Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[
<p> One of the common doubts among Java beginners while learning to overload and overriding is, whether it&#8217;s possible to overload main() in Java? Can you overload the main() method in Java? How will JVM find if you change the signature of the main method as part of the method overloading? etc. </p>



<p>So, the answer is <strong>Yes</strong>, We can overload the main() method in java but JVM only calls the original main method, it will never call our overloaded main method. </p>



<center>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Fads -->
<ins class="adsbygoogle fads"
     style="display:inline-block;"
     data-ad-client="ca-pub-3804472713147276"
     data-ad-slot="1267368188"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</center>




<h2>Overload Main() Method in Java.</h2>



<p> This is just one way, you can create as many versions of main as you want, but you must make sure that the method signature of each main is different. You can change the method signature by changing the type of argument, number of arguments or order of arguments. Best practice to overload a method is by changing the number of arguments, or types of arguments.  In Java, it&#8217;s not possible to overload the method by just changing return type. </p>



<h2>Example:-</h2>



<pre class="wp-block-code"><code>public class Maxester { 


// Overloaded main method 1  
    // Should be executed when character is passed 
    public static void main(char value) 
    { 
        System.out.println("Inside main(char value) method"); 
    } 
  
    // Overloaded main method 2 
   // Should be executed when int value is passed 
    public static void main(int value) 
    { 
        System.out.println("Inside main(int value) method"); 
    } 
    // Overloaded main method 3  
    // Should be executed when double value is passed 
    public static void main(Double[] value) 
    { 
        System.out.println("Inside main(Double[] value) method"); 
    } 
  
    // Original main() 
    public static void main(String[] args) 
    { 
        System.out.println("Inside original main(String[] args) method "); 
    } 
} </code></pre>



<h3>Output:-</h3>



<center>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Fads -->
<ins class="adsbygoogle fads"
     style="display:inline-block;"
     data-ad-client="ca-pub-3804472713147276"
     data-ad-slot="1267368188"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</center>



<p><em><strong>Inside original main(Strings[] args) method.</strong></em></p>



<p> As from the above example, it is clear that every time the original main method executes but not the overloaded methods because JVM only executes the original main method by default but not the overloaded one.</p>



<p>we can overload the main() method in java<br>But, to execute overloaded methods of main, we must call them from the original main method. </p>



<p>I hope this will be helpful to you.</p>



<p>Thank you.</p>
<p>The post <a rel="nofollow" href="https://www.maxester.com/blog/2019/12/19/can-we-overload-the-main-method-in-java/">Can we Overload the main() method in Java?</a> appeared first on <a rel="nofollow" href="https://www.maxester.com/blog">MaXEster Technologies  | Technical Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.maxester.com/blog/2019/12/19/can-we-overload-the-main-method-in-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lambda Expressions in Java.</title>
		<link>https://www.maxester.com/blog/2019/11/29/lambda-expressions-in-java/</link>
		<comments>https://www.maxester.com/blog/2019/11/29/lambda-expressions-in-java/#respond</comments>
		<pubDate>Fri, 29 Nov 2019 11:24:00 +0000</pubDate>
		<dc:creator><![CDATA[Birjesh Gupta]]></dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Lambda Expression]]></category>

		<guid isPermaLink="false">https://www.maxester.com/blog/?p=754</guid>
		<description><![CDATA[<p>Lambda expression in java is a new and important feature of Java which was included in Java SE 8. And, Lambda expression in java also provides a clear and concise way to represent one method interface using an expression. It&#8230;</p>
<p><a href="https://www.maxester.com/blog/2019/11/29/lambda-expressions-in-java/" class="btn-more">Read More<span class="arrow-more">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://www.maxester.com/blog/2019/11/29/lambda-expressions-in-java/">Lambda Expressions in Java.</a> appeared first on <a rel="nofollow" href="https://www.maxester.com/blog">MaXEster Technologies  | Technical Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[
<p>Lambda expression in java is a new and important feature of Java which was included in Java SE 8. </p>



<p>And,  Lambda expression in java also provides a clear and concise way to represent one method interface using an expression.</p>



<center>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Fads -->
<ins class="adsbygoogle fads"
     style="display:inline-block;"
     data-ad-client="ca-pub-3804472713147276"
     data-ad-slot="1267368188"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</center>




<p>It is also very useful in the collection library. It helps to iterate, filter and extract data from the collection.</p>



<h2>Functional Interface</h2>



<p> An interface that has only one abstract method is called a functional interface. </p>



<p>But,</p>



<p>Lambda Expressions in Java also provides an annotation <strong>@</strong><em><strong>FunctionalInterface</strong></em>, which is used to declare an interface as a functional interface. </p>



<h2>Important Characteristics of a lambda expression. </h2>



<p><strong>1.Optional type declaration:</strong></p>



<p>No need to declare the type of a parameter.</p>



<center>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Fads -->
<ins class="adsbygoogle fads"
     style="display:inline-block;"
     data-ad-client="ca-pub-3804472713147276"
     data-ad-slot="1267368188"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</center>




<p> Also, The compiler can inference the same from the value of the parameter.</p>



<p><strong>2.</strong>  <strong>The optional parenthesis around parameter</strong> :</p>



<p>No need to declare a single parameter in parenthesis.  </p>



<p>But, For multiple parameters, parentheses are required.</p>



<p><strong>3.</strong>  <strong>Optional curly braces</strong> </p>



<p>No need to use curly braces in the expression body if the body contains a single statement. Then, it is  optional to return keyword</p>



<p><strong>4. Optional return keyword</strong></p>



<p>The compiler automatically returns the value if the body has a single expression to return the value. </p>



<p>Also, Curly braces are required to indicate that expression returns a value.</p>



<center>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Fads -->
<ins class="adsbygoogle fads"
     style="display:inline-block;"
     data-ad-client="ca-pub-3804472713147276"
     data-ad-slot="1267368188"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</center>




<h2>Why We Use Lambda Expression?</h2>



<ol><li>To provide the implementation of a Functional interface.</li><li>Less coding.</li></ol>



<h2>Syntax Of Lambda Expression</h2>



<ul><li><strong>no parameter syntax</strong></li></ul>



<pre class="wp-block-code"><code>() -> {  
//Body of no parameter lambda  
}
//Lambda Expressions in Java.</code></pre>



<ul><li><strong>one parameter syntax</strong></li></ul>



<pre class="wp-block-code"><code>(s1) -> {  
//Body of one parameter lambda  
}

//Lambda Expressions in Java.</code></pre>



<ul><li><strong>two-parameter syntax</strong></li></ul>



<pre class="wp-block-code"><code>(s1,s2) -> {  
//Body of two parameter lambda  
}

//Lambda Expressions in Java.</code></pre>



<h2>Example:-</h2>



<h2>Without using Lambda Expression:</h2>



<p></p>



<pre class="wp-block-code"><code>//Lambda Expressions in Java.

interface MyLambda{  
    public void lambda();  
}  
public class LambdaExample {  
    public static void main(String[] args) {  
        String name = "XYZ";  
  
        //without lambda, MyLambdaimplementation using anonymous class  
        MyLambda ml=new MyLambda(){  
            public void lambda(){System.out.println("Hello,  "+name);}  
        };  
        ml.lambda();  
    }  
}  

//Lambda Expressions in Java.</code></pre>



<p><strong>Output:&nbsp;&nbsp;</strong></p>



<p>Hello, XYZ</p>



<center>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Fads -->
<ins class="adsbygoogle fads"
     style="display:inline-block;"
     data-ad-client="ca-pub-3804472713147276"
     data-ad-slot="1267368188"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</center>




<h2>Using Lambda Expression:</h2>



<pre class="wp-block-code"><code>//Lambda Expressions in Java.

@FunctionalInterface  //It is optional 
interface MyLambda{  
    public String lambda(String name);  
}  
  
public class LambdaExample{  
    public static void main(String[] args) {  
      
        // Lambda expression with single parameter.  
        MyLambda my1=(name)->{  
            return "Hello, "+name;  
        };  
        System.out.println(my1.lambda("XYZ"));  
          
        // You can omit function parentheses    
        MyLambda my2= name ->{  
            return "Hello, "+name;  
        };  
        System.out.println(my2.lambda("ABC"));  
    }  
}

//Lambda Expressions in Java. </code></pre>



<p><strong>Output:&nbsp;</strong></p>



<pre class="wp-block-preformatted">Hello, XYZ<br>Hello, ABC</pre>



<p>You can also use no parameter and multiple parameters lambda expression as in the above example.</p>



<p>Then, you can see How Lambda Expression is very useful.</p>



<p>Also, I hope, this will be helpful for you.</p>



<p>You can also visit on below link for a brief Introduction about Lambda Expressions in Java.</p>



<p><a href="https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html">https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html</a></p>



<p>ThankYou.</p>
<p>The post <a rel="nofollow" href="https://www.maxester.com/blog/2019/11/29/lambda-expressions-in-java/">Lambda Expressions in Java.</a> appeared first on <a rel="nofollow" href="https://www.maxester.com/blog">MaXEster Technologies  | Technical Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.maxester.com/blog/2019/11/29/lambda-expressions-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
