<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aymen Marouani</title>
    <description>The latest articles on DEV Community by Aymen Marouani (@aymenmarouani).</description>
    <link>https://dev.to/aymenmarouani</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F341446%2F415223d3-d54e-4dc2-9cc0-2246f6a14c00.png</url>
      <title>DEV Community: Aymen Marouani</title>
      <link>https://dev.to/aymenmarouani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aymenmarouani"/>
    <language>en</language>
    <item>
      <title>React Hooks to Tame the Complexity</title>
      <dc:creator>Aymen Marouani</dc:creator>
      <pubDate>Fri, 28 Feb 2020 14:40:57 +0000</pubDate>
      <link>https://dev.to/aymenmarouani/react-hooks-to-tame-the-complexity-15lg</link>
      <guid>https://dev.to/aymenmarouani/react-hooks-to-tame-the-complexity-15lg</guid>
      <description>&lt;p&gt;Hooks are a new feature introduced by React 16.7.0-alpha that allows the use of state (and other features like context, store or life cycle) outside the scope of a class namely in a pure function. React hooks were first introduced (alongside other features like Suspense, Time Slicing and Profiler) to the public in ReactConf 2018 by Sophie Alpert and Dan Abramov (one of the creators of Redux).&lt;/p&gt;

&lt;h2&gt;
  
  
  Motivation and Background
&lt;/h2&gt;

&lt;p&gt;React Hooks are meant to solve some problems and limitations that the React Team in Facebook noticed. We can summarize those limitations in three main problems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;"Wrapper Hell": components as classes tend to clutter in a big intricate hierarchy that has to pass properties between them and encapsulate each other. This can be seen in big projects where extra layers of abstraction wrappers serve to pass properties and extract reusable logic. Things become more complicated when forced to update the structure of the hierarchy by moving component with their wrappers.&lt;/li&gt;
&lt;li&gt;"Giant Component": when creating a component, we need usually to implement its life cycle methods (componentDidMount, compnentWillUnmount ...) and it's hard to separate them from the class, so this will increase component's size when we have to add more logic to them.&lt;/li&gt;
&lt;li&gt;"Hard Classes": a stateless react component written as a function requires more effort to migrate it to a class form. In addition, the React Team noticed that classes are hard to optimize by the compiler.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The above limitations have as source the fact that React doesn't have a smaller unit than the class context to encapsulate statefull behavior. In their way to solve this problem, the React Team opted for the first time to adopt the RFC approach (Request for Comment) and started tackling the root cause (the atomicity of the class) by restraining the solution to the following main criteria:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;"opt-in": the solution must be neither mandatory nor intrusive, i.e. it'll not oblige the current code to adopt them and it can be removed without collateral effect.&lt;/li&gt;
&lt;li&gt;"retro-compatible": don't break the current code. Hooks can live alongside class components.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Introducing React Hooks
&lt;/h2&gt;

&lt;p&gt;Simply a Hook is a function that fetches React context data for the functional component.  In order to enable this feature, we have to import a React version above 16.7.&lt;/p&gt;

