<?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 Java Beginners Tutorial on Medium]]></title>
        <description><![CDATA[Stories by Java Beginners Tutorial on Medium]]></description>
        <link>https://medium.com/@admin_76350?source=rss-3cb8d7ec9c33------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*9Qe_83QrU6x5kaF9WorBrQ.jpeg</url>
            <title>Stories by Java Beginners Tutorial on Medium</title>
            <link>https://medium.com/@admin_76350?source=rss-3cb8d7ec9c33------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 14:44:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@admin_76350/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[Switch case statement in Java]]></title>
            <link>https://medium.com/@admin_76350/switch-case-statement-in-java-5de8fa4a5f44?source=rss-3cb8d7ec9c33------2</link>
            <guid isPermaLink="false">https://medium.com/p/5de8fa4a5f44</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java12]]></category>
            <dc:creator><![CDATA[Java Beginners Tutorial]]></dc:creator>
            <pubDate>Sat, 09 Nov 2019 13:42:04 GMT</pubDate>
            <atom:updated>2019-12-03T02:45:44.446Z</atom:updated>
            <content:encoded><![CDATA[<p>Java 12 has enhanced <a href="https://javabeginnerstutorial.com/core-java-tutorial/switch-case-statement-in-java/"><strong>Switch expressions</strong></a> for Pattern matching. It extends the switch statement so that it can be used as either a statement or an expression. In this article, we will talk about Switch statement and a <a href="https://javabeginnerstutorial.com/core-java-tutorial/java-12-new-features/">new feature added in Java 12.</a></p><p>A switch statement is a conditional statement that tests against multiple cases and displays one or multiple outputs based on the matching circumstances. Unlike if-then and if-then-else statements, the switch statement can work with byte, short, char, and int primitive data types. It also works with <em>enum types</em> (discussed in <a href="https://javabeginnerstutorial.com/core-java-tutorial/java-enum-enumerations/">Java Enum</a>), the class, and a few wrapper classes: Character, Byte, Short, and Integer.</p><h3>Important Rules</h3><ul><li>Only constants or literals are allowed in case</li><li>Duplicate values in the case are not allowed</li><li>the default statement is optional, and it can appear anywhere in switch body not necessarily in the end</li><li>the break statement is optional, and if not used, execution will move to the next statement.</li><li>Make sure that the expression in any switch statement is not null to prevent a NullPointerException from being thrown.</li></ul><h3>Syntax of a switch statement</h3><pre>switch(expression)<br>{<br>   case value1 :<br>      &lt;&lt;CODE_TO_EXECUTE&gt;&gt;<br>      break;<br>   default : <br>      &lt;&lt;CODE_TO_EXECUTE&gt;&gt;   <br>   case value2 :<br>      &lt;&lt;CODE_TO_EXECUTE&gt;&gt;<br>}</pre><h3>Example code of Switch statement</h3><pre>public class switch_statement {</pre><pre>public static void main(String[] args) {</pre><pre>int weekday = 10;<br>        String weekdayString;<br>        // switch statement with int data type<br>        switch (weekday) {<br>            case 1:<br>                weekdayString = &quot;Sunday&quot;;<br>                break;<br>            case 2:<br>                weekdayString = &quot;Monday&quot;;<br>                break;<br>// default statement can be anywhere. Not necessarily in the end only<br>            default:<br>                weekdayString = &quot;Not a weekday&quot;;<br>                break;<br>            case 3:<br>                weekdayString = &quot;Tuesday&quot;;<br>                break;<br>            case 4:<br>                weekdayString = &quot;Wednesday&quot;;<br>                break;<br>            case 5:<br>                weekdayString = &quot;Thursday&quot;;<br>                break;<br>            case 6:<br>                weekdayString = &quot;Friday&quot;;<br>                break;<br>            case 7:<br>                weekdayString = &quot;Saturday&quot;;<br>                // break is not required for last case<br>        }<br>        System.out.println(weekdayString);<br>    }<br>}</pre><h3>Use of break statement</h3><p>Though the break statement is optional. It plays an important role in controlling the execution flow. If we don’t use it, execution will continue to the next case. Sometimes it is desirable to have multiple cases without break statements between them. Especially when you want to perform the same action for more than one case.</p><pre>public class switch_statement {</pre><pre>public static void main(String[] args) {<br>        boolean isWeekend = false;<br>        int weekday = 5;<br>        switch (weekday) {<br>            /*<br>             * Two cases can be combined in different ways. <br>             * Either by writing case 1,7 <br>             * or <br>             * case 1:<br>             * case 2:<br>             * Both are valid. Though i prefer first option. :)<br>             */<br>            case 1, 7:<br>                isWeekend = true;<br>                break;<br>            case 2:<br>            case 3:<br>            case 4:<br>            case 5:<br>            case 6:<br>                isWeekend = false;<br>        }<br>        System.out.println(&quot;Is it Weekend ? &quot; + isWeekend);<br>    }<br>}</pre><h3>Java 7 switch case string</h3><p>In Java SE 7 and later, you can use a String object in the switch statement&#39;s expression. Please note that String.equals() method is used to compare the switch expression with expression associated with each case label. There is no direct way of comparing the string ignoring case. To do so, follow below practice. Please see below example</p><pre>public class switch_statement {<br><br>    public static void main(String[] args) {<br>        String weekdayString = &quot;Friday&quot;;<br>        int weekdayInt;<br><br>        switch (weekdayString.toUpperCase()) {<br>            case &quot;SUNDAY&quot;:<br>                weekdayInt = 1;<br>                break;<br>            case &quot;MONDAY&quot;:<br>                weekdayInt = 2;<br>                break;<br>            default:<br>                weekdayInt = 0;<br>                break;<br>            case &quot;TUESDAY&quot;:<br>                weekdayInt = 3;<br>                break;<br>            case &quot;WEDNESDAY&quot;:<br>                weekdayInt = 4;<br>                break;<br>            case &quot;THURSDAY&quot;:<br>                weekdayInt = 5;<br>                break;<br>            case &quot;FRIDAY&quot;:<br>                weekdayInt = 6;<br>                break;<br>            case &quot;SATURDAY&quot;:<br>                weekdayInt = 7;<br>        }<br>        System.out.println(weekdayInt + &quot; DAY OF THE WEEK&quot;);<br>    }<br>}</pre><h3>Java 12 switch statement</h3><p>In Java 12, an extended switch statement has been added so that it can be used as either a statement or an expression. Before Java 12, switch was only used as a statement to control the flow. After Java 12, switch can be used as expression too, which means now switch can be evaluated to get the exact value like tertiary operator.</p><p>This change not only simplifies the coding but also prepares the way for the use of pattern matching in the switch. Statement and expression form can use either traditional caselabels (e.g. case 1:) (with fall through) or simplified case labels ( e.g. case -&gt; 1) (no fall through).</p><p>With the new extended switch statement, we no longer use a colon, but arrow syntax from the lambda expression. Also, the break keyword is not required anymore and the fall-through case will not happen. Whatever is on the right side of -&gt; will get executed. If you want to evaluate multiple statements at the same time in a case you can do this with blocks {}.</p><p>We can utilize the extended switch statement to re-write the above code.</p><pre>public class switch_statement {<br><br>    public static void main(String[] args) {<br>        int weekday = 1;<br>        &lt;em&gt;switchExtendedVersion&lt;/em&gt;(weekday);<br>    }<br><br>    private static void switchExtendedVersion(int weekday) {<br>// Switch expression is used to assign the result value to local variable<br>        boolean isWeekend = switch (weekday) {<br>            case 1, 7 -&gt; {<br>                System.&lt;em&gt;out&lt;/em&gt;.println(&quot;Multiple statement evaluation test&quot;);<br>                break true;<br>            }<br>            /*<br>             * Here default is mandated by compiler.<br>             * As &#39;switch&#39; expression needs to cover all possible values.<br>             */<br>            default -&gt; throw new IllegalStateException(&quot;Unexpected value: &quot; + weekday);<br>            case 2, 3, 4, 5, 6 -&gt; false;<br>            case 9 -&gt; true;<br>        };<br>        System.&lt;em&gt;out&lt;/em&gt;.println(&quot;Is it Weekend ? &quot; + isWeekend);<br>    }<br>}</pre><p>Here default case is mandated by the java compiler as an extended switch statement is supposed to cover all possible values. For the old switch statement default case is purely optional.</p><p>Java 12 introduces switch expressions as a preview language feature. That means it can change over the next few releases. And this feature needs to enabled at compile time and run time, with the new command-line option -enable-preview…</p><p><em>Originally published at </em><a href="https://javabeginnerstutorial.com/core-java-tutorial/switch-case-statement-in-java/"><em>https://javabeginnerstutorial.com</em></a><em> on November 9, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5de8fa4a5f44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[1. Hello World with Vue.js]]></title>
            <link>https://medium.com/@admin_76350/1-hello-world-with-vue-js-9404645ac71a?source=rss-3cb8d7ec9c33------2</link>
            <guid isPermaLink="false">https://medium.com/p/9404645ac71a</guid>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Java Beginners Tutorial]]></dc:creator>
            <pubDate>Fri, 27 Jul 2018 04:46:42 GMT</pubDate>
            <atom:updated>2018-08-12T15:29:30.890Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi, Rockstars (Music not included though)! Excited to dive into the World of Vue.js? Then what are we waiting for?!</p><p><em>Good News: </em>It is laughably simple to get started with Vue.</p><p>Let us keep our <strong><em>GOAL</em></strong> pretty simple today. Following the age-old tradition, let us aim to display the message, “Hello World” on our webpage using Vue.</p><h3>Environment Set Up</h3><p>Since we have decided to keep everything simple, why not use <strong>CDN</strong> which is basically importing Vue.js from another server. Later in this tutorial series, we will be using a more complex set up with Vue CLI and Webpack to bundle all our files. But for now, to just practice, understand and learn the basics of Vue, CDN will do. And yes, you can use this simple set up for very small projects as well.</p><h3>Option 1:</h3><pre>&lt;!-- development version --&gt; &lt;script src=&quot;https://cdn.jsdelivr.net/npm/<a href="https://javabeginnerstutorial.com/cdn-cgi/l/email-protection">[email protected]</a>/dist/vue.js&quot;&gt;&lt;/script&gt; &lt;!-- production version --&gt; &lt;script src=&quot;https://cdn.jsdelivr.net/npm/<a href="https://javabeginnerstutorial.com/cdn-cgi/l/email-protection">[email protected]</a>&quot;&gt;&lt;/script&gt;</pre><h3>Option 2:</h3><p>Vue is also available on unpkg,</p><pre>&lt;script src=&quot;https://unpkg.com/<a href="https://javabeginnerstutorial.com/cdn-cgi/l/email-protection">[email protected]</a>/dist/vue.js&quot;&gt;&lt;/script&gt;</pre><p>Version 2.5.16 is the latest at the time of writing this article. It is recommended to include the specific version number in the URL. You can edit the version manually to the latest one in use.</p><p>But if you don’t want to mention the version and use the latest, just go ahead with,</p><pre>&lt;script src=&quot;https://cdn.jsdelivr.net/npm/<a href="https://javabeginnerstutorial.com/cdn-cgi/l/email-protection">[email protected]</a>/dist/vue.js&quot;&gt;&lt;/script&gt; &lt;script src=&quot;https://cdn.jsdelivr.net/npm/vue&quot;&gt;&lt;/script&gt; &lt;!-- or --&gt; &lt;script src=&quot;https://unpkg.com/vue/dist/vue.js&quot;&gt;&lt;/script&gt;</pre><h3>Option 3:</h3><p>You can <a href="https://vuejs.org/v2/guide/installation.html">download the development or production versions</a> of Vue.js to your local and include them directly using the &lt;script&gt; tags in the HTML file.</p><p><strong><em>Sticky Note:</em></strong><em> Development version consists of console warnings that can be very useful for debugging. Whereas, the production version is mainly optimized for size (by using minified versions of the vue.js file etc.) and speed which becomes very important when publishing in live environment.</em></p><h3>Initial Code</h3><p>I am using Visual Studio Code as the IDE. You can use Sublime Text, WebStorm, Atom, Notepad++ or any other IDE of your choice. <strong>My advice?</strong> Please go with <a href="http://jsfiddle.net/"><strong><em>JS Fiddle</em></strong></a> because you can just concentrate on the code and forget about creating each file and linking them with &lt;script&gt; tags. And that is just the icing on the cake. The best part is, you can view HTML, CSS, JS and the output on a single screen. Unlike the browser where you have to refresh it every single time for changes to get reflected, JS fiddle detects the changes and renders the output automatically in the “Result” pane.</p><p>Create an HTML file, “index.html” with the following code,</p><pre>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Hello Vue!&lt;/title&gt; &lt;!-- including Vue with development version CDN --&gt; &lt;script src=&quot;https://cdn.jsdelivr.net/npm/vue/dist/vue.js&quot;&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id=&quot;app&quot;&gt; &lt;h1&gt;Hello World!&lt;/h1&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt;</pre><p>The code is pretty simple. We are giving the page a title, “Hello Vue!” and including the development version of vue.js using CDN with &lt;script&gt; tags in the &lt;head&gt; section. We are displaying “Hello World!” message within &lt;h1&gt; tags inside a &lt;div&gt; element with an id=”app” in the &lt;body&gt; section.</p><p>The current output in Chrome browser is as follows,</p><p>With me so far? Okay, I hear you say that we have rendered “Hello World!” with &lt;h1&gt; tags but isn’t that contradicting with our original goal of using Vue.js to display that?! <strong><em>Good question.</em></strong></p><h3>Let us answer that now,</h3><h3>Step 1: Create a new Vue instance</h3><p>We have imported Vue.js in our project using &lt;script&gt; tags but that doesn’t do the magic. It is equivalent to having a laptop on our work table. To switch it ON and get some work done, we have to press the power button. Similarly, to use Vue in our project, we have to create an instance of the Vue object using the new keyword. This instance is Vue’s power button!</p><pre>new Vue();</pre><h3>Step 2: Passing options object</h3><p>Just creating an instance only powers Vue. But we want to do a lot more <em>with</em> Vue. For that, we have to pass options or config object as an argument to the instance that we just created. This options object has some reserved properties that Vue will recognize and they are specified as <strong>key-value pairs</strong>. As the name suggests, not all properties are required and can be specified as the need arises. Mostly they are used to store data and perform certain actions.</p><p><strong>e.g.</strong>: “el”, “data”, “methods” etc.</p><pre>new Vue({ options/config object });</pre><h3>Step 3: Establishing a connection to the DOM</h3><p>We want to somehow grab the control of a part of the HTML code that we wish to manipulate. In our case, it would be the &lt;div&gt; element with the id, “app”, so that we can display the message “Hello World” through Vue.</p><p>To establish this connection between the Vue instance and a part of the DOM so that it can be controlled as per our needs, we have a reserved property named “el” which translates to an <em>element</em>. This property takes a string as the value which is specified as a CSS selector i.e. “#” for id and “.” for class.</p><pre>new Vue({ el: &quot;#app&quot; });</pre><p>With this simple line of code, our &lt;div&gt; element with id, “app” along with its content are now linked to the Vue instance. They are now <em>inseparable</em>!</p><h3>Step 4: Specifying our data</h3><p>To store all the data/information we would like to work within this Vue instance and its linked DOM, we have another reserved property named, “data”. Unlike “el”, “data” takes an object as its value. Since we want to display the message “Hello World” to our DOM, let us specify that in the “data” object as a key-value pair.</p><pre>new Vue({ el: &quot;#app&quot;, data: { message: &quot;Hello World&quot; } });</pre><h3>Step 5: Rendering this data to the DOM</h3><p>Just use two curly braces as shown below to render the value specified in the data object of the Vue instance to the DOM. (More on this in our next article!)</p><pre>&lt;div id=&quot;app&quot;&gt; &lt;h1&gt;{{ message }}&lt;/h1&gt; &lt;/div&gt;</pre><p>To differentiate the previous output (without Vue), with the one using Vue, let us display “<strong>Hello World!!!</strong>” instead of “Hello World!”.</p><p>Yay! We have thereby created our very first Vue app. All the code discussed as part of this post is available in the <a href="https://github.com/JBTAdmin/vuejs/tree/master/01_Hello%20World%20with%20Vuejs">GitHub repo</a>.</p><p>Have a great day!</p><p><em>Originally published at </em><a href="https://javabeginnerstutorial.com/js/vue-js/1-hello-world-with-vue-js/"><em>javabeginnerstutorial.com</em></a><em> on July 27, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9404645ac71a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hey Vue? What’s up? What’s the deal?]]></title>
            <link>https://medium.com/@admin_76350/hey-vue-whats-up-what-s-the-deal-ec331a54e288?source=rss-3cb8d7ec9c33------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec331a54e288</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vue]]></category>
            <dc:creator><![CDATA[Java Beginners Tutorial]]></dc:creator>
            <pubDate>Sat, 21 Jul 2018 05:00:45 GMT</pubDate>
            <atom:updated>2018-08-12T01:19:25.511Z</atom:updated>
            <content:encoded><![CDATA[<p>You guessed it right. In this Vue Js tutorial, We are going to talk about Vue.js. A lot! Just pronounce it like the word, “view”.</p><h3>What is Vue.js?</h3><p>In simple words, <em>Vue is a </em><strong><em>progressive JavaScript framework</em></strong> for building <strong><em>user interfaces</em></strong> on the web. You might be thinking why you should learn yet another JavaScript framework when there are already the big ones like Angular, React, Ember, etc. There are a lot of differentiating factors here and one of them is, Vue being a progressive framework.</p><p>More on the<strong> progressive framework </strong>part — Vue is incrementally adoptable. That is, it adapts from being a core library that just focuses on the view layer to an entire framework with an ecosystem of supporting libraries and packages based on a project’s inherent complexity. Vue can thus easily tackle the complexities of sophisticated SPAs (Single Page Applications). Here is an <a href="https://github.com/vuejs/awesome-vue#components--libraries">exhaustive list</a> of supporting libraries.</p><p>For example, you can just use Vue in one part of the application (view layer) to provide an interactive experience. Or, maybe you decide to solve other common front-end needs such as state management, routing, fetching data, scaffolding, hot-reloading etc., Vue has the ecosystem required to scale. So, it is a framework that you can progressively opt-in to.</p><p>Since Vue has a lean core that works well alone and is mostly focused on declarative view rendering (which we will be looking into in our upcoming articles) and component composition, it is fairly easy for developers with intermediate knowledge on HTML, CSS, and JavaScript to jump right in and get started. It can be easily embedded into existing front-end code.</p><p>It is approachable (with time-travel debugging, hot-reloading, components etc.), versatile, performant, maintainable, and testable as well.</p><p>Some of the <strong>notable Vue.js concepts</strong> that differentiate it from other JavaScript frameworks are,</p><ol><li><strong>Reactivity</strong> — Keeping the state and view in sync</li><li><strong>Components</strong> — Reusable Vue instances to structure complex interfaces</li><li><strong>Modularity</strong> — Each component along with its HTML, CSS, and JavaScript can be made modular</li><li><strong>Animations</strong> — Vue has a built-in transition system</li><li>SPA routing, state management, project scaffolding, browser DevTools extension, etc. — We have vue-router, vuex, vue-cli, vue-devtools respectively!</li></ol><h3>Browser Compatibility</h3><p>Vue.js supports all browsers that are <a href="http://kangax.github.io/compat-table/es5/">ES5-compliant</a> (IE8 and below are not supported) — as per the official vue.js GitHub page.</p><h3>Comparison with other big frameworks</h3><p>It is similar to React in terms of reusable components and not having a router of its own. It draws its inspiration of data binding from Angular. So Vue basically mixes the best of Angular and React. I am not going to dive deep into this but if you are interested, have a look at the <a href="https://vuejs.org/v2/guide/comparison.html">official documentation</a> about this very topic.</p><h3>Backstory</h3><p>Vue was founded by <strong>Evan You </strong>which first started as a personal project in 2013. He was working at Google back then and his job involved building UI prototypes for which he used vanilla JavaScript and Angular 1. His words were, “<em>I figured, what if I could just extract the part that I really liked about Angular and build something lightweight.</em>” That is the very thought which made him start Vue.</p><p>He was born in China, in a city called Wuxi close to Shanghai. Attracted to JavaScript, he learned to programme primarily from reading other people’s code, online resources, and books. He is not a computer science major. Before working full time on Vue, he was at Google and Meteor.</p><p>Vue was officially released as a project on February 2014. In just two years, Vue reached 2,000,000 downloads.</p><h3>Who is Vue.js tutorial for?</h3><ul><li><em>Target audience: </em>Front-end developers, full-stack developers or any enthusiastic developer is on-board!</li><li><em>Vue Level:</em> Beginner (“Newbies”)</li><li><em>Expectation:</em> Beginner (strong in basic concepts) to an Intermediate level knowledge of HTML, CSS, and vanilla JavaScript</li><li><em>Prior Experience</em> with other JavaScript frameworks is <strong><em>not </em></strong><em>required.</em></li><li>A <em>step by step explanation</em> along with screenshots and code snippets will be provided wherever required</li><li><em>Visual Studio Code</em> will be used in the examples. You are welcome to try out any IDE of your choice viz., Sublime Text, WebStorm, Atom, etc.</li><li>The code discussed as part of each post will be updated in the <a href="https://github.com/JBTAdmin/vuejs">GitHub repo</a></li></ul><h3>Roadmap</h3><p>Get ready to build your first application with Vue.js. The below list will be updated constantly.</p><h3>Vue.js Fundamentals</h3><ul><li><a href="https://javabeginnerstutorial.com/js/vue-js/1-hello-world-with-vue-js/">Hello World with Vue.js</a></li><li><a href="https://javabeginnerstutorial.com/js/vue-js/2-template-syntax-reactivity/">Template Syntax and a glimpse into Reactivity</a></li><li>Vue directives</li><li>Vue Devtools chrome extension</li><li>Data binding and reactivity</li><li>Conditional rendering Part 1 (v-if, v-else-if, v-else)</li><li>Conditional rendering Part 2 (v-if and v-show)</li><li>List rendering</li><li>Listening to user events and keyboard events</li><li>Let’s use shorthands</li><li>Two-way data binding and modifiers</li><li>Value bindings (checkboxes, radio buttons and multi-select)</li><li>Computed properties</li><li>Let’s watch for changes with watchers</li><li>Binding HTML classes</li><li>Binding CSS styles</li><li>Vue Instance — Deep Dive</li><li>How are data and methods handled in a Vue instance?</li><li>Vue Instance — Lifecycle hooks and a diagrammatic representation</li></ul><p><strong>Advanced Vue.js</strong> — Vue CLI, components</p><p>Keep watching this space, and you will be practicing Vue.js in no time.</p><p>See you soon. Have a great day!</p><p><em>Originally published at </em><a href="https://javabeginnerstutorial.com/js/vue-js/what-is-vuejs/"><em>javabeginnerstutorial.com</em></a><em> on July 21, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec331a54e288" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started With Expressjs]]></title>
            <link>https://medium.com/@admin_76350/getting-started-with-expressjs-2549c0429660?source=rss-3cb8d7ec9c33------2</link>
            <guid isPermaLink="false">https://medium.com/p/2549c0429660</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Java Beginners Tutorial]]></dc:creator>
            <pubDate>Tue, 12 Jun 2018 03:23:38 GMT</pubDate>
            <atom:updated>2018-06-18T15:36:45.205Z</atom:updated>
            <content:encoded><![CDATA[<p>In previous articles, we discussed <a href="https://javabeginnerstutorial.com/node-js/node-js-network-programming/">node js network programming</a> also we discussed how to build a basic web server using Node.js alone. By Node.js alone, I mean using its core API modules such as URL and HTTP. In the second article, we glimpsed briefly on how Node.js works behind the scenes. There is a lot in depth we haven’t discussed such as working of libuv and role V8 in depth. I consider those things out of the scope of these articles since our sole focus is to get started in web development and build production level API servers. Using Expressjs, we can do that.</p><p>When it comes to building a fully functional web server using Node.js, it can take a huge amount of time since Node.js core modules are raw. Over the years Node.js has matured enough due to the support from the community. Using Node.js as a backend for web applications and websites help the developers to start working on their application or product quickly. In this tutorial, we are going to look into Expressjs which is a Node.js framework for web development that comes with features like routing and rendering and support for REST APIs.</p><p>Expressjs is the most popular framework when it comes to building a web server using Node.js at its core. Express requires minimal setup to kickstart an application and is mostly unopinionated in many ways. This gives the flexibility to follow a design pattern such as MVC to build a web application. Other backend frameworks follow a certain amount of philosophy that how a web application or an API should be written. This certainly affects development time.</p><p>Expressjs is developed by TJ Holowaychuk and is currently maintained by Node.js foundation and various open source developers around the world. To get started in web development using Expressjs, you need to have Node.js and npm installed. You can install <a href="https://nodejs.org/en/">Node.js</a> on your local machine and along with it comes the command line utility npm that will help us to install plugins or as called dependencies later on in our project. If you have followed the previous articles, we have already installed Node.js and npm on our dev machines. So let us take a look at why we should use Expressjs:</p><ul><li>Since Expressjs is an unopinionated framework, you can use it to build a single page, multi-page, or even hybrid web applications. These days it is common to use Node.js in mobile development to provide an API, and Expressjs works very well there.</li><li>By default, Express comes with a default templating engine called Jade/Pug. If you want to quickly prototype a website or web application, this is helpful.</li><li>It supports MVC (Model-View-Controller), a very common architecture to design web applications.</li><li>Since it is built on Node.js core API, it does leverage upon its asynchronous architecture. Please note that Express is mostly a wrapper written on Node.js core API to make things easy for the developer when it comes to writing code.</li></ul><h3>Installing Express</h3><p>To initiate any Expressjs project, we need a package.json file inside the root directory where will be storing files or modules written in JavaScript. First, we need to create it.</p><pre>mkdir express-server-example cd express-server-example npm init --yes</pre><p>The npm init –yes is available to us because we have installed npm. npm is the Node Package Manager, a public registry that has a collection of open-source packages for Node.js, front-end applications, mobile, APIs, databases, etc. There are two ways npm allows us to access to these packages or modules. We can install them locally or globally. Not every module is required to install globally, but almost every other module is required to install locally. We will make use of both local and global installation so stay tuned.</p><p>This will generate a package.json file in the root of the project directory. We need to install the express module from npm to initiate a web server.</p><pre>npm install express --save</pre><p>If you get the below in output in your terminal, this means the package was installed successfully.</p><pre>npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN <a href="https://javabeginnerstutorial.com/cdn-cgi/l/email-protection">[email protected]</a> No description npm WARN <a href="https://javabeginnerstutorial.com/cdn-cgi/l/email-protection">[email protected]</a> No repository field. + <a href="https://javabeginnerstutorial.com/cdn-cgi/l/email-protection">[email protected]</a> added 50 packages in 4.214s</pre><p>However, a better way to check if the package has installed correctly is to take a look at package.json file.</p><pre>{ &quot;name&quot;: &quot;express-server-example&quot;, &quot;version&quot;: &quot;1.0.0&quot;, &quot;description&quot;: &quot;&quot;, &quot;main&quot;: &quot;index.js&quot;, &quot;scripts&quot;: { &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot; }, &quot;keywords&quot;: [], &quot;author&quot;: &quot;&quot;, &quot;license&quot;: &quot;ISC&quot;, &quot;dependencies&quot;: { &quot;express&quot;: &quot;^4.16.3&quot; } }</pre><p>This file is a manifesto for any Node.js or JavaScript related project. It is in JSON format that means you can write JavaScript inside it. This is what triggers our JavaScript project, in this case, our Express web server when we deploy our application on a production-ready service such as Heroku or AWS. Notice, the dependencies section which contains the name and the semantic version of the module we currently installed. Also, notice that a new folder called node_modules suddenly appeared in the root of our project directory. This folder stores the packages we install locally in our project.</p><h3>Building a Basic Web Server</h3><p>Now at the root of our project, create a new file called index.js. Inside this file, we are going to write our first web server using Expressjs.</p><pre>const express = require(&#39;express&#39;); const app = express(); app.get(&#39;/&#39;, (req, res) =&gt; res.send(&#39;Hello World!&#39;)); app.listen(3000, () =&gt; console.log(&#39;Example app listening on port 3000!&#39;));</pre><p>The first line in our index.js file declares that we import our open-sourced express module that we installed using npm in the previous section. This is how we will initialize every express server file we are going to create. This line confirms that we are defining an instance of express and are going to use it in the file below. This instance of express is going to provide us with ways to handle requests coming from the client and deliver responses to those requests from our web server. The require function is part of the core Node.js API and helps us to define an instance of any npm module or core Node.js module in any JavaScript file. Not just this one.</p><p>This express module is the wrapper or a class we were talking about earlier. It provides its own methods such as app. We can use this app to define routes and communicate with HTTP methods such as GET, POST, etc. and listen for incoming requests from the client. It will also be responsible for sending a response to the server. In other words, the app has access to request and response objects. The .get() signifies that it is an HTTP GET methods. We will learn more about HTTP methods in this series. It also has a callback function that contains two arguments req and res.</p><p>In our example above, we are using req for request and res for a response as arguments. This req is an object that signifies HTTP request and res signifies response. We are listening to any request coming from a client on route path / using app.listen() that bootstraps the Express web server using a port such as 3000 in our case. We can use any port number when developing our web server. The console.log method is just an indication to us that the web servers starts without any errors. This will be echoed in your terminal.</p><p>To start this server, from your terminal, write:</p><pre>node index.js</pre><p>You will be prompted by a message:</p><pre>The example app is listening on port 3000!</pre><p>You can also verify that our web server is working by visiting <a href="http://localhost:3000/">http://localhost:3000</a> from a browser. In the browser window, you will be prompted by a Hello World! Message. Congratulations! You just developed your first web server using Expressjs. Now let us proceed further. To close the server, press control + c from your keyboard.</p><h3>Anatomy of an Express Application</h3><p>It is better to get familiar with some jargons or characteristics of an Express app before we dive deep into building a REST API. Generally, an Expressjs application will always have:</p><h3>Dependencies</h3><p>We have seen how to use dependencies in the previous section. It is simple, by requiring them using require() method. These dependencies can be installed using npm. There are two types of dependencies: devDependencies and dependencies. You will learn more about them as we proceed but the basic difference between them that devDependencies are not going to install when we deploy our web server. Our deployment server will only need a listed dependency in our package.json file.</p><h3>Instantiations</h3><p>The second thing we did on our express web server, is to get an instance of the express module as an app to use its properties. This has to be done whenever we are writing an Express web server from scratch.</p><h3>Configurations</h3><p>Although our minimalistic application lacks any configuration in no time, we are going to see some, especially when we will be making use of environment variables and database. They are mostly statements that are defined in a separate file or can be defined in our index.js too.</p><h3>Middleware</h3><p>Middleware functions are the core philosophy as well as paradigm behind an Express application. The determine the flow of a request-response cycle. We already know that a web server is like a two-way communication between a client and a server. When the client sends a request, a server has to respond, does not matter now whether the server responds successfully or with an error message. To manipulate this cycle between the two we use middleware functions.</p><h3>Bootstrapping Server</h3><p>This is simple. This is something that is always defined in the last. We have seen it already in our example is called app.listen() method.</p><h3>RESTful Service</h3><p>If you are going to develop a web application, you are going to come across this term called RESTful Service. REST is an acronym for Representation State Transfer and is an industry standard for defining how an API and its endpoint (routes) should communicate with the server of your application.</p><p>A REST API contains HTTP methods such GET, POST, etc. with endpoints that are nothing but URLs so that you can use these routes to fetch appropriate data or update/create new data or delete existing data in the database. In his <a href="https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm">whitepaper</a>, Roy Fielding described the paradigms and practical use of REST as a protocol. I am going to summarise the points what he exactly says in that paper. The basis of a RESTful API depends on below:</p><ul><li>Client-Server</li><li>Stateless</li><li>Uniform Interface</li><li>Cacheable</li><li>Layered System</li><li>Code-On-Demand style</li></ul><p>An application that makes use of REST APIs perform four basic operations that are known as CRUD.</p><ul><li>C: Creating data</li><li>R: Reading data</li><li>U: Updating data</li><li>D: Deleting/removing data</li></ul><p>To understand this concept, let us consider a real-world example. Suppose we have a company called <em>Rentflix</em> that rents out movies to various customers. On our client part of the application, we have a way to manage the list of our customers. To fetch this data or the list form our database, on our server we will have to expose this service in the form of an endpoint like <a href="http://rentflix.com/api/users.">http://rentflix.com/api/users.</a> Now, our client can send an HTTP request (GET in this case) to display this data in the browser.</p><p>Thus in Express, similar to our app.get(), we do have other methods to handle each HTTP request:</p><h3>Using nodemon</h3><p>Let us create a new endpoint in our app called numbers which will send an array full of numbers to our client. Now, whenever we make changes to our Express web server, we need to quit the previous running web server and add the changes and then restart it. This is a very tedious way of working and to overcome this; we will install nodemon which is short for <em>node monitor</em> as a devDependency in our package.json file.</p><p>To install:</p><pre>npm install nodemon -D</pre><p>Now go back to the package.json file and notice this section below our previous dependencies section:</p><pre>&quot;devDependencies&quot;: { &quot;nodemon&quot;: &quot;^1.17.5&quot; }</pre><p>This is how you install devDependencies, use the flag -D instead of -S or –save.</p><p>Now to make it work, we will also modify our package.json file and a new script called dev under scripts section. The dev is just naming convention that signifies that we are using for the development environment.</p><pre>&quot;scripts&quot;: { &quot;start&quot;: &quot;node index.js&quot;, &quot;dev&quot;: &quot;nodemon index.js&quot;, &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot; }</pre><p>To start this script, type:</p><pre>npm run dev</pre><p>You will be prompted with the same message as the previous example. Now, without closing it, we will modify index.jsfile. Add a new route /api/numbers below our app.get(‘/’, …) endpoint</p><pre>app.get(&#39;/api/numbers&#39;, (req, res) =&gt; { res.send([1, 2, 3]); });</pre><p>Visit the URL <a href="http://localhost:3000/api/numbers,">http://localhost:3000/api/numbers,</a> and you will notice the same result we are sending from our web server. Do notice that terminal now and you will see that it has been restarted on its own (using nodemon) at least once or whenever you have saved the file.</p><p>This concludes our first section of getting started with Expressjs and build a web server. In the next article, we are going to make use of Express Generator, a better way of getting started whether you are writing an API or an Express web application. More to follow about middleware functions using custom and both third-party middlewares, template engines and many more. To get the code or follow along, you can visit <a href="https://github.com/amandeepmittal/express-server-example">this Github Repository</a>.</p><p><em>Originally published at </em><a href="https://javabeginnerstutorial.com/node-js/getting-started-with-expressjs/"><em>javabeginnerstutorial.com</em></a><em> on June 12, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2549c0429660" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Facade Design Pattern]]></title>
            <link>https://medium.com/@admin_76350/facade-design-pattern-90f28ee02b1e?source=rss-3cb8d7ec9c33------2</link>
            <guid isPermaLink="false">https://medium.com/p/90f28ee02b1e</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[facade]]></category>
            <dc:creator><![CDATA[Java Beginners Tutorial]]></dc:creator>
            <pubDate>Sun, 27 May 2018 07:47:24 GMT</pubDate>
            <atom:updated>2018-05-27T07:52:26.922Z</atom:updated>
            <content:encoded><![CDATA[<h4>In this article I will write about the Facade Design Pattern and give you some examples for its usage.</h4><h3>About the Facade Design Pattern</h3><p>A facade is for hiding features from external clients and to give them a unified access point to public functionality.</p><p>Let’s see what the Gang of Four (GoF) tells us about this pattern:</p><p>“Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.”</p><p>So to have this pattern applied in your application your goal is to isolate your client from the code of your application.</p><p>You can use this pattern in a Service Oriented Architecture (SOA): for example a service enables access to other smaller services. You do not have to think in this case that these are web services and outside clients: you can have this pattern applied to your application too as you design it and restrict access between packages (this requires some build-time validation too however tools like SonarQube are capable of this).</p><p>Another way to use this pattern is to encapsulate complex functionality from the caller of your facade: you have a complex system in the background and when using this systems you need to fire up queries, ask other services and do various calculations to get the result. If you would access it normally you would need to know each service, the order to call them to get your result. With a facade in-between you only let one method known by your users and you can configure the logic in the facade.</p><h3>Example</h3><p>The best example is again the AppStore where we can order an app and we do not have to know what happens in the background: the app is developed and tested. And we are happy that we don’t have to call every phase of the development life-cycle ourself just the one facade.</p><p>Let’s see how this works with a simple example. In this app store we have a 3-phase development: first a Design is created by an AppDesigner based on some requirements. Then an AppDeveloper develops an App based on the Design. When the App is ready an AppTester verifies that the App is working as defined in the Design.</p><p>First of all, let’s create the Design and App classes:</p><pre>/**<br> * Simple class to mock a design object for an app.<br> *<br> * @author GHajba<br> *<br> */<br>public class Design {</pre><pre>    private final String requirements;</pre><pre>    public Design(final String requirements) {<br>        this.requirements = requirements;<br>        System.out.println(toString());<br>    }</pre><pre>    @Override<br>    public String toString() {</pre><pre>        return &quot;App design for requirements: &quot; + requirements;<br>    }<br>}</pre><pre>/**<br> * Simple app mock which does nothing currently.<br> *<br> * @author GHajba<br> *<br> */<br>public class App {</pre><pre>    private final String title;</pre><pre>    public App(final Design design, final String title) {<br>        System.out.println(&quot;Creating an app based on the design: &quot; + design);<br>        this.title = title;<br>    }</pre><pre>    @Override<br>    public String toString() {</pre><pre>        return &quot;Fantastic app with title: &quot; + title;<br>    }<br>}</pre><pre>Then we create the back-end workers:</pre><pre>/**<br> * Simple designer class.<br> *<br> * @author GHajba<br> *<br> */<br>public class AppDesigner {</pre><pre>    public static Design design(final String requirements) {</pre><pre>        return new Design(requirements);<br>    }<br>}</pre><pre>import java.util.Arrays;<br>import java.util.Collections;<br>import java.util.List;</pre><pre>/**<br> * Simple app developer mock.<br> *<br> * @author GHajba<br> *<br> */<br>public class AppDeveloper {</pre><pre>    private static final List&lt;String&gt; POSSIBLE_NAMES = Arrays.asList(&quot;Pointless Kangaroo&quot;,<br>            &quot;Moon Forgotten&quot;, &quot;Purple Rusty Space&quot;, &quot;Blue Vulture&quot;, &quot;Skilled Ostrich&quot;, &quot;Saturday&#39;s Intense Xylophone&quot;,<br>            &quot;Harsh Reborn Gravel&quot;, &quot;Liquid Rhinestone&quot;, &quot;Wooden Haystack&quot;, &quot;Scissors Olive&quot;, &quot;Moving Doorstop&quot;,<br>            &quot;Strong Restless Arm&quot;, &quot;Dreaded Pottery&quot;);</pre><pre>    public static App develop(final Design design) {</pre><pre>        Collections.shuffle(POSSIBLE_NAMES);</pre><pre>        return new App(design, POSSIBLE_NAMES.get(0));<br>    }<br>}</pre><pre>/**<br> * A simple app tester.<br> *<br> * @author GHajba<br> *<br> */<br>public class AppTester {</pre><pre>    public static boolean test(final App app, final Design design) {</pre><pre>        System.out.println(&quot;Testing app: &quot; + app + &quot;, based on the design &quot; + design);</pre><pre>        return Math.random() &lt; 0.5;<br>    }<br>}</pre><pre>Without a facade we have to know how every component works until we have our final App. An example of calling the workers is listed here:</pre><pre>/**<br> * Entry point for the application and here we can order our apps.<br> *<br> * @author GHajba<br> *<br> */<br>public class AppStore {</pre><pre>    public static void main(final String... args) {</pre><pre>        Design d = AppDesigner.design(<br>                &quot;Create me a cool app which knows everything I want and makes this fast. And of course it has to be cheap.&quot;);</pre><pre>        App app = AppDeveloper.develop(d);<br>        while (!AppTester.test(app, d)) {<br>            System.out.println(&quot;App &quot; + app + &quot; failed the tests :(&quot;);<br>        }<br>    }<br>}</pre><p>And an example output:</p><pre>App design for requirements: Create me a cool app which knows everything I want and makes this fast. And of course it has to be cheap.<br>Creating an app based on the design: App design for requirements: Create me a cool app which knows everything I want and makes this fast. And of course it has to be cheap.<br>Testing app: Fantastic app with title: Pointless Kangaroo, based on the design App design for requirements: Create me a cool app which knows everything I want and makes this fast. And of course it has to be cheap.<br>App Fantastic app with title: Pointless Kangaroo failed the tests :(<br>Testing app: Fantastic app with title: Pointless Kangaroo, based on the design App design for requirements: Create me a cool app which knows everything I want and makes this fast. And of course it has to be cheap.<br>App Fantastic app with title: Pointless Kangaroo failed the tests :(<br>Testing app: Fantastic app with title: Pointless Kangaroo, based on the design App design for requirements: Create me a cool app which knows everything I want and makes this fast. And of course it has to be cheap.<br>App Fantastic app with title: Pointless Kangaroo failed the tests :(<br>Testing app: Fantastic app with title: Pointless Kangaroo, based on the design App design for requirements: Create me a cool app which knows everything I want and makes this fast. And of course it has to be cheap.</pre><p>To leverage our AppStore from the knowledge of who has to work on the App (perhaps we want to introduce some other step in the creation process like UX testers) we encapsulate the functionality into a facade:</p><pre>/**<br> * This is the facade where the apps are created.<br> *<br> * @author GHajba<br> *<br> */<br>public class AppCreationFacade {</pre><pre>    public static App orderApp(final String requirements) {</pre><pre>        Design d = AppDesigner.design(requirements);<br>        App app = AppDeveloper.develop(d);<br>        while (!AppTester.test(app, d)) {<br>            System.out.println(&quot;App &quot; + app + &quot; failed the tests :(&quot;);<br>        }</pre><pre>        System.out.println(&quot;Successfully developed &quot; + app);</pre><pre>        return app;<br>    }<br>}</pre><p>As you can see, this facade does basically the same thing as we did previously in the AppStore. However with this approach we hide the implementation details from the clients of the facade and only the facade has to know how it gets an App from the initial requirements.</p><p>From the AppStore we only have to call the right method of the facade:</p><pre>/**<br> * Entry point for the application and here we can order our apps.<br> *<br> * @author GHajba<br> *<br> */<br>public class AppStore {</pre><pre>    public static void main(final String... args) {<br>        AppCreationFacade.orderApp(<br>                &quot;Create me a cool app which knows everything I want and makes this fast. And of course it has to be cheap.&quot;);<br>    }<br>}</pre><p>Here is an example output of the above example application:</p><p>App design for requirements: Create me a cool app which knows everything I want and makes this fast. And of course it has to be cheap.<br>Creating an app based on the design: App design for requirements: Create me a cool app which knows everything I want and makes this fast. And of course it has to be cheap.<br>Testing app: Fantastic app with title: Saturday’s Intense Xylophone, based on the design App design for requirements: Create me a cool app which knows everything I want and makes this fast. And of course it has to be cheap.<br>Successfully developed Fantastic app with title: Saturday’s Intense Xylophone</p><h3>Conclusion</h3><p>As you could see, using this design pattern is nothing tricky — and if you work with Java applications then you may already used this pattern without noticing it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90f28ee02b1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>