<?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 Yasara Fernando on Medium]]></title>
        <description><![CDATA[Stories by Yasara Fernando on Medium]]></description>
        <link>https://medium.com/@yashfer853?source=rss-4da010955dea------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*srIyLIAfu1tYrly2</url>
            <title>Stories by Yasara Fernando on Medium</title>
            <link>https://medium.com/@yashfer853?source=rss-4da010955dea------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 05:13:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yashfer853/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[Memento]]></title>
            <link>https://medium.com/@yashfer853/memento-9c4fb04e9505?source=rss-4da010955dea------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c4fb04e9505</guid>
            <dc:creator><![CDATA[Yasara Fernando]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 05:24:01 GMT</pubDate>
            <atom:updated>2022-07-19T16:34:02.885Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chapter 18 — Distributed Computing</h3><p>This is the last article in this series and this is about servlets. This article is written by referring the Head First Java by Keith Sierra.</p><p>Servlets are Java programs that are run on a HTTP web server. When a client uses a web browser to interact with a web page, the request is sending to the server. If that request needs a help of a Java servlet then web browser runs a servlet code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*5JaUwpAv9hk4V12TFCIu4w.png" /></figure><p><strong>Steps for making and running servlet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/190/1*6uPR4SRe_RkNiIm2NwvQNA.png" /></figure><p>Find out where your servlets need to be placed</p><p>Get the servlets.jar and add it to your classpath</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/88/1*USezyfE-2wksI5diSq1E0A.png" /></figure><p>Write a servlet class by extending HttpServlet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/111/1*ZeXjl3bQkURO7l5T-gaunw.png" /></figure><p>Write on HTML page that invokes your servlet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/97/1*zXhx29NYQ5QZ7v-DZ5q5lA.png" /></figure><p>Make your servlet and HTML page available to your server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/205/1*1CFJ3sWIULpfuy3_LNPm9w.png" /></figure><p><strong>In the following image you can see a simple servlet code</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*R7nd8MKmMoRfaravPhBayw.png" /></figure><p><strong>HTML page links to a servlet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*AkHJh1urkMpUc4k6duvHPg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c4fb04e9505" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chapter 17 — Release Your Code]]></title>
            <link>https://medium.com/@yashfer853/chain-of-responsibility-2b9fc73e117c?source=rss-4da010955dea------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b9fc73e117c</guid>
            <dc:creator><![CDATA[Yasara Fernando]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 05:23:42 GMT</pubDate>
            <atom:updated>2022-07-19T16:32:38.627Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the seventeenth article of this series and in this article, I discuss packages, jars, and local deployment.</p><p><strong>Deploying your application</strong></p><p>After completing the development of your application you need to deploy it. That means the application is going to deal with the end users. But they don’t have your application. Let’s focus on local deployments including Executable Jars and the part-local/part-remote technology called Java Web Start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*tP6tSrsOvfPHxhWkyd6WDw.png" /></figure><p><strong><em>Separate source code and class files</em></strong></p><p>Organizing your code is very important because the source code and class file be in separate directories. The standard organization structure is to create a project directory and then put the source directory and a class directory inside the project directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*CWKc6pavybQCfbR6VRW8RA.png" /></figure><p><strong><em>Compiling and running the code</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*FloEng_28EpzI4CXGgIdYA.png" /></figure><p><strong><em>Making an executable Jar</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*gMFSOA7c8yQwIvQRc65rrw.png" /></figure><p><strong><em>Running/executing the Jar</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*KkrpvrG7d36UPDa17LuF-Q.png" /></figure><p><strong>Package</strong></p><p>The package can prevent naming conflicts. But it’s important to choose a unique name. Prefacing your packages with your reverse domain name Is the best way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*W1tLlD3EVwDK6kQBjh2_Zw.png" /></figure><p>To put your class in a package there are three steps.</p><p>· Choose a package name</p><p>· Put a package statement in your class</p><p>· Set up a matching directory structure</p><p><strong><em>Compiling and running with packages</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*MVzgi9xX4tBPd2ssXv0WGg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*z3e9k6do0MzdX6YVFCuXNw.png" /></figure><p><strong><em>Making an executable Jar with packages</em></strong></p><p>· Make sure all of your class files are within the correct package structure, under the classes directory</p><p>· Create a manifest.txt file that states which class has the main() method, and be sure to use the fully-qualified class name</p><p>· Run the jar tool to create a Jar file that contains the package directories plus the manifest</p><p><strong>Java Web Start</strong></p><p>Users can launch a Java Web Start application by clicking a link on a web page. Once the application downloads, it runs outside the browser like a standalone application. A Java Web Start app is an executable Jar that’s distributed over the web. The key purpose of the ‘helper app’ is to manage downloads, updates, and launch the application. In the following image, you can see how a Java Web Start application works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*hvQd-gWO4nE7ok8KxkIqkg.png" /></figure><p>To make a Java Web Start app you need a .jnlp (Java Network Launch Protocol) file that describes your application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*BaKNK41Hyh-Xr6uByk3oEQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b9fc73e117c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Builder pattern]]></title>
            <link>https://medium.com/@yashfer853/builder-pattern-cb50b01d5f48?source=rss-4da010955dea------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb50b01d5f48</guid>
            <dc:creator><![CDATA[Yasara Fernando]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 05:23:20 GMT</pubDate>
            <atom:updated>2022-07-19T16:28:09.794Z</atom:updated>
            <content:encoded><![CDATA[<p>This design patterns comes under creational design patterns. When you are using multiple constructors in a program we use builder pattern. Implementing this pattern in a traditional way is complex because there are number of constructors are used in the program. When implementing this some people used telescoping constructor. It means a user can have multiple constructors and each constructor used other constructors depending on the parameters. The other method to implement this pattern is using setters. But the disadvantage of using setters is it cannot make immutable. That means the object can be changed by anyone after it created.</p><p>Ex : Just imagine that you are going to manufacture vehicles. To build a vehicle basically you need tyres, an engine, doors, steering wheel and etc. In this pattern we can use a constructor and a toString() to print the objects. With the use of the builder class we can simply change the values of the variables and can build various vehicles with their features (We can define sepataretly the number of tyres, doors , having engine regarding the vehicle we need to build).</p><p>For example car has an engine, four tyres, for doors, a steering wheel and four seats (Considering some of the variables). But when we are going to build a push bicycle we need only two tyres, a seat.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb50b01d5f48" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Factory method]]></title>
            <link>https://medium.com/@yashfer853/factory-method-e85be509b688?source=rss-4da010955dea------2</link>
            <guid isPermaLink="false">https://medium.com/p/e85be509b688</guid>
            <dc:creator><![CDATA[Yasara Fernando]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 05:22:37 GMT</pubDate>
            <atom:updated>2022-07-19T15:47:45.108Z</atom:updated>
            <content:encoded><![CDATA[<p>Factory method is categorized under creational design patterns. This design pattern provides an interface for create objects in a super class and allows sub classes to alter the type of objects that will created.</p><p>Ex : Imagine there is a biscuit factory where sells circular shaped biscuits and square shaped biscuit. By using an interface with the common methods of the two types of biscuits we can use this design pattern. Two biscuit classes (concrete classes) can be implemented from the factory interface. Specific methods can be included in concrete classes.</p><p>When implementing factory pattern we can use a parameter to determine which instance needed to get. In this pattern we don’t know the instance what we are going to get (sometimes get sub instances instead of parent instances).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e85be509b688" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chapter 16 — Data structures]]></title>
            <link>https://medium.com/@yashfer853/chapter-16-data-structures-b0b208f0e581?source=rss-4da010955dea------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0b208f0e581</guid>
            <dc:creator><![CDATA[Yasara Fernando]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 22:45:08 GMT</pubDate>
            <atom:updated>2022-07-18T22:45:08.529Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chapter 16 — Data structures</h3><p>In this article, I’m going to discuss the Java collection framework and generics.</p><p>The following image gives you a brief idea about the Java collection framework(ArrayList is not included here)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*Irp0fi1NzifKpyWYRtcJrQ.png" /></figure><p><strong>Generic</strong></p><p>Generic means more type safety. Generic use to sort by instances of objects. When creating classes they must accept generics.</p><p>The following image shows the three matters that need to know about generics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*rTJwWMncq4zkK52H4Wnigg.png" /></figure><p>When using generic classes there are two key areas to look at.</p><p>· The class declaration</p><p>· The method declaration that let you add elements</p><p><strong><em>Using generic methods</em></strong></p><p>The generic method means that the method declaration uses a type parameter in its signature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*cSAmsxhvfqslWSq3aTFbMw.png" /></figure><p><strong><em>Generics — “extends” means extend or implement</em></strong></p><p>It works for both situations. The word “extends” means IS-A and it works regardless of whether the type on the right is an interface or class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*q74K7UXwsdtgGukcTfsNLg.png" /></figure><p><strong><em>Collection API</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*X4kCi7kB-7Yoewxb8t9sCw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0b208f0e581" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chapter 15 — Make a connection]]></title>
            <link>https://medium.com/@yashfer853/chapter-15-make-a-connection-f4a4cc928652?source=rss-4da010955dea------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4a4cc928652</guid>
            <dc:creator><![CDATA[Yasara Fernando]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 22:41:04 GMT</pubDate>
            <atom:updated>2022-07-18T23:21:44.183Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chapter 15 — Make a connection</h3><p>Let’s have a look at how a program deals with another program or another machine. In this article, I’m going to talk how a program connects to the outside world with sockets and about threads. So, this is the article fifteenth from the Head First Java by Keith Sierra.</p><p>First, I’m going to write about how the connection is established between the client and the server, sending messages to the server and receiving messages from the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*iYyTdJA9tkHxIvgN_LJr3Q.png" /></figure><p><strong>Connection</strong></p><p>As I mentioned at the beginning of the article let’s see how the socket connection is established. A socket connection is a connection between two machines including a network location (IP address) and TCP port. A socket (java.net.Socket class) is an object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*upofTqXhk6BvR6mNvJTIig.png" /></figure><p>A TCP port is a 16-bit number that identifies a specific program on the server. Well-known TCP port numbers for common server applications are shown in the following image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*dNgJrI7K_KDqRTzHqllKsw.png" /></figure><p>For the purpose of reading data from a socket a <em>BufferReader</em> is used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*CiquZIFsTra1HQHxrF-v9w.png" /></figure><p>To write data to a socket a <em>PrintWriter</em> is used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*8hGCnPPOgxmsvFoSAJHIPw.png" /></figure><p><strong>Threads</strong></p><p>Java has multiple threads but a single Thread class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*e7ZFBGL595hKPRCxPrJT_g.png" /></figure><p><strong><em>Launch a thread</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*5Z6_O-j0Gk7I0ZMjycC9wQ.png" /></figure><p><strong><em>Implementing Runnable interface</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*OlBwnMXXXKWewg4sh4-NzA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*5p-bDf9j7JUC9rDuyysJHw.png" /></figure><p>There are three states of a new thread</p><p>· New</p><p>· Runnable</p><p>· Running</p><p><strong><em>Putting a thread to sleep</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*11TjUSKp9maETEq3bA4BNA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4a4cc928652" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chapter 14 — Saving Objects]]></title>
            <link>https://medium.com/@yashfer853/chapter-14-saving-objects-dde46f89cf16?source=rss-4da010955dea------2</link>
            <guid isPermaLink="false">https://medium.com/p/dde46f89cf16</guid>
            <dc:creator><![CDATA[Yasara Fernando]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 20:21:57 GMT</pubDate>
            <atom:updated>2022-07-18T20:21:57.723Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chapter 14 — Saving Objects</h3><p>In this chapter, I’m going to discuss serialization and file I/O by referring to the fourteenth chapter of Head First Java by Keith Sierra.</p><p><strong>Serializing</strong></p><p>Serializing means saving an object. There are a few steps of serializing and the following diagram shows those.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*LqpuEDi_IDn2cjE6w7P7AA.png" /></figure><p><strong>Deserialization</strong></p><p>Deserialization is restoring the object back to its original state at some later date in a different JVM. This is the reverse of serialization. There are five steps in deserialization and in the following diagram shows clearly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*m-THqoJPICNGlO1dlDLTrg.png" /></figure><p>The things that happen during deserialization are listed down below.</p><p>· The object is read from the stream</p><p>· The JVM determines the object’s class type</p><p>· The JVM attempts to find and load the object’s class. If the JVM failed to find/load the class then JVM throws an exception and the process fails.</p><p>· A new object is given space on the heap but the serialized object’s constructor does not run. If the constructor runs it would restore the state of the object back to its original ‘new’ state. But we need the object to be restored to the state it had when it was serialized.</p><p>· If the object has a non-serialized class somewhere up its inheritance tree the constructor for that non-serializable class will run along with any constructors above that. Whenever the constructor chaining begins it cannot be stopped. That means all superclasses beginning with the first non-serializable one will reinitialize their state.</p><p>· The object’s instance variables are given the values from the serialized state. Transient variables are given a value of null for object references and defaults.</p><p><strong>The java.io.File class</strong></p><p>This class represents a file on a disk but not the content of the file.</p><p>Things that can do with a file object are shown in the below diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*cGqsjgeXNGrkZCWBLbluUA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dde46f89cf16" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chapter 13 — Work on Your Swing]]></title>
            <link>https://medium.com/@yashfer853/chapter-13-work-on-your-swing-30d7a9ba9032?source=rss-4da010955dea------2</link>
            <guid isPermaLink="false">https://medium.com/p/30d7a9ba9032</guid>
            <dc:creator><![CDATA[Yasara Fernando]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 20:19:38 GMT</pubDate>
            <atom:updated>2022-07-18T20:19:38.469Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chapter 13 — Work on Your Swing</h3><p>This is the thirteenth article on Head First Java and here I’m going to discuss Swing, layout managers, and use them.</p><p><strong>Swing</strong></p><p>The component can be called a widget as well. These are the things we put in a GUI. Text fields, buttons, and radio buttons, are some of the components extend in javax.swing.JComponent. To make a GUI there are a few steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*bZO1Hgy6d9YT6l9UiyxP4w.png" /></figure><p><strong>Layout managers</strong></p><p>A layout manager is a Java object. It is associated with a particular component and it is always a background component. This controls the components contained within the component the layout manager is associated with.</p><p>The general layout scenario is shown in the following diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*7CKKMTie7RoxaBXCsQzv4A.png" /></figure><p>When designing a GUI we can place the components in the right place for the purpose of user-friendliness. Designing a GUI is not an easy task because users must experience a user-friendly, effective application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30d7a9ba9032" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chapter 12 — A Very Graphic Story]]></title>
            <link>https://medium.com/@yashfer853/chapter-12-a-very-graphic-story-f6c8c7aec1c8?source=rss-4da010955dea------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6c8c7aec1c8</guid>
            <dc:creator><![CDATA[Yasara Fernando]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 20:07:47 GMT</pubDate>
            <atom:updated>2022-07-18T20:07:47.910Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chapter 12 — A Very Graphic Story</h3><p>When we are developing an application a graphical interface is an important thing. An interface will help people to use the application easily. So, in this article, I’m going to discuss how to add a button on the screen that can do something after clicking and displaying an image and finally do some animation. I have referred to chapter twelve of the Head First Java by Keith Sierra.</p><p><strong>Making a GUI</strong></p><p>1. Make a frame (a JFrame)</p><p>JFrame frame = new JFrame();</p><p>2. Make a widget (button, text field, etc.)</p><p>JButton button = new JButton(“click me”);</p><p>3. Add the widget to the frame</p><p>frame.getContentPane().add(button);</p><p>4. Display it (give it a size and make it visible)</p><p>frame.setSize(300,300);</p><p>frame.setVisible(true);</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*B67coNo8VTFHhXG0fxtGPA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*EY34d2VZ6Pzg6kTyKacHKw.png" /></figure><p>The next step is we have to do something after clicking the button</p><p>To do this we need to do two things</p><p>· A method to be called when the user clicks</p><p>· A way to know when to trigger that method</p><p><strong><em>Make the method</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*SWXK9uqcB8KOmrMRlj74DA.png" /></figure><p>To know whether the button is clicked or not the first button has to know that we care about it and then the button knows that we care for them. Therefore whenever something happens to the button it sends a message. To do this a pre-build class in Java called event is used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*fcVqnLLnKOkaLh0DUguAWA.png" /></figure><p><strong>Adding graphics</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*EP8CmomGpjOfuOMtZibc6g.png" /></figure><p><strong>Make your own drawings</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*ON1DCoRm3HpBx6On4n_fBA.png" /></figure><p><strong>Display an image</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*itK7JEo9lJ-SZJtYmJqUMA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6c8c7aec1c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chapter 11 — Risky Behavior]]></title>
            <link>https://medium.com/@yashfer853/chapter-11-risky-behavior-ff94cab966f9?source=rss-4da010955dea------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff94cab966f9</guid>
            <dc:creator><![CDATA[Yasara Fernando]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 20:03:58 GMT</pubDate>
            <atom:updated>2022-07-18T20:03:58.649Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chapter 11 — Risky Behavior</h3><p>This is the eleventh article on Head First Java by Keith Sierra and in this chapter, we are going to look into exception handling. Exceptional situations can occur when compiling codes and running the codes. However, it’s not an error.</p><p>Normally, if there are risky codes in your code try/catch block can be used to wrap the above-mentioned code. This block tells the compiler that it knows there is an exception happening in the method that is calling. Try/catch block is prepared to handle it and the compiler does not care how it handles but it cares that the block is caring about it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*7uAe96mu7c0ADQ-_nwrO3w.png" /></figure><p>An an exception is an object, and the thing you are caught is an object. Sometimes an object of type exception can be an instance of any subclass of exception. In the following diagram (code) catch argument is declared as a type exception and the parameter reference variable is ex.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*aw3UzUVCDQY1aATcowX3KQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*3Z5cbOgGRtI52Qgg1EvyMg.png" /></figure><p><strong><em>The code catches the exception but whose code throws it?</em></strong></p><p>When the code calls a risky method, it’s the risky method that throws the exception back to you. It may be you who wrote both classes. The matter is knowing which method throws the exception and which method catches it. When someone writes a code that could throw an exception they must declare the exception.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*elyaZfjRgfGmYltapEneEg.png" /></figure><p><strong>Checked and unchecked exceptions</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*vI_93Q5HQeV_bGFLTxvocQ.png" /></figure><p><strong><em>Finally</em></strong></p><p>A finally block is where you put code that must run regardless of an exception. A finally block lets you put all the important cleanup code in one place instead of duplicating it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/223/1*u9Cl7i_UuPd3DFmBFg2p1w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff94cab966f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>