&lt;p&gt;Let's consider this simple introductory example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;SimpleHook&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Fragment&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;A&lt;/span&gt; &lt;span class="nx"&gt;Simple&lt;/span&gt; &lt;span class="nx"&gt;Hook&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Increment&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Decrement&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Reset&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/React.Fragment&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mountPoint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;SimpleHook&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mountPoint&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this example creates an increment decrement control on a given integer displayed as a label.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fn6ef41xwc6fn19br7b40.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fn6ef41xwc6fn19br7b40.png" alt="Simple Hook"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example we have a page that uses a single functional component. With Hooks, it has a state accessed by importing the &lt;strong&gt;&lt;code&gt;useState&lt;/code&gt;&lt;/strong&gt; function and initialized using the directive&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We declared both the state and the set-state by calling &lt;strong&gt;&lt;code&gt;useState&lt;/code&gt;&lt;/strong&gt; and passing the initial value 0. Changing the state is done by calling the previously declared state setter&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Increment&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;useState&lt;/code&gt;&lt;/strong&gt; is the simplest Hook and  we have various types, mainly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;useEffect&lt;/code&gt;&lt;/strong&gt;, provided for life cycle behavior implementation (same purpose as componentDidMount, componentWillUnmount)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;useContext&lt;/code&gt;&lt;/strong&gt;, to access React context API (sort of a global state container)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;userReducer&lt;/code&gt;&lt;/strong&gt;, to manage local state using pure functions called reducers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More details on how to use those Hook types in this &lt;a href="https://reactjs.org/docs/hooks-reference.html" rel="noopener noreferrer"&gt;URL&lt;/a&gt;. Custom Hooks can be also defined as shown in this &lt;a href="https://reactjs.org/docs/hooks-custom.html" rel="noopener noreferrer"&gt;section&lt;/a&gt; from React Hook API reference.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Hooks are the new way for React to define elementary function based components by allowing a statefull behavior outside the old class definition. They'll live with the legacy and promote design flexibility and code reuse.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;For more details you can consult the following links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ReactConf 2018 video presentation: &lt;a href="https://www.youtube.com/watch?v=dpw9EHDh2bM" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=dpw9EHDh2bM&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The RFC: &lt;a href="https://github.com/reactjs/rfcs/pull/68" rel="noopener noreferrer"&gt;https://github.com/reactjs/rfcs/pull/68&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Official page entry: &lt;a href="https://reactjs.org/docs/hooks-intro.html" rel="noopener noreferrer"&gt;https://reactjs.org/docs/hooks-intro.html&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Java 11, the Good Parts</title>
      <dc:creator>Aymen Marouani</dc:creator>
      <pubDate>Tue, 25 Feb 2020 14:45:40 +0000</pubDate>
      <link>https://dev.to/aymenmarouani/java-11-the-good-parts-548p</link>
      <guid>https://dev.to/aymenmarouani/java-11-the-good-parts-548p</guid>
      <description>&lt;p&gt;Announced in 25 September 2018, Java 11 is the latest long term support release by Oracle for the Java community. The following is a listing of the most important features and changes:&lt;/p&gt;

&lt;h2&gt;
  
  
  Type inference for Lambda parameters
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;var&lt;/code&gt; key word was introduced in Java 10 to implement local scope variables with dynamic type inference.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;aString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"This is a String"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Java 11, the &lt;code&gt;var&lt;/code&gt; key word can be used to qualify a given lambda parameter&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Predicate&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;notNull&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  HTTP Client
&lt;/h2&gt;

&lt;p&gt;This is known to be an incubating feature from JDK 9. It's a standard API to support HTTP/1, HTTP/2 clients, synchronous, asynchronous and in a reactive-functional style. This being illustrated by the following code from the Oracle HTTP Client Page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;HttpClient&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;HttpClient&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;newHttpClient&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="nc"&gt;HttpRequest&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;HttpRequest&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;newBuilder&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
      &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;URI&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;create&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"http://openjdk.java.net/"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
      &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sendAsync&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;asString&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt;
      &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;thenApply&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;HttpResponse:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
      &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;thenAccept&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;println&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
      &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;join&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  TLS 1.3
&lt;/h2&gt;

&lt;p&gt;Java 11 comes with the implementation of the Transport Layer Security Protocol (TLS) version 1.3. TLS is protocol for providing secured data exchange between two ends of a communication channel. It defines a secure communication channel as having those 3 main criteria:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authentication&lt;/li&gt;
&lt;li&gt;Confidentiality&lt;/li&gt;
&lt;li&gt;Integrity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;TLS 1.3 consists of two main specifications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Communication establishment, aka Handshake phase management, where the two peers negotiates the security of the exchange via key exchange and cryptographic algorithms&lt;/li&gt;
&lt;li&gt;Data Exchange phase, aka Record Protocol where the traffic is considered as a transit of records protected by the parameters from the first phase.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Enough as a digression, please see the link in the References paragraph for more. The JDK steering committee included the TLS 1.3 implementation because of its robustness as a security protocol and to keep competitive with other vendors implementing it. Following suit, the TLS implementation includes various cryptographic algorithms for signature and encryption.&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance related features
&lt;/h2&gt;

