{"id":279,"date":"2016-12-06T10:28:12","date_gmt":"2016-12-06T10:28:12","guid":{"rendered":"https:\/\/sidroniolima.com.br\/blog\/?p=279"},"modified":"2016-12-14T17:09:00","modified_gmt":"2016-12-14T17:09:00","slug":"lambdas-oracle-mooc","status":"publish","type":"post","link":"https:\/\/sidroniolima.com.br\/blog\/2016\/12\/06\/lambdas-oracle-mooc\/","title":{"rendered":"Lambdas Oracle MOOC"},"content":{"rendered":"\n<div class=\"twitter-share\"><a href=\"https:\/\/twitter.com\/intent\/tweet?via=sidroniolima\" class=\"twitter-share-button\">Tweet<\/a><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/networkengg.com\/wp-content\/uploads\/2015\/12\/lambda-in-python.png\" alt=\"Java 8 Lambda\" width=\"212\" height=\"221\" \/><\/p>\n<h1>Section 1<\/h1>\n<p>&#8211; Need changes to Java to simplify parallel coding.<br \/>\n&#8211; Lambda expressions simplify how to pass behavior as a parameter.<\/p>\n<p>-Show the differences through Java basic code, inner classes and lambdas.<\/p>\n<p>Non-functional (imperative) programming style versus functional.<\/p>\n<p>Problem: external iteration.<br \/>\nAfter: more functional with inner classes;<br \/>\nAnd then: lambda approach, more concise, less code (error-prone), client logic is stateless, thread-safe.<\/p>\n<p>The lambda expression provides the implementation of the abstract method. The type is the abstract method.<\/p>\n<p>@FunctionalInterface -&gt; Functional Interface = an interface with one abstract method; default doesn&#8217;t count. The <em>equals<\/em> also doesn&#8217;t count in therms of abstract method.<\/p>\n<p>Variable assignment: Callable c = () -&gt; process();<\/p>\n<p>Method parameter: mew Thread(() -&gt; process()).start();<\/p>\n<p>Lambda expressions can be used anywhere the type is a functional interface.<\/p>\n<p>&#8211; A functional interface has only one abstract method.<\/p>\n<p>The lambda expression provides the implementation of the single abstract method of the functional interface.<\/p>\n<h3>java.util.function Package<\/h3>\n<h4>Consumer&lt;T&gt;<\/h4>\n<p>Operation that takes a single value and return no result: String s -&gt; System.out.println(s) .<\/p>\n<p><em>Example: String s -&gt; System.out.println(s);<\/em><\/p>\n<h4>BiConsumer&lt;T,U&gt;<\/h4>\n<p>Takes two values and returns no result.<\/p>\n<p><em>Example: (k,v) -&gt; System.out.println(&#8220;key: &#8221; + k + &#8220;, value: &#8221; + v);<\/em><\/p>\n<h4>Supplier<\/h4>\n<p>The opposite of a Consumer. Doesn&#8217;t take any parameter and returns a value.<\/p>\n<p><em>Example: ( ) -&gt; createLogMessage();<\/em><\/p>\n<h4>Function&lt;T,R&gt;<\/h4>\n<p>Takes one argument, do something and returns a result.<\/p>\n<p><em>Example: Student s -&gt; s.getName();<\/em><\/p>\n<h4>BiFunction&lt;T,U,R&gt;<\/h4>\n<p>Takes two arguments and returns a result.<\/p>\n<p><em>Example: (String name, Student s) -&gt; new Teacher(name, student);<\/em><\/p>\n<h4>UnaryOperator&lt;T&gt;<\/h4>\n<p>Kind function: single argument and result of the same type.<\/p>\n<ul>\n<li>T apply(T a)<\/li>\n<\/ul>\n<p><em>Example: String s -&gt; s.toLowerCase();<\/em><\/p>\n<h4>BinaryOperartor&lt;T&gt;<\/h4>\n<p>Specialised form of BiFunction: two arguments and a result, all of the same type.<\/p>\n<ul>\n<li>T apply(T a, T b)<\/li>\n<\/ul>\n<p><em>Example: (String x, String y) -&gt; { if (x.length() &gt; y.length()) return x; return y; }<\/em><\/p>\n<h4>Predicate<\/h4>\n<p>A boolean valued function of one argument:<\/p>\n<p><em>Example: Student s -&gt; s.graduationYear() == 2011<\/em><\/p>\n<h4>BiPredicate<\/h4>\n<p>Takes two arguments<\/p>\n<p><em>Example: (Student s, int minGrade) -&gt; s.grade &lt;= minGrade<\/em><\/p>\n<h3>Method and constructor references<\/h3>\n<p>FileFilter x = (File f) -&gt; f.canRead();<\/p>\n<p>FileFilter x = File::canRead;<\/p>\n<h3>External variables<\/h3>\n<p>Final or effective final.<\/p>\n<h4><span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/apexapps.oracle.com\/pls\/apex\/f?p=44785:145:10040796816707::NO:RP,145:P145_EVENT_ID,P145_PREV_PAGE:5067,2\">Link<\/a> to the on line free Oracle course.<\/span><\/h4>\n\n<div class=\"twitter-share\"><a href=\"https:\/\/twitter.com\/intent\/tweet?via=sidroniolima\" class=\"twitter-share-button\">Tweet<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Section 1 &#8211; Need changes to Java to simplify parallel coding. &#8211; Lambda expressions simplify how to pass behavior as a parameter. -Show the differences through Java basic code, inner classes and lambdas. Non-functional (imperative) programming style versus functional. Problem: external iteration. After: more functional with inner classes; And then: lambda approach, more concise, less [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[27],"tags":[50,51,48,49],"class_list":["post-279","post","type-post","status-publish","format-standard","hentry","category-java","tag-course","tag-lambdas","tag-mooc","tag-oracle"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/posts\/279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/comments?post=279"}],"version-history":[{"count":9,"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/posts\/279\/revisions"}],"predecessor-version":[{"id":303,"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/posts\/279\/revisions\/303"}],"wp:attachment":[{"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/media?parent=279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/categories?post=279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/tags?post=279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}