

{"id":19077,"date":"2018-06-17T04:00:17","date_gmt":"2018-06-17T04:00:17","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=19077"},"modified":"2026-05-22T17:51:37","modified_gmt":"2026-05-22T12:21:37","slug":"java-closure","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/java-closure\/","title":{"rendered":"What is Java Closure | Java 8 Lambda Expressions"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:1903,&quot;href&quot;:&quot;https:\\\/\\\/www.java.com&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20080828101111\\\/http:\\\/\\\/java.com.\\\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-10 07:41:40&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2025-12-17 10:16:59&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2025-12-22 10:42:34&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-05 10:28:30&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-16 08:47:12&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-26 14:09:36&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-29 21:01:35&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-03 12:34:11&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-27 22:13:37&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-10 23:32:17&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-15 11:07:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-22 18:35:59&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-29 13:27:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-11 12:56:33&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-22 13:02:41&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-28 15:41:35&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-02 04:22:41&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-26 12:47:33&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-13 06:54:11&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-13 06:54:11&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>In our last Tutorial, we discussed <strong><a href=\"https:\/\/data-flair.training\/blogs\/final-keyword-in-java\/\" target=\"_blank\" rel=\"noopener\">final keywords in Java<\/a><\/strong>. Today, we will discuss Java Closure. Here, in this article, we will first see the introduction to closure in Java. Moreover, we will learn how Java creates closures. Along with this, we will discuss Java 8 Lambda expressions. Also, the limitations of Java 8 Lambda and JavaScript functions. At last, we will see Java Closure using Mutable objects.<\/p>\n<p><span style=\"font-weight: 400\">So, let us start with Java Closure.<\/span><\/p>\n<div id=\"attachment_19103\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-Closure-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-19103\" class=\"wp-image-19103 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-Closure-01.jpg\" alt=\"Java Closure\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-Closure-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-Closure-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-Closure-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-Closure-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-Closure-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-19103\" class=\"wp-caption-text\">What is Java Closure | Java 8 Lambda Expressions<\/p><\/div>\n<h3>What is a Java Closure?<\/h3>\n<p>Suppose we wish to make an easy thread that solely prints one thing on the console:<\/p>\n<pre class=\"EnlighterJSRAW\">int answer = 14;\r\nThread t = new Thread(\r\n() -&gt; System.out.println(\"The answer is: \" + answer)\r\n);<\/pre>\n<p><span style=\"font-weight: 400\">In this Java Closure article, we will prefer to answer this question, discussing the limitations of <strong><a href=\"https:\/\/data-flair.training\/blogs\/java-functional-interface\/\" target=\"_blank\" rel=\"noopener\">Java lambda expressions<\/a><\/strong> and consequences on the approach Java implements closures is the answer to this question, however, there are limitations once we compare them with different languages. On the other hand, these limitations are thought to be negligible.<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/design-patterns-in-java\/\" target=\"_blank\" rel=\"noopener\">Do you know what Design Patterns in Java?<\/a><\/strong><\/p>\n<h3>What are Java 8 Lambda Expressions?<\/h3>\n<p>A Java 8 lambda expression is a function with no name and is defined in a single line.<\/p>\n<pre class=\"EnlighterJSRAW\">int answer = 14;\r\nThread t = new Thread(new Runnable() \"&gt;\r\n});<\/pre>\n<p><span style=\"font-family: Verdana, Geneva, sans-serif\">Since Java 8, the previous example could be written using a lambda expression.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Now, we have a tendency to all know that Java 8 lambda expressions don&#8217;t seem to be only about reducing the verbosity of your code; they also have many different new features. What is more, there are between the implementation of anonymous classes and lambda expressions.<\/span><\/p>\n<div id=\"attachment_19130\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-8-Lambda-Expressions-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-19130\" class=\"wp-image-19130 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-8-Lambda-Expressions-01.jpg\" alt=\"Java Closure - Java 8 Lambda Expressions\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-8-Lambda-Expressions-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-8-Lambda-Expressions-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-8-Lambda-Expressions-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-8-Lambda-Expressions-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-8-Lambda-Expressions-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-19130\" class=\"wp-caption-text\">Java 8 Lambda Expressions<\/p><\/div>\n<p><span style=\"font-weight: 400\">But, the main purpose we might highlight here is that, considering how they act with the enclosing scope, we are able to think about them even as a compact approach to making anonymous classes of interfaces, like Runnable, Callable, Function, Predicate, and so on.<\/span><\/p>\n<h3>Java 8 Lambda Limitations<\/h3>\n<ul>\n<li><span style=\"font-weight: 400\">The intromission scope for Lambda expressions in Java will solely access the ultimate (or effectively final) variables. <\/span><span style=\"font-weight: 400\">For example, take into account the subsequent example:<\/span><br \/>\n<span style=\"font-family: Verdana, Geneva, sans-serif\">void fn()<\/span><br \/>\n<span style=\"font-weight: 400\">Compilation won\u2019t be done as incrementation of myVar is final.<\/span><\/li>\n<li>It is difficult to detect the error and find where it is, as it does not have a name associated with it.<\/li>\n<li>Java 8 Lambda lacks when it comes to defining complex problems because the logic cannot be coded in a single statement.<\/li>\n<li>Use of various Java 8 Lambda expressions can confuse the compiler, leading to an error.<\/li>\n<\/ul>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/java-language-keywords\/\" target=\"_blank\" rel=\"noopener\">Read Java Language Keywords &#8211; Top 4 Keywords in Java (Part 2)<\/a><\/strong><\/p>\n<h3>JavaScript and Its Functions<\/h3>\n<p><strong>Functions and lambda expressions in JavaScript use the concept of closures:<\/strong><\/p>\n<p><span style=\"font-weight: 400\">A closure may be a special kind of object that combines 2 things: a function, and therefore the environment in which that function was created. It contains local variables. In fact, the previous example works well in JavaScript.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">function fn() { \/\/ the intromission scope\r\nvar myVar = 42;\r\nvar lambdaFun = () =&gt; myVar;\r\nmyVar++;\r\nconsole.log(lambdaFun()); \/\/ it prints 43\r\n}<\/pre>\n<h3>Does Java Create Closures?<\/h3>\n<p><span style=\"font-weight: 400\">The only value of free variables is allowed by Java to allow them to be used within lambda expressions. Albeit there was an increment of myVar, the lambda function would still return 42. The compiler avoids the creation of these incoherent scenarios, limiting the kind of variables that will be used within lambda expressions (and anonymous classes) to only final and effectively final ones. <\/span><\/p>\n<p><span style=\"font-weight: 400\">In fact, closures, in their own theoretical acceptation, capture the value of free variables solely. In pure functional languages, this is often the sole issue that ought to be allowed, keeping the referential transparency property.<\/span><\/p>\n<div id=\"attachment_19105\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Does-Java-Create-Closures-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-19105\" class=\"wp-image-19105 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Does-Java-Create-Closures-01.jpg\" alt=\"Java Closure\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Does-Java-Create-Closures-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Does-Java-Create-Closures-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Does-Java-Create-Closures-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Does-Java-Create-Closures-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Does-Java-Create-Closures-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-19105\" class=\"wp-caption-text\">How to Create Java Create Closures?<\/p><\/div>\n<h3>Side Effects and JavaScript<\/h3>\n<p><span style=\"font-weight: 400\">To better understand the concept of closures in Java, take into account the subsequent JavaScript code (forgive that in JavaScript, this may be written as an awfully compact approach; however, we would like it to seem like Java for a comparison):<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/java-functional-interface\/\" target=\"_blank\" rel=\"noopener\">Explore Java Functional Interface | Lambda Expression in Java<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">function createCounter(initValue) { \/\/ the intromission scope\r\nvar count = initValue;\r\nvar map = new Map();\r\nmap.set('val', () =&gt; count);\r\nmap.set('inc', () =&gt; count++);\r\nreturn map;\r\n}<\/pre>\n<p><span style=\"font-weight: 400\">v = createCounter(42);<\/span><br \/>\n<span style=\"font-weight: 400\">v.get(&#8216;val&#8217;)(); <\/span><br \/>\n<span style=\"font-weight: 400\">v.get(&#8216;inc&#8217;)(); <\/span><br \/>\n<span style=\"font-weight: 400\">v.get(&#8216;val&#8217;)(); <\/span><br \/>\n<span style=\"font-weight: 400\">The first function in Java Closure has side effects that change the results of the other. An important fact to note here is that createCounter&#8217;s scope still exists once its termination, \u2014 and is at the same time employed by the 2 lambda functions.<\/span><br \/>\n<span style=\"font-weight: 400\">Now let&#8217;s attempt to do a similar issue in Java:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">public static Map createCounter(int initValue) { \/\/ the intromission scope\r\nint count = initValue;\r\nMap map = new HashMap&lt;&gt;();\r\nmap.put(\"val\", () -&gt; count);\r\nmap.put(\"inc\", () -&gt; count++);\r\nreturn map;\r\n}<\/pre>\n<p><span style=\"font-weight: 400\">This code does not compile as a result of the second lambda performing an attempt to change the variable count.<\/span><br \/>\n<span style=\"font-weight: 400\">Java stores function variables (e.g. count) within the stack; those are removed with the termination of createCounter. The created lambdas use copied versions of count. If the compiler allowed the second lambda to change its traced version of count, it&#8217;d be quite confusing.<\/span><\/p>\n<h3>Java Closures Using mutable Objects<\/h3>\n<p><span style=\"font-weight: 400\">The value of a user variable is copied to the lambda or anonymous class. In this case, solely the reference would be copied, and we might look at things a bit differently.<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/java-semaphore\/\" target=\"_blank\" rel=\"noopener\">Let&#8217;s discuss Java Semaphore \u2013 Working &amp; Constructor<\/a><\/strong><\/p>\n<p><span style=\"font-weight: 400\">We might just about emulate the behavior of JavaScript&#8217;s closures in the following way:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">private static category MyClosure\r\n}\r\npublic static Map createCounter(int initValue) {\r\nMyClosure closure = new MyClosure(initValue);\r\nMap counter = new HashMap&lt;&gt;();\r\ncounter.put(\"val\", () -&gt; closure.value);\r\ncounter.put(\"inc\", () -&gt; closure.value++);\r\nreturn counter;\r\n}<\/pre>\n<p><span style=\"font-weight: 400\">Supplier[] v = createCounter(42);<\/span><br \/>\n<span style=\"font-weight: 400\">v.get(&#8220;val&#8221;).get(); \/\/ returns forty two<\/span><br \/>\n<span style=\"font-weight: 400\">v.get(&#8220;inc&#8221;).get(); \/\/ returns forty two<\/span><br \/>\n<span style=\"font-weight: 400\">v.get(&#8220;val&#8221;).get(); \/\/ returns forty three<\/span><\/p>\n<p><span style=\"font-weight: 400\">Java Closures are employed by JavaScript as a fundamental mechanism to make &#8220;class&#8221; instances: objects. This is often why, in JavaScript, a function like MyCounter is termed a &#8220;constructor function.&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400\">In the previous example, we do not want a closure. That &#8220;factory function&#8221; is basically a weird example of a category definition. In Java, we can merely outline a class just like the following one:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">class MyJavaCounter non-public int value;\r\npublic MyJavaCounter(int initValue)\r\npublic int increment() { come value++; }\r\npublic int get() { return value; }\r\n}\r\nMyJavaCounter v = new MyJavaCounter(42);\r\nSystem.out.println(v.get());\r\nSystem.out.println(v.increment());\r\nSystem.out.println(v.get());<\/pre>\n<p><span style=\"font-weight: 400\">Lambda functions that modify free variables (i.e. any object that has been outlined outside the lambda function) might generate confusion. Aspect effects of different functions could lead to unwanted errors.<\/span><\/p>\n<h3>Use Cases for Java Closures<\/h3>\n<p>Despite these limitations, Java closures can still be a valuable tool for functional programming in Java. Here are some common use cases:<\/p>\n<p><strong>1. Creating Event Listeners:<\/strong> Java closures can be used to create event listeners that capture state from the enclosing scope. For example, you could create a button click listener that remembers the current value of a counter variable and increments it when clicked.<\/p>\n<p><strong>2. Encapsulating State and Behavior:<\/strong> Closures can be used to create objects that encapsulate both data (state) and the functions that operate on that data (behavior). This can improve code organization and readability.<\/p>\n<p><strong>3. Partial Function Application:<\/strong> A closure can be used to create a new function by fixing some of the input parameters of an existing function. This can be a powerful technique for creating reusable and generic functions.<\/p>\n<p>So, this was all about Java Closure. Hope you like our explanation.<\/p>\n<h3>Conclusion<\/h3>\n<p><span style=\"font-weight: 400\">Hence, in this Java Closure tutorial, we learned about closures in Java. Moreover, we discussed Java 8 Lambda expressions and its limitations. Also, we saw JavaScript and its Functions. Still, if any doubt, ask in the comment tab.\u00a0<\/span><\/p>\n<p><strong>See also &#8211;\u00a0<\/strong><strong><a href=\"https:\/\/data-flair.training\/blogs\/bubble-sort-in-java\/\" target=\"_blank\" rel=\"noopener\">Bubble Sort in Java &#8211; Definition &amp; Examples<\/a><\/strong><\/p>\n<p><a href=\"https:\/\/www.java.com\/\" target=\"_blank\" rel=\"noopener\"><strong>For reference<\/strong><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our last Tutorial, we discussed final keywords in Java. Today, we will discuss Java Closure. Here, in this article, we will first see the introduction to closure in Java. Moreover, we will learn&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":19103,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[2578,4031,7358,7360,7361,7426,7674,15777],"class_list":["post-19077","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-closures-in-java","tag-does-java-create-closures","tag-java-8-features","tag-java-8-lambda-limitations","tag-java-8-lamda-expression","tag-java-closures-using-mutable-objects","tag-java-script-functions","tag-what-is-java-closure"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What is Java Closure | Java 8 Lambda Expressions - DataFlair<\/title>\n<meta name=\"description\" content=\"Java Closure tutorial: what is closure in Java, Java 8 Lambda expression, Java 8, how doesJava create closure,Java Closure using mutable objects,Java script\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/java-closure\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is Java Closure | Java 8 Lambda Expressions - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Java Closure tutorial: what is closure in Java, Java 8 Lambda expression, Java 8, how doesJava create closure,Java Closure using mutable objects,Java script\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/java-closure\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-17T04:00:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-22T12:21:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-Closure-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is Java Closure | Java 8 Lambda Expressions - DataFlair","description":"Java Closure tutorial: what is closure in Java, Java 8 Lambda expression, Java 8, how doesJava create closure,Java Closure using mutable objects,Java script","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/java-closure\/","og_locale":"en_US","og_type":"article","og_title":"What is Java Closure | Java 8 Lambda Expressions - DataFlair","og_description":"Java Closure tutorial: what is closure in Java, Java 8 Lambda expression, Java 8, how doesJava create closure,Java Closure using mutable objects,Java script","og_url":"https:\/\/data-flair.training\/blogs\/java-closure\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-06-17T04:00:17+00:00","article_modified_time":"2026-05-22T12:21:37+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-Closure-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/java-closure\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/java-closure\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"What is Java Closure | Java 8 Lambda Expressions","datePublished":"2018-06-17T04:00:17+00:00","dateModified":"2026-05-22T12:21:37+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/java-closure\/"},"wordCount":1149,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/java-closure\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-Closure-01.jpg","keywords":["closures in Java","Does Java create Closures","Java 8 features","Java 8 Lambda Limitations","Java 8 Lamda expression","Java Closures using mutable Objects","Java Script functions","What is Java Closure"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/java-closure\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/java-closure\/","url":"https:\/\/data-flair.training\/blogs\/java-closure\/","name":"What is Java Closure | Java 8 Lambda Expressions - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/java-closure\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/java-closure\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-Closure-01.jpg","datePublished":"2018-06-17T04:00:17+00:00","dateModified":"2026-05-22T12:21:37+00:00","description":"Java Closure tutorial: what is closure in Java, Java 8 Lambda expression, Java 8, how doesJava create closure,Java Closure using mutable objects,Java script","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/java-closure\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/java-closure\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/java-closure\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-Closure-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Java-Closure-01.jpg","width":1200,"height":628,"caption":"what is Java Closure"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/java-closure\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Java Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/java\/"},{"@type":"ListItem","position":3,"name":"What is Java Closure | Java 8 Lambda Expressions"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/19077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=19077"}],"version-history":[{"count":9,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/19077\/revisions"}],"predecessor-version":[{"id":148421,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/19077\/revisions\/148421"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/19103"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=19077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=19077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=19077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}