&lt;p&gt;JDK 11 put a big deal on performance enhancement and tooling. Aware of the fact that Garbage Collection is the pivotal point for Java performance, the following features were introduced for GC:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ZGC&lt;/code&gt;&lt;/strong&gt;: although experimental, the ZGC promises low latency time (less than 10ms) and wide range of memory size support (from hundred of megabytes to terabytes). It's only available for Linux x64.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Epsilon GC&lt;/code&gt;&lt;/strong&gt;: a generous GC that allocates memory without reclaiming it. Useful for performance testing and short living Java processes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Performance tools have a lion share in this release:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Low Overhead Heap Profiling&lt;/code&gt;&lt;/strong&gt;: offers a non intrusive way to monitor Java memory heap allocation. It's in fact a programmatic native API available for the JVMTI (JVM Tooling Interface) to get information about object on the Heap.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Java Flight Recorder&lt;/code&gt;&lt;/strong&gt;: an important tool for low overhead performance data troubleshooting and collection. It produces dump data that can be red by Java Mission Control tool. In a nutshell, we start the tool on the command line as the following
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;jcmd &amp;lt;pid&amp;gt; JFR.start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where &lt;code&gt;pid&lt;/code&gt; is the process id of an already running java application. To specify the dump process file that will record the application's performance status use the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;jcmd &amp;lt;pid&amp;gt; JFR.dump &lt;span class="nv"&gt;filename&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;recording.jfr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To stop the recording, issue the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;jcmd &amp;lt;pid&amp;gt; JFR.stop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and the produced file can be imported by other profiling tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deprecation and removal of some features from the JDK
&lt;/h2&gt;

&lt;p&gt;JavaFx is no more a part of the JDK, it's a separate download. Oracle stopped providing 32bit binaries and auto updates via Server JRE.&lt;br&gt;
The following modules are removed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Corba&lt;/li&gt;
&lt;li&gt;JAXB, JAX-WS, JAF and Common Annotations&lt;/li&gt;
&lt;li&gt;Nashorn JavaScript Engine is being deprecated&lt;/li&gt;
&lt;li&gt;The packing suit of Java WebStart and Java Plugin&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For Corba and the other J2EE modules (like JAXB and JAX-WS) the removal was justified by the fact that they can evolve and be maintained outside the JDK sphere and it becomes more and more difficult to sync the changes.&lt;/p&gt;
&lt;h2&gt;
  
  
  Minor Features
&lt;/h2&gt;

&lt;p&gt;With JDK 11 comes the support for Unicode 10 which means we can print emojies. Another feature is the possibility to execute single java file programs in one pass by calling&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;java OneClassFileProgram.java
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;instead of the usual sequence (javac then java). Under the hood, no class file on the disc, all in memory.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Main feature page: &lt;a href="http://openjdk.java.net/projects/jdk/11"&gt;http://openjdk.java.net/projects/jdk/11&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Oracle migration guide: &lt;a href="https://docs.oracle.com/en/java/javase/11/migrate/index.html"&gt;https://docs.oracle.com/en/java/javase/11/migrate/index.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Oracle HTTP Client: &lt;a href="http://openjdk.java.net/groups/net/httpclient/recipes-incubating.html"&gt;http://openjdk.java.net/groups/net/httpclient/recipes-incubating.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;TLS 1.3: &lt;a href="https://tools.ietf.org/html/rfc8446"&gt;https://tools.ietf.org/html/rfc8446&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>Project Loom: Java on Fiber</title>
      <dc:creator>Aymen Marouani</dc:creator>
      <pubDate>Tue, 25 Feb 2020 14:06:41 +0000</pubDate>
      <link>https://dev.to/aymenmarouani/project-loom-java-on-fiber-hl</link>
      <guid>https://dev.to/aymenmarouani/project-loom-java-on-fiber-hl</guid>
      <description>&lt;p&gt;With Java 9 came a whole bunch of ambitious projects to modernize the Java language and enhance the JVM performance; one of these projects is the &lt;strong&gt;&lt;code&gt;Project Loom&lt;/code&gt;&lt;/strong&gt; which tackled the multithreading model offered by the JDK. According to &lt;a href="https://openjdk.java.net/projects/loom/"&gt;the project's page&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The goal of this Project is to explore and incubate Java VM features and APIs built on top of them for the implementation of lightweight user-mode threads (fibers), delimited continuations (of some form), and related features, such as explicit tail-call.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This statement seems not clear for anyone who used the page as the only source to be introduced to the subject of this still incubated and promising feature, but the project was announced in notorious tech conferences mainly Devoxx Belgium in 2018 and before that in an Oracle Java event in 2017. The purpose of this article is to clarify the underlying and the future enhancements expected from this important, yet under development, project. Please note that the code excerpts are taken as it from the project page and are not in a final state.&lt;/p&gt;

