<?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/tag/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>Change margin of a view programmatically?</title>
		<link>https://www.maxester.com/blog/2023/07/12/change-margin-of-a-view-programmatically/</link>
		<comments>https://www.maxester.com/blog/2023/07/12/change-margin-of-a-view-programmatically/#respond</comments>
		<pubDate>Wed, 12 Jul 2023 11:09:16 +0000</pubDate>
		<dc:creator><![CDATA[Jony Chawla]]></dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[margin]]></category>
		<category><![CDATA[programmatically]]></category>
		<category><![CDATA[serMargin]]></category>
		<category><![CDATA[view margin]]></category>

		<guid isPermaLink="false">https://www.maxester.com/blog/?p=1123</guid>
		<description><![CDATA[<p>Let suppose view in a LinearLayout. First you have to get Layoutparams of the view and cast into to specific Layoutparams and modify the margins. As I remove margins by setting it all by 0. OR You can create a&#8230;</p>
<p><a href="https://www.maxester.com/blog/2023/07/12/change-margin-of-a-view-programmatically/" 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/2023/07/12/change-margin-of-a-view-programmatically/">Change margin of a view programmatically?</a> appeared first on <a rel="nofollow" href="https://www.maxester.com/blog">MaXEster Technologies  | Technical Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[
<p>Let suppose view in a LinearLayout. First you have to get Layoutparams of the view and cast into to specific Layoutparams and modify the margins. As I remove margins by setting it all by 0.</p>



<pre class="wp-block-code"><code>((LinearLayout.LayoutParams) view.getLayoutParams()).setMargins(0,0,0,0);

               {or}

((LinearLayout.LayoutParams) view.getLayoutParams()).topMargin = 5;</code></pre>



<p style="text-align:center">OR</p>



<p>You can create a LayoutParams variable and set margins to it. And set LayoutParams back to the view. as below</p>



<pre class="wp-block-code"><code>LinearLayout.LayoutParams parmas = (LinearLayout.LayoutParams) holder.imageView.getLayoutParams();
            parmas.setMargins(0,5,0,0);
            holder.imageView.setLayoutParams(parmas);</code></pre>



<p style="text-align:center">OR</p>



<p>You can use it in more generic way without specifying the particular Layout. </p>



<p><br>If the view is inside RelativeLayout.  </p>



<pre class="wp-block-code"><code>RelativeLayout.LayoutParmas</code></pre>



<p>Or you can use generic ViewGroup.MarginLayoutParams without specifying parent</p>



<pre class="wp-block-code"><code>if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
        ViewGroup.MarginLayoutParams mp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        mp.setMargins(0,5,0,0);
        view.requestLayout();
    }</code></pre>
<p>The post <a rel="nofollow" href="https://www.maxester.com/blog/2023/07/12/change-margin-of-a-view-programmatically/">Change margin of a view programmatically?</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/2023/07/12/change-margin-of-a-view-programmatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>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>
