<?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 Cun Yang on Medium]]></title>
        <description><![CDATA[Stories by Cun Yang on Medium]]></description>
        <link>https://medium.com/@backslash112?source=rss-66805dbaef03------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sKWeEurgifmbDhI3qvihvA.jpeg</url>
            <title>Stories by Cun Yang on Medium</title>
            <link>https://medium.com/@backslash112?source=rss-66805dbaef03------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 25 Nov 2026 01:04:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@backslash112/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[Start a Remote MySQL Server with Docker quickly]]></title>
            <link>https://medium.com/@backslash112/start-a-remote-mysql-server-with-docker-quickly-9fdff22d23fd?source=rss-66805dbaef03------2</link>
            <guid isPermaLink="false">https://medium.com/p/9fdff22d23fd</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Cun Yang]]></dc:creator>
            <pubDate>Wed, 16 May 2018 14:31:13 GMT</pubDate>
            <atom:updated>2018-05-16T14:36:02.073Z</atom:updated>
            <content:encoded><![CDATA[<p>-</p><h4>Take a quick glance at MySQL and Docker</h4><p><strong>MySQL</strong> is a freely available open-source relational database management system that uses SQL.</p><p><strong>Docker</strong> is an virtualization software that performs operating-system-level virtualization.</p><p>Unlike traditional VM, docker doesn’t take up a lot of space, memory and processing power.</p><p>Docker provides a light-weight <strong>container</strong> environment which can be used to host any application of your choice. Because it’s light-weight, it can be easily shipped to other machines and be executed on those machines, then you can get the exact same environment in dev and product system. Or you can clone your environment for any new team members easily and quickly, without painful setups.</p><p>With Docker, you can easily launch containers based on images that contain different versions of the software.</p><p>You could create as many container as you want on the host machine, and each of the container are isolated from one another.</p><p>Also, each docker images are version controlled.</p><h4>Step 1: Get the docker image of MySQL</h4><p>You can search what you want from the <a href="https://hub.docker.com/">https://hub.docker.com/</a> .</p><p>In this tutorial, I will use the first one: <em>mysql/mysql-server</em>.</p><p>Here is the command to down the image from the server to your local machine:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c96627aa14ec6f2df8a78cd780fe0ede/href">https://medium.com/media/c96627aa14ec6f2df8a78cd780fe0ede/href</a></iframe><p>After download finished, you can see it through the <em>docker image</em> command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/162b71592727fa33bc71c35e15287df3/href">https://medium.com/media/162b71592727fa33bc71c35e15287df3/href</a></iframe><h4>Step 2: Start running a docker container from MySQL image</h4><p>Now, you can start a mysql-server instance with the <em>docker run</em> command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/879b206df8b71710e9cbf2e92f4f9bd6/href">https://medium.com/media/879b206df8b71710e9cbf2e92f4f9bd6/href</a></iframe><p>If you only want to access it locally, it’s enough, but if you want to access your mysql server remotely, you need mapping the port <strong>3306</strong> of the container to port <strong>3306</strong> of the host machine. Also, you need to set the environment variable MYSQL_ROOT_HOST with wildcards to allow root connections from other hosts:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17a6b500739caff4e9d7a8857298bcdc/href">https://medium.com/media/17a6b500739caff4e9d7a8857298bcdc/href</a></iframe><h4>Step 3: Connecting to the MySQL Server instance</h4><p>Since it’s already running, you can connect to it with the<em> docker exec </em>command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16dbca319a2dfe819f6ebae1e5104503/href">https://medium.com/media/16dbca319a2dfe819f6ebae1e5104503/href</a></iframe><p>The system will ask you to change to root password, use the following command to achieve it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1cd5ad6dff9b09ee201352f11094cf2a/href">https://medium.com/media/1cd5ad6dff9b09ee201352f11094cf2a/href</a></iframe><p>Now your mysql server instance is running inside the docker, and you can access it from other hosts through 3306 port.</p><p>You can check your running containers through <em>docker ps</em> command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2448964fb29420f2f69abd5075fb8e36/href">https://medium.com/media/2448964fb29420f2f69abd5075fb8e36/href</a></iframe><h4>Problem solving for remotely access</h4><p>If you got the same problem like this while connect to MySQL server from another host (It depends on which version of MySQL you are using):</p><p><strong>java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed</strong></p><p>You should change your password of root user by using the native password hashing method to fix it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/316f75c00ee280b35bf616e98ed0792e/href">https://medium.com/media/316f75c00ee280b35bf616e98ed0792e/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9fdff22d23fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a Maven Project with Servlet in IntelliJ IDEA 2018]]></title>
            <link>https://medium.com/@backslash112/create-maven-project-with-servlet-in-intellij-idea-2018-be0d673bd9af?source=rss-66805dbaef03------2</link>
            <guid isPermaLink="false">https://medium.com/p/be0d673bd9af</guid>
            <category><![CDATA[intellij]]></category>
            <category><![CDATA[maven]]></category>
            <category><![CDATA[servlet]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Cun Yang]]></dc:creator>
            <pubDate>Tue, 15 May 2018 02:50:26 GMT</pubDate>
            <atom:updated>2018-05-15T02:57:26.009Z</atom:updated>
            <content:encoded><![CDATA[<p>IntelliJ IDEA 2018.1 (Ultimate Edition)<br>macOS 10.13.4</p><p>A Servlet is a java class that is extended to handle the capabilities of a server. Servlets can be used to handle the requests and responses of a server.</p><p>Apache Maven is a software project management and comprehension tool. Maven can help you manage a project’s build, reporting and documentation from a central piece of information.</p><p>In this tutorial I’ll be explaining how to create a simple servlet project with maven in IntelliJ IDEA.</p><h4>Step 1: Create a Maven project in intellij IDEA</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EF8KaPDMUmlI3YCofi5BLA.png" /></figure><h4>Step 2: Use the pom.xml file to manage your project dependencies</h4><p>POM stands for “Project Object Model”. It is an XML representation of a Maven project held in a file named pom.xml.</p><p>Here is a introduction of pom.xml file:</p><blockquote>A project contains configuration files, as well as the developers involved and the roles they play, the defect tracking system, the organization and licenses, the URL of where the project lives, the project’s dependencies, and all of the other little pieces that come into play to give code life. It is a one-stop-shop for all things concerning the project. In fact, in the Maven world, a project need not contain any code at all, merely a pom.xml.</blockquote><p>For the full introduction, please check <a href="https://maven.apache.org/pom.html#What_is_the_POM">https://maven.apache.org/pom.html#What_is_the_POM</a></p><p>Let’s go back to our project:</p><p>Go to the <a href="https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api/4.0.1">https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api/4.0.1</a> page, copy the dependency code inside the Maven tab:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e03304832480c25f5075890ea56f77b/href">https://medium.com/media/5e03304832480c25f5075890ea56f77b/href</a></iframe><h4>Step 3: Create the web app</h4><p><strong>3.1 Create a servlet class</strong></p><p>Firstly, create a new folder named java inside the src.main folder, then right-click the java folder, set it as sources root. If you don’t do that, then the IntelliJ IDEA will not show ‘Class’ when we right-click and select ‘New’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PKiSlL_fln1fnEWIRBCNEQ.png" /></figure><p>Right-click the java folder, and select ‘New’ — ‘Servlet’, name it com.demo.DemoServlet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U7CjaHPyR7hoNJbVOrPKFg.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98303dd68c81975fca0a618080466a44/href">https://medium.com/media/98303dd68c81975fca0a618080466a44/href</a></iframe><p>Remember to change the annotation code from @WebServlet(name = “DemoServlet”) to @WebServlet(“/DemoServlet”).</p><h4>Step 4: Run the project with Tomcat Server</h4><p><strong>4.2 Set up the Tomcat Server</strong></p><p>Open the Run/Debug Configurations dialog (e.g. Run | Edit Configurations).<br>Click (⌘N), select the Tomcat Server and select Local.</p><p>If this is your first to use Tomcat, the ‘Application Server’ item should be empty.<br>You need to download the Apache Tomcat first. Visit <a href="https://tomcat.apache.org/">https://tomcat.apache.org/</a> page, select ‘Download’ — ‘Tomcat 9’ — ‘Binary Distributions’ — ‘Core’ — ‘tar.gz’.<br>decompress it.</p><p>Then back to IntelliJ IDEA, press the ‘Configure’ button next to the ‘Application Server’ item, and select the Tomcat folder.</p><p><strong>4.3 Pressing the Fix button to add artifact.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n2G4ZSnI0MJwEoGD3NXIDg.png" /></figure><p><strong>4.4 Finally, Build and Run.</strong></p><p>Visit <a href="http://localhost:8080/DemoServlet">http://localhost:8080/DemoServlet</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oZXmQqdVGaOvIISKCFzbJg.png" /></figure><h4>Sources</h4><p><a href="https://www.jetbrains.com/help/idea/working-with-artifacts.html#artifact_def">https://www.jetbrains.com/help/idea/working-with-artifacts.html#artifact_def</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be0d673bd9af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analysis of Algorithms]]></title>
            <link>https://medium.com/@backslash112/analysis-of-algorithms-40ea32714285?source=rss-66805dbaef03------2</link>
            <guid isPermaLink="false">https://medium.com/p/40ea32714285</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[analysis]]></category>
            <dc:creator><![CDATA[Cun Yang]]></dc:creator>
            <pubDate>Thu, 10 May 2018 19:12:06 GMT</pubDate>
            <atom:updated>2018-05-10T19:12:06.168Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is analysis of algorithms?</h3><p>The definition of the technical level about analysis of algorithms is:<br>Study the use efficiency of <strong>time</strong> and <strong>memory space</strong> when an algorithm is running.<br>That’s mean focus on the time efficiency and space efficiency.</p><p>Time efficiency means how fast when invoke an algorithm.<br>Space efficiency means how many extra space will be used when invoke an algorithm.</p><p>Early in the computer age, the time and the space, those two resources are both expensive. But now with the increase of the technology, the space efficiency is not an importance problem anymore. We only need to focus on the time efficiency.</p><p><strong>So that’s mean when we analysis an algorithm, we only care the speed.</strong></p><h3>A common idea of analysis of algorithms:</h3><p>When we try to analysis an algorithm, we can follow those steps:</p><h4>Step 1: the size of the input</h4><p>Firstly, we need figure out what’s the size of the input, the parameter, in other words, how big of the problem we trying to solve?<br>Start with here because there is a general rule, no matter which algorithm you are using, larger size of the input will cost longer time to invoke.<br>The size of the input depends on the particular problem, the same input can be different in different situations. For example an algorithm for spell checking.<br>If you focus on each word, then the length of the input just the size of the input.<br>But if you focus on the phrase, then the size of the input will becoming smaller.</p><h4>Step 2: How to calculate the run time of an algorithm?</h4><p>And the second step is to calculate the speed of an algorithm.<br>You can simply using a stopwatch to find out how much time an algorithm spend while running.<br>But there is a big problem is when you invoke the same algorithm on another computer, you will get a different result. It depends on the performance of the computer.<br>So is there a better way to do that?<br>The answer is YES.<br>We can calculate <strong>how many steps it invoked</strong>, to make it more simple, we can only focus on the most important operation, which called “Basic Operation”.</p><h4>Step 3: The Best Efficiency, the Worst Efficiency and the Average Efficiency</h4><p>Sometimes, the efficiency of an algorithm depends on the details of the input.<br>For example a simple searching algorithm, let’s say to find the number 9 from the list sequentially.<br>We have two lists, which are:</p><pre>list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]<br>list2 = [9, 1, 2, 3, 4, 5, 6, 7, 8]</pre><p>It’s easy to know that it will be quicker to find the number 9 from the list2.<br>Generally, we call the efficiency of an algorithm <strong>“The Best Efficiency”</strong> when the input is as good as list2.<br>And call it <strong>“The Worst Efficiency”</strong> when the input is as bad as list1.</p><p>In the actual condition, the input data will be random, neither “the best input” nor “the worst input”.<br>So in the actual condition, we call it <strong>“The Average Efficiency”</strong>.</p><p><strong>Now how to figure out the average efficiency of an algorithm is our question.</strong><br>First of all, you can’t use the average value of the best efficiency and the worst efficiency, even sometimes the real average efficiency equals that value coincidentally.<br>The correct method is we need to do some hypothesis about the input data n. Let’s using the example above to explain it, there are two hypotheses:</p><ol><li>No matter you choose witch number as your target number, you always can find it from the list successfully. Now the probability to find the target is p(0 &lt;= p &lt;= 1).</li><li>For any target number i, the probability of the target number located in position i are same.</li></ol><p>From the two hypotheses above we can see that:</p><ol><li>If it always can find the given target i from the input, the probability is p/n that the target just located in position 1 for the first time. In this case, the number of comparison is 1.</li><li>If it always can’t find the given target from the input, the number of comparisons is n. In this case the probability is (1-p).</li></ol><p>The average efficiency C(n) = p(n+1) / 2 + n(1-p)</p><pre>C(n) = [1 * p/n + 2 * p/n + ... + i * p/n + ... + n * p/n] + n*(1-p)<br>=  p/n[1 + 2 + ... + i + ... + n] + n(1-p)<br>= p/n * n(n+1)/2 + n(1-p)<br>= p(n+1) / 2 + n(1-p)</pre><p>We can see that,</p><ol><li>If p = 1, that’s mean the searching must be success, the result is (n+1)/2 witch means it need to search about half of the input data.</li><li>If p = 0, that’s mean the searching must be fail, the result is n witch means it need to search the whole input data.</li></ol><h3>References：</h3><p><a href="https://www.amazon.com/Introduction-Design-Analysis-Algorithms-3rd/dp/0132316811"><em>Introduction to The Design and Analysis of Algorithms, Third Edition</em> by Anany Leitin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40ea32714285" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programming Paradigms: Imperative Programming, Declarative Programming and Functional Programming]]></title>
            <link>https://medium.com/@backslash112/programming-paradigms-imperative-programming-declarative-programming-and-functional-programming-a929ef812112?source=rss-66805dbaef03------2</link>
            <guid isPermaLink="false">https://medium.com/p/a929ef812112</guid>
            <category><![CDATA[programming-paradigms]]></category>
            <category><![CDATA[declarative-programming]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[imperative-programming]]></category>
            <dc:creator><![CDATA[Cun Yang]]></dc:creator>
            <pubDate>Thu, 10 May 2018 19:10:29 GMT</pubDate>
            <atom:updated>2018-05-10T19:10:29.539Z</atom:updated>
            <content:encoded><![CDATA[<h4>There are three main programming paradigms: Imperative programming, Declarative programming and Functional programming.</h4><h3>Imperative Programming</h3><p>The main idea of imperative programming is focusing on the steps of execution. For example you want to find out the numbers which bigger that number 5 from a collection which named collection, so with imperative programming idea you need to do this: Step 1, create a variable to store the results which can be named results. Step 2, iterate the collection. Step 3, compare each number to target number 5, if the current number is bigger that 5 then add it to the variable results. step 4, return the variable results.</p><p>And the code of the steps above is:</p><pre>List<strong>&lt;int&gt;</strong> results <strong>=</strong> <strong>new</strong> List<strong>&lt;int&gt;();</strong><br>foreach<strong>(</strong>var num in collection<strong>)</strong><br><strong>{</strong><br>    <strong>if</strong> <strong>(</strong>num <strong>&gt;</strong> 5<strong>)</strong><br>          results<strong>.</strong>Add<strong>(</strong>num<strong>);</strong><br><strong>}</strong></pre><p>From this example you can see, this kind of programming paradigm is very common, no matter which language you are using, like C, C++, C#, Java, Javascript, BASIC, Python or Ruby, you can write code with those languages in this way.</p><h3>Declarative Programming</h3><p>Declarative programming is focusing on the data structure, with the data structure to express the logic of the program, the idea is different from the imperative programming, instead of focusing on the steps, “how to do”, declarative programming focusing on “what you want”. For example SQL statement is a kind of declarative programming, here is a statement will do a similar thing as above example, but in a totally different way:</p><pre><strong>SELECT</strong> <strong>*</strong> <strong>FROM</strong> collection <strong>WHERE</strong> num <strong>&gt;</strong> 5</pre><h3>Functional Programming</h3><p>Functional programming is related with the declarative programming, because they all have the same idea: focus on what you want not how to do, it is a form of declarative programming but it isn’t the only kind of declarative programming. One key feature of functional programming is “first class values”, that means that not only can you write functions, but you can write functions that write functions, you can pass functions as parameters to other functions and return them as values. Most programming languages already support this paradigm, for example JavaScript, C# and Java. Here is an example to write a functional code in Java:</p><pre>List<strong>&lt;</strong>Number<strong>&gt;</strong> results <strong>=</strong> collection<strong>.</strong>stream<strong>()</strong><br>                                 <strong>.</strong>filter<strong>(</strong>n <strong>-&gt;</strong> n <strong>&gt;</strong> 5<strong>)</strong><br>                                 <strong>.</strong>collect<strong>(</strong>Collectors<strong>.</strong>toList<strong>());</strong></pre><p>You can see that it’s more clear and easy to understand in this way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a929ef812112" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Functional Programming in Java]]></title>
            <link>https://medium.com/@backslash112/functional-programming-in-java-1b871c027c3f?source=rss-66805dbaef03------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b871c027c3f</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[java8]]></category>
            <dc:creator><![CDATA[Cun Yang]]></dc:creator>
            <pubDate>Thu, 10 May 2018 19:08:15 GMT</pubDate>
            <atom:updated>2018-05-10T19:08:15.046Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>The big change in Java SE 8 is the best-known new feature: Lambda expression, it takes an effort to bring Java into the world of functional programming. It provide a clear and concise way to write the code. OK, let’s start with something simple to learn to how use it.</strong></h4><h3>A quick look at the Lambda expression</h3><p>First, let define a very simple lambda expression:</p><pre>x -&gt; x + 1</pre><p>This expression takes one argument named x, and uses the expression form the return x+1. Through this example we can easily know that a lambda expression is composed of three parts:</p><pre>(Argument list) -&gt; { Body }</pre><p>Argument list, Arrow token and body.</p><p>The body can either a single expression or a statement block. The bracketed in the argument list part can be omit if there is only one argument. The statement block in the body part is the same as in a normal method, but if there is only one single expression, the body is simply evaluated and returned, and the curly braces also can be omit. For example:</p><pre>(int x, int y) -&gt; { return x + y; }<br>(int x, int y) -&gt; x + y<br>x -&gt; x + 1<br>() -&gt; 3.14<br>(String s) -&gt; { System.out.println(s); }</pre><p>The first expression takes two integer arguments named x and y, and uses the expression form to return x+y. The second expression is as same as the first one, just omitted the curly braces and the return key word. The third expression takes one argument and uses the expression form to return x+1. The fourth expression takes no argument and simply return an number 3.14. The fifth expression takes one String argument named s, and uses the block form to print the string to the console, and returns nothing.</p><p>About the third expression, I guess you probably want to ask two questions: What’s the type of the argument x? What’s the type of the whole expression?</p><p>Now let introduce another concept which is java.util.function package. The definition about it from the official document is “Functional interfaces provide target types for lambda expressions and method references.”. So that’s mean it’s a class for the functional objects, how to store the functional objects. Well, The answer is that it depends. In Java the same lambda expression could be bound to variables of different types. OK, let’s go back to our example of lambda expression: x -&gt; x + 1, we can write two different Function types for the same expression:</p><pre>Function&lt;Integer, Integer&gt; add = x -&gt; x + 1;<br>Function&lt;String, String&gt; concat  = x -&gt; x + 1;</pre><p>The type of x in the first expression is Integer, it takes a integer argument which named x and use the expression form to return x+1. The type of x in the second expression is String, it takes a string argument and use the expression from to return the result of concatenates the integer 1 to any string x.</p><h3>The type with two arguments</h3><p>Now we know how to define the type with one argument, how to write the code if the expression takes two arguments? Let’s say we want to summarize two integer arguments x and y then return the result? Well, we need another class to do that, the BiFunction&lt;T, U, R&gt; type, the T is mean the type of the first argument, the U mean the type of the second argument, and the R mean the type of the return value. For example:</p><pre>BiFunction&lt;Integer, Integer, Integer&gt; sum = (x, y) -&gt; x + y;</pre><h3>The type with arguments but return value</h3><p>How to define a lambda expression if it doesn’t need to return a value? The answer is use the Consumer&lt;T&gt; class, like this:</p><pre>Consumer&lt;String&gt; sayHi = name -&gt; System.out.println(&quot;hi, &quot; + name);</pre><p>P.S.: If you need two arguments you need to use ‘BiConsumer&lt;T, U&gt;’ class.</p><h3>The type without any argument</h3><p>If we want to define a expression without any argument but you want to return a value, you need to use the Supplier&lt;T&gt; class, here is an example for it:</p><pre>Supplier<strong>&lt;</strong>String<strong>&gt;</strong> getName <strong>=</strong> <strong>()</strong> <strong>-&gt;</strong> &quot;Carl&quot;<strong>;</strong></pre><p>This lambda expression will return a String as result when you call it each time.</p><h3>How to invoke the lambda expression?</h3><p>After we defined our lambda expressions, we need to use the apply() method to invoke these functions:</p><pre>Integer result = add.apply(2);  // yields 3<br>String answer = concat.apply(&quot;hi&quot;);  // yields &quot;hi1&quot;<br>Integer  total = sum.apply(1, 2);  // yields 3<br>String name = getName.apply();  // yields &quot;Carl&quot;</pre><h3>References:</h3><ol><li><a href="https://www.amazon.com/Beginning-Java-Objects-Concepts-Second/dp/1590594576"><em>Beginning Java objects</em> by Jacquie Barker</a></li><li><a href="http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html">Java SE 8: Lambda Quick Start</a></li><li><a href="https://www.javacodegeeks.com/2014/07/java-se-8-new-features-tour-functional-programming-with-lambda-expression.html">The big change in Java SE 8</a></li><li><a href="https://dzone.com/articles/functional-programming-java-8">Functional Programming with Java 8 Functions</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b871c027c3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>