&lt;h2&gt;
  
  
  Motivation Behind
&lt;/h2&gt;

&lt;p&gt;For any serious production ready Java code, concurrency comes as a prominent feature. Failing to fulfill concurrency and parallelism dooms the usability of the final product although its functional facet may be near perfection. In other words, real life Java applications must deal with multi-users, multi-resources, concurrent access and sporadic calls. For that reason, Java offers a threading model conform to the low level basic concurrency patterns and principles (locks, concurrent data structures, join-yield calls, etc...). Given this, implementing asynchronous and concurrent proof code presents the challenge of being an art apart and a burden for maintenance. A top of this, we have to use external libraries to manage Thread Pools in Java. So here comes the need to make the threading API in Java more accessible to the users via a user mode threads (called fibers) unlike the low level standard threads.&lt;/p&gt;

&lt;h2&gt;
  
  
  fiber = continuation + scheduler
&lt;/h2&gt;

&lt;p&gt;The main idea is to use simply manageable user level threads called &lt;strong&gt;&lt;code&gt;Fibers&lt;/code&gt;&lt;/strong&gt;. Fibers are user mode thread which means that they are created and managed by the JVM unlike the normal Threads spawn by the OS via the JVM system calls. But before explaining more the concept of fibers, let's understand the concept of &lt;strong&gt;&lt;code&gt;Continuation&lt;/code&gt;&lt;/strong&gt;. After all, the Project Loom is introducing three concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fibers&lt;/li&gt;
&lt;li&gt;Continuation&lt;/li&gt;
&lt;li&gt;Tail-calls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Forget, for the moment, about the last concept (&lt;strong&gt;&lt;code&gt;tail-calls&lt;/code&gt;&lt;/strong&gt;) as it's not yet developed. To those days, the first two concepts are almost ready.&lt;br&gt;
Fibers are based on the concept of continuation; a &lt;strong&gt;&lt;code&gt;Continuation&lt;/code&gt;&lt;/strong&gt; is a demarcation of a flow of execution to allow the play-pause actions. In other words, a continuation allows us to design a piece of code to be started, paused, and then restarted again from its previously stopped point. The prototype for this class is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;_Continuation&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;_Continuation&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_Scope&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Runnable&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="n"&gt;_Continuation&lt;/span&gt; &lt;span class="nf"&gt;suspend&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_Scope&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Consumer&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;_Continuation&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ccc&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;getStackTrace&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UsQUQ4EZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y6jwmk00wxyu4zzl27sc.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UsQUQ4EZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y6jwmk00wxyu4zzl27sc.jpg" alt="Java Fibers"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So how continuation is related to the fibers? In fact, fibers are meant to be attached to one thread according to this logic:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A flow of execution, meant to be concurrent and parallalised, is wrapped by a continuation.&lt;/li&gt;
&lt;li&gt;When starting the concurrency process, the JVM instantiates as many copies of this demarked continuation as needed.&lt;/li&gt;
&lt;li&gt;One thread is then spawn and it will carry the execution of one continuation instance.&lt;/li&gt;
&lt;li&gt;When preempted (by a blocking call or by an interruption), the call stack of this continuation is removed from the thread's stack and saved apart to mark the paused execution, this is called &lt;strong&gt;&lt;code&gt;parking&lt;/code&gt;&lt;/strong&gt;, and the thread can execute another code.&lt;/li&gt;
&lt;li&gt;When needed, the execution resumes by pushing again the saved continuation call stack (&lt;strong&gt;&lt;code&gt;un-parking&lt;/code&gt;&lt;/strong&gt;) onto the threads stack and continue from there.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;From the above we can see that a thread can hold the execution of multiple fibers and, according to the authors, the already existing scheduler of type &lt;strong&gt;&lt;code&gt;ForkJoinPool&lt;/code&gt;&lt;/strong&gt; is suitable for this schema of execution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;_Fiber&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;_Continuation&lt;/span&gt; &lt;span class="n"&gt;cont&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;Executor&lt;/span&gt; &lt;span class="n"&gt;scheduler&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;volatile&lt;/span&gt; &lt;span class="nc"&gt;State&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;Runnable&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;​&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;enum&lt;/span&gt; &lt;span class="nc"&gt;State&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="no"&gt;NEW&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LEASED&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="no"&gt;RUNNABLE&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="no"&gt;PAUSED&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="no"&gt;DONE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;_Fiber&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Runnable&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Executor&lt;/span&gt; &lt;span class="n"&gt;scheduler&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;scheduler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scheduler&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;cont&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;_Continuation&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_FIBER_SCOPE&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;NEW&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;task&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
              &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;cont&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;park0&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt;
                     &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// parking; otherwise, had lease -- continue&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;
              &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;DONE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;};&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;casState&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;NEW&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;RUNNABLE&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalStateException&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;scheduler&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;execute&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;park&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_Continuation&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;suspend&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_FIBER_SCOPE&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;park0&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;State&lt;/span&gt; &lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nst&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;st&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
              &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;LEASED:&lt;/span&gt;   &lt;span class="n"&gt;nst&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;RUNNABLE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
              &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;RUNNABLE:&lt;/span&gt; &lt;span class="n"&gt;nst&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;PAUSED&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;   &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
              &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;       &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;IllegalStateException&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;casState&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nst&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;nst&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;PAUSED&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;unpark&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;State&lt;/span&gt; &lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nst&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;State&lt;/span&gt; &lt;span class="n"&gt;st&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
              &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;LEASED:&lt;/span&gt; 
              &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;RUNNABLE:&lt;/span&gt; &lt;span class="n"&gt;nst&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;LEASED&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;   &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
              &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;PAUSED:&lt;/span&gt;   &lt;span class="n"&gt;nst&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;RUNNABLE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
              &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;       &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;IllegalStateException&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;casState&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nst&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nst&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;RUNNABLE&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;scheduler&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;execute&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;casState&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;State&lt;/span&gt; &lt;span class="n"&gt;oldState&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;State&lt;/span&gt; &lt;span class="n"&gt;newState&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;  
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Advantages and Limitations
&lt;/h2&gt;

&lt;p&gt;Advantages of this approach are mainly less memory overhead (some 100Kb against 1Mb for threads), reduced context switching time between tasks and a simple threading model.&lt;br&gt;
The main limitations reside in the management of thread stacks containing native methods calls and the impact on the existing concurrent APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The project main page: &lt;a href="https://openjdk.java.net/projects/loom"&gt;https://openjdk.java.net/projects/loom&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The Proposal: &lt;a href="http://cr.openjdk.java.net/%7Erpressler/loom/Loom-Proposal.html"&gt;http://cr.openjdk.java.net/~rpressler/loom/Loom-Proposal.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Belgium 2018 Devoxx Talk: &lt;a href="https://www.youtube.com/watch?v=vbGbXUjlRyQ"&gt;https://www.youtube.com/watch?v=vbGbXUjlRyQ&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Oracle Talk: &lt;a href="https://www.youtube.com/watch?v=J31o0ZMQEnI"&gt;https://www.youtube.com/watch?v=J31o0ZMQEnI&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>WebAssembly, a Web without JavaScript</title>
      <dc:creator>Aymen Marouani</dc:creator>
      <pubDate>Tue, 25 Feb 2020 10:02:18 +0000</pubDate>
      <link>https://dev.to/aymenmarouani/webassembly-a-web-without-javascript-1pi8</link>
      <guid>https://dev.to/aymenmarouani/webassembly-a-web-without-javascript-1pi8</guid>
      <description>&lt;p&gt;According to &lt;a href="https://webassembly.org/"&gt;the official site&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based   virtual machine. Wasm is designed as a portable target for compilation of high- level languages like C/C++/Rust, enabling deployment on the web for client and server applications.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In a nutshell, it's a technology that allows code written in other languages; mainly C/C++ and Rust; to be executed by a VM embedded in the browser as a low level byte code.&lt;/p&gt;

&lt;h2&gt;
  
  
  History
&lt;/h2&gt;

&lt;p&gt;The idea behind Wasm is not new, some precursors existed like Google Native Client and asm.js, we perhaps remember the Java Applets. Wasm started as a project by Mozilla and was announced in June 2015. The first PoC was in March 2016 and consisted on a Unity game running on FireFox.  By 2017, the majority of the browsers including Chrome, Safari and Edge implemented the Wasm VM. In February 2018, Wasm was adopted as W3C standard as the Javascript core specification and Api have been published by a group of engineers from Mozilla, Microsoft, Google and Apple.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design and Main Ideas
&lt;/h2&gt;

&lt;p&gt;The de facto language for the Web is JavaScript, a high level interpreted programming language executed by various engines like V8 in Chrome, SpiderMonkey in FireFox and Chakra in IE. Besides that, JavaScript is weakly typed and dynamic. The previous facts imply that JavaScript is not an ideal language for performance for the following reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The process of interpretation leads to the time consuming process of parsing and processing the code before executing it.&lt;/li&gt;
&lt;li&gt;Byte code generation for the engine is usually optimized by a technique called JIT (Just in Time) compilation where parts of code are analyzed (profiled precisely) to spot frequently used parts to be precompiled as a "compilation cache". Although the apparent performance gains, profiling can add overhead to the code execution life cycle.&lt;/li&gt;
&lt;li&gt;Being weakly typed and dynamic leads to an additional effort of inferring variable types and scopes which add more processing time.&lt;/li&gt;
&lt;li&gt;Finally, GC and mono-threading will make things all but faster.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OcVXrH7p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x1bxz1lbjlqa9lh8r9l1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OcVXrH7p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x1bxz1lbjlqa9lh8r9l1.png" alt="V8 engine overview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Being not well suited for performance is not a major issue for the JavaScript programming language as the majority of Web related coding is frequently limited to DOM manipulation, regular expression parsing or GUI component instantiation and lifecycle management. But when it comes to some more intensive tasks like running a 3D game or a Virtual Reality scene, media streaming or even high performance large DOM manipulation; certainly JavaScript will not be the first choice. Those performance demanding tasks are already coded in the low level language C/C++ and are well proven, so the idea was to be able to integrate the already coded high performance C/C++ libraries (like OpenGL for 3D rendering) on the Web page. In other words, porting a high-performance code to the browser.&lt;br&gt;
WebAssembly made this possible by adopting a compiled byte code from an already existing C/C++ or Rust code. This already compiled byte code will be executed by a stack based virtual machine supported by the browser. Wasm Specification consists of those two main parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A byte code specification for the stack base VM to implement.&lt;/li&gt;
&lt;li&gt;A JavaScript API to allow any Wasm code to call or access its surrounding environment (DOM, passing arguments).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IuC_6c-O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xetji617g9ol2ayxrnkm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IuC_6c-O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xetji617g9ol2ayxrnkm.jpg" alt="Wasm vs JavaScript"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tools and Usage
&lt;/h2&gt;

&lt;p&gt;WebAssembly tooling is based on EmScripten, the main goal of those tools is to take a C/C++ source code and generate a Wasm module in addition to a JavaScript "glue" to make the module readable by  the browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HhPNUKyU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4pqw0z197rmp2xypup5q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HhPNUKyU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4pqw0z197rmp2xypup5q.png" alt="Wasm typical flow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A typical flow for C/C++ source code (factorial in this example) will involve the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generating a Wasm module by calling:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;emcc factorial.c &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="nv"&gt;WASM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 &lt;span class="nt"&gt;-o&lt;/span&gt; factorial.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Running the resulting Wasm module and JavaScript glue code:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;emrun &lt;span class="nt"&gt;--no_browser&lt;/span&gt; &lt;span class="nt"&gt;--port&lt;/span&gt; 8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Future Road Map
&lt;/h2&gt;

&lt;p&gt;Although accepted as W3C standard, the committee has planned the following features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Threading and concurrency, provide a p-thread like environment execution, shared memory and mutexes.&lt;/li&gt;
&lt;li&gt;Garbage collection, allocate and manipulate GC objects from Wasm code.&lt;/li&gt;
&lt;li&gt;Exception handling, full implementation of C++ style exception handling.&lt;/li&gt;
&lt;li&gt;Bulk memory operations, copying and clearing large chunks of memory with an efficient architecture independent way.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;WebAssembly is a technology meant to integrate high-performance portable C/C++ code (or even other languages like Rust) into the JavaScript Web context in order to extend its capabilities to run highly demanding features like 3D or image and video processing.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;For more details you can consult the following links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Official page: &lt;a href="https://webassembly.org"&gt;https://webassembly.org&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;W3C entry: &lt;a href="https://www.w3.org/community/webassembly"&gt;https://www.w3.org/community/webassembly&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webassembly</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
