<?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 Kishara Jayasanka on Medium]]></title>
        <description><![CDATA[Stories by Kishara Jayasanka on Medium]]></description>
        <link>https://medium.com/@KisharaBuddika?source=rss-993a59612273------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*d2AWa2vI7ZJNjnZfvBW9wg.jpeg</url>
            <title>Stories by Kishara Jayasanka on Medium</title>
            <link>https://medium.com/@KisharaBuddika?source=rss-993a59612273------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 18:21:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@KisharaBuddika/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[Cloudflare Data Breach: What Sri Lankan Users Need to Know]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@KisharaBuddika/cloudflare-data-breach-what-sri-lankan-users-need-to-know-c34f01d6cc4d?source=rss-993a59612273------2"><img src="https://cdn-images-1.medium.com/max/1024/1*QZHDfv32Qn59K1vS5EUibg.png" width="1024"></a></p><p class="medium-feed-snippet">The digital world often feels secure, but recent news about a data breach at Cloudflare reminds us that no system is entirely impervious&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@KisharaBuddika/cloudflare-data-breach-what-sri-lankan-users-need-to-know-c34f01d6cc4d?source=rss-993a59612273------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@KisharaBuddika/cloudflare-data-breach-what-sri-lankan-users-need-to-know-c34f01d6cc4d?source=rss-993a59612273------2</link>
            <guid isPermaLink="false">https://medium.com/p/c34f01d6cc4d</guid>
            <category><![CDATA[digital-world]]></category>
            <category><![CDATA[data-breach]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[api-security]]></category>
            <category><![CDATA[cloudflare]]></category>
            <dc:creator><![CDATA[Kishara Jayasanka]]></dc:creator>
            <pubDate>Mon, 08 Sep 2025 16:14:23 GMT</pubDate>
            <atom:updated>2025-09-08T16:18:03.213Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[The A to Z of AI Levels - From Assistants to Agents]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@KisharaBuddika/the-a-to-z-of-ai-levels-from-assistants-to-agents-0a44501182ff?source=rss-993a59612273------2"><img src="https://cdn-images-1.medium.com/max/1216/1*TfmCryzFkeeGBBJg4NXRiA.jpeg" width="1216"></a></p><p class="medium-feed-snippet">The journey of AI has only just begun, and staying informed about these levels is the first step in making AI work for you.</p><p class="medium-feed-link"><a href="https://medium.com/@KisharaBuddika/the-a-to-z-of-ai-levels-from-assistants-to-agents-0a44501182ff?source=rss-993a59612273------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@KisharaBuddika/the-a-to-z-of-ai-levels-from-assistants-to-agents-0a44501182ff?source=rss-993a59612273------2</link>
            <guid isPermaLink="false">https://medium.com/p/0a44501182ff</guid>
            <dc:creator><![CDATA[Kishara Jayasanka]]></dc:creator>
            <pubDate>Sat, 30 Aug 2025 19:44:30 GMT</pubDate>
            <atom:updated>2025-08-30T20:09:06.778Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Getting Started with Unit Testing in Spring Boot (A Beginner’s Guide)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@KisharaBuddika/getting-started-with-unit-testing-in-spring-boot-a-beginners-guide-19db3591aa00?source=rss-993a59612273------2"><img src="https://cdn-images-1.medium.com/max/2600/1*axYbY-_E0c8E8cM4cxCREw.png" width="7000"></a></p><p class="medium-feed-snippet">Think of your application as a big, complex machine. Unit tests are like a set of automated inspectors that check each small part of the&#xA0;&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@KisharaBuddika/getting-started-with-unit-testing-in-spring-boot-a-beginners-guide-19db3591aa00?source=rss-993a59612273------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@KisharaBuddika/getting-started-with-unit-testing-in-spring-boot-a-beginners-guide-19db3591aa00?source=rss-993a59612273------2</link>
            <guid isPermaLink="false">https://medium.com/p/19db3591aa00</guid>
            <dc:creator><![CDATA[Kishara Jayasanka]]></dc:creator>
            <pubDate>Mon, 11 Aug 2025 15:54:07 GMT</pubDate>
            <atom:updated>2025-08-11T15:54:07.299Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Spring vs Spring Boot]]></title>
            <link>https://medium.com/@KisharaBuddika/spring-vs-spring-boot-998a3d927829?source=rss-993a59612273------2</link>
            <guid isPermaLink="false">https://medium.com/p/998a3d927829</guid>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[oop-concepts]]></category>
            <dc:creator><![CDATA[Kishara Jayasanka]]></dc:creator>
            <pubDate>Thu, 22 Aug 2024 07:30:46 GMT</pubDate>
            <atom:updated>2024-08-22T07:30:46.433Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*60QD8382PSWckContYAqlQ.jpeg" /></figure><p>Spring and Spring Boot are both popular frameworks for building Java applications, but they serve different purposes and are used in different contexts. Here’s a comparison:</p><h3>Spring Framework</h3><ul><li><strong>Overview</strong>: Spring is a comprehensive framework that provides various modules for building enterprise Java applications. It offers a wide range of capabilities such as dependency injection (IoC), aspect-oriented programming (AOP), transaction management, and more.</li><li><strong>Configuration</strong>: Spring applications require extensive manual configuration, usually through XML files or annotations. Developers need to handle boilerplate code and configure beans, data sources, and other components.</li><li><strong>Flexibility</strong>: Spring provides a flexible environment where you can use only the modules or features you need. It’s highly customizable but may involve complex configurations for larger projects.</li><li><strong>Scalability</strong>: Suitable for building large, complex applications, especially in enterprise environments where full control over configuration is needed.</li></ul><h3>Spring Boot</h3><ul><li><strong>Overview</strong>: Spring Boot is built on top of the Spring Framework. It simplifies Spring application development by providing auto-configuration, an embedded server, and pre-built templates for faster setup and execution of Java applications.</li><li><strong>Configuration</strong>: Spring Boot significantly reduces the need for manual configuration. It uses default configurations and conventions, allowing you to build applications with minimal setup. Annotations like @SpringBootApplication take care of many of the underlying configurations.</li><li><strong>Embedded Server</strong>: Spring Boot includes an embedded server like Tomcat or Jetty, which means you don’t need to deploy the application to an external server; you can run it as a standalone application.</li><li><strong>Starter Dependencies</strong>: Spring Boot includes “starter” dependencies that bundle the required libraries for specific tasks (e.g., web, data, security) so that you don’t have to manage them individually.</li><li><strong>Microservices</strong>: Spring Boot is designed to help with the development of microservices due to its rapid startup, easy configuration, and lightweight nature.</li></ul><h3>Key Differences</h3><ol><li><strong>Configuration</strong>: Spring requires extensive configuration; Spring Boot simplifies this with auto-configuration and sensible defaults.</li><li><strong>Setup</strong>: Spring Boot offers pre-built templates and starter projects for faster setup. Spring involves more manual setup.</li><li><strong>Deployment</strong>: Spring Boot includes an embedded server for standalone applications, while Spring applications are usually deployed on an external server.</li><li><strong>Complexity</strong>: Spring gives more control for complex applications but can be harder to configure. Spring Boot is easier to get started with but may limit configuration flexibility in some cases.</li><li><strong>Use Case</strong>: Spring is suitable for larger, monolithic applications, while Spring Boot is ideal for microservices and small to medium-sized applications.</li></ol><p>In summary, if you’re building a new project and want to minimize configuration and focus on rapid development, <strong>Spring Boot</strong> is the better choice. For projects that require more granular control and customization, or are part of large enterprise systems, <strong>Spring</strong> might be more appropriate.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=998a3d927829" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Head First Java by Keith Sierra Chapter 18. Distributed Computing]]></title>
            <link>https://medium.com/@KisharaBuddika/head-first-java-by-keith-sierra-chapter-18-distributed-computing-6ee421c6ca68?source=rss-993a59612273------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ee421c6ca68</guid>
            <category><![CDATA[helpers]]></category>
            <category><![CDATA[distributed-computing]]></category>
            <category><![CDATA[remote-service]]></category>
            <category><![CDATA[head-first-java]]></category>
            <category><![CDATA[servlet]]></category>
            <dc:creator><![CDATA[Kishara Jayasanka]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 10:04:38 GMT</pubDate>
            <atom:updated>2022-07-19T10:04:38.701Z</atom:updated>
            <content:encoded><![CDATA[<p>The purpose of this article is to highlight the key ideas covered in the chapter.</p><h3>A design for remote method calls</h3><ol><li>Create client and server apps. The server app is the remote service that has an object with the method that the client wants to invoke.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*6jFhswl7tI2GQsJZDi7rsg.png" /></figure><p>2. Make “helpers” for the client and server. To make it appear as though your client and service are in the same heap, they will take care of all the low-level networking and I/O aspects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*lOTDF-Wi3B8COvwjkml41w.png" /></figure><h3>Helpers</h3><p>The objects that carry out the real communication are the “helpers.”<br>They enable the client to simulate the act of invoking a method on a local object. The client uses the client-helper as if it were the service by calling a method on it. The client-helper is a proxy for the Real Thing. In other words, because the client helper is impersonating the service object, the client object believes it is calling a method on the distant service. pretending to be the thing the client wishes to call with that method!</p><h4>How the method call happens</h4><ol><li>Client object calls doBigThing() on the client helper object.</li><li>Client helper packages up information about the call (arguments, method name, etc.) and ships it over the network to the service helper.</li><li>Service helper unpacks the information from the client helper, finds out which method to call (and on which object) and invokes the real method on the real service object.</li></ol><h3>Server Making the Remote Service</h3><ol><li><strong>Make a Remote Interface</strong></li></ol><p>A client’s ability to invoke methods remotely is specified by the remote interface. The polymorphic class type for your service will be what the client uses. This will be implemented in both the Stub and the actual service.</p><p><strong>2. Make a Remote Implementation</strong></p><p>The remote methods specified in the remote interface are really implemented in it. The client wants to call methods on the object.</p><p><strong>3. Generate the stubs and skeletons using rmic</strong></p><p>These are the “helpers” for the client and server. These classes are generated automatically; you don’t need to write them. When you use the rmic utility that comes with your Java development kit, everything is taken care of automatically.</p><p><strong>4. Start the RMI registry (rmiregistry)</strong></p><p>The user goes there to obtain the proxy.</p><p><strong>5. Start the remote service</strong></p><p>The service object has to be operational. The service is created by your service implementation class, and it is then registered with the RMI registry. Clients can access the service after registering.</p><h3>What about Servlets?</h3><p>Servlets are Java applications that work with and on HTTP web servers. A request is sent back to the web server whenever a client uses a web browser to interact with a web page. The web server executes (or invokes, if the servlet is already executing) the servlet code if the request requires assistance from a Java servlet.</p><p>The simplest definition of servlet code is simply code that executes on the server and performs tasks in response to client requests. CGI scripts or servlets are used by web developers to administer discussion boards, transfer user-submitted data to databases, and perform a variety of other tasks.</p><h4>Steps for making and running a servlet</h4><ol><li>Find out where your servlets need to be placed.</li><li>Get the servlets.jar and add it to your classpath</li><li>Write a servlet class by extending HttpServlet</li><li>Write an HTML page that invokes your servlet</li><li>Make your servlet and HTML page available to your server</li></ol><h3>Thank you for reading! If you enjoyed please leave a clap and follow my page.</h3><p><a href="https://medium.com/u/993a59612273?source=post_page-----14a2b67a7b7a--------------------------------">Kishara Buddika</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ee421c6ca68" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Head First Java by Keith Sierra Chapter 17. Release Your Code]]></title>
            <link>https://medium.com/@KisharaBuddika/head-first-java-by-keith-sierra-chapter-17-release-your-code-211a594cb0c1?source=rss-993a59612273------2</link>
            <guid isPermaLink="false">https://medium.com/p/211a594cb0c1</guid>
            <category><![CDATA[java-web-start]]></category>
            <category><![CDATA[jar]]></category>
            <category><![CDATA[executable-jar]]></category>
            <category><![CDATA[head-first-java]]></category>
            <category><![CDATA[source-code]]></category>
            <dc:creator><![CDATA[Kishara Jayasanka]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 06:21:24 GMT</pubDate>
            <atom:updated>2022-07-19T06:21:24.478Z</atom:updated>
            <content:encoded><![CDATA[<p>The purpose of this article is to highlight the key ideas covered in the chapter.</p><h3>Deploying the application</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/0*AwXgbdABjE-3TGWA.png" /></figure><p>An accurate definition of a Java application, What do you give when development is complete, in other words? It’s likely that your end users don’t utilize a system that is exactly like yours. They don’t have your application, which is more significant. Therefore, it is now necessary to prepare your program for release into The Outside World. We’ll examine local installations in this chapter, including Executable Jars and Java Web Start, a part-local/part-remote technology. We’ll examine the more distant deployment alternatives, such as RMI and Servlets, in the following chapter.</p><ol><li>Local</li></ol><p>The full program is executed on the the standalone PC of the end-user<br>likely a GUI, software, used as an executable JAR.</p><p>2. Combination of local and remote</p><p>The distributed application has a client component that runs on the user’s local computer and is linked to a server where other components of the program are running.</p><p>3. Remote</p><p>The client connects to the server system through a non-Java method, most often a web browser, while the complete Java program executes on the server system.</p><h3>Separate source code and class files</h3><p>Using this method, you establish a project directory, and inside of that, you construct directories labeled sources and classes. The first thing you do is save your source code (.java files) into the source directory. The challenge therefore is to build your code in a such that the results (the.class files) wind up in the classes directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/0*2LdasHak-unZ8sGB.png" /></figure><h3>JAR</h3><p>A Java ARchive is a JAR file. It is based on the pkzip file format and enables you to bundle all of your classes into a single JAR file rather than giving your client 28 class files.</p><blockquote>JAR is a executable file</blockquote><p>An executable JAR eliminates the need for the end-user to extract the class files in order to launch the application. While the class files are still in the JAR, the user may still use the program. The secret is to produce a manifest file, which is stored in the JAR and contains details about the contents within. The manifest must instruct the JVM how to create an executable JAR.</p><h4>Making an executable JAR</h4><ol><li>Make sure all of your class files are in the classes directory</li></ol><p>We’re going to refine this in a few pages, but for now, keep all your class files sitting in the directory named ‘classes’.</p><p>2. Create a manifest.txt file that states which class has the main() method</p><p>Make a text file named manifest.txt that has one line:</p><pre>Main-Class: MyApp </pre><p>3. Run the jar tool to create a JAR file that contains everything in the classes directory, plus the manifest.</p><pre>%cd MyProject/classes  %jar -cvmf manifest.txt app1.jar *.class <br><strong>OR</strong> <br>%jar -cvmf manifest.txt app1.jar MyApp.class</pre><h4>Executing the JAR</h4><p>Java is capable of running the main() method of a class after it has been loaded from a JAR file. In reality, the JAR can continue to contain the entire application. Your classes’ origins are irrelevant to the JVM as long as it can locate them. Additionally, the JVM searches any JAR files on the classpath as one of its possible locations. When the JVM wants to locate and load a class, it will look in that JAR if it can see it.</p><p>You might even be able to run the JAR file by just double-clicking it, depending on how your operating system is set up. Both Mac OS and the majority of Windows versions support this. The standard way to do this is to choose the JAR and instruct the OS to “Open with…”</p><h4>Put the classes in packages</h4><ol><li>Choose a package name</li></ol><pre>com.headfirstjava.PackageExercise</pre><p>2. Put a package statement in your class</p><p>It must appear before any import declarations as the first statement in the source code file. All classes in a source file must be in the same package as there can only be one package statement per source code file. That naturally encompasses the inner classes.</p><p>3. Set up a matching directory structure</p><h4>Making an executable JAR with packages</h4><ol><li>Make sure all of your class files are within the correct package structure, under the classes directory.</li><li>Create a manifest.txt file that states which class has the main() method, and be sure to use the fully-qualified class name!</li><li>Run the jar tool to create a JAR file that contains the package directories plus the manifest</li></ol><h4>Java Web Start</h4><blockquote>End-users launch a Java Web Start app by clicking on a link in a Web page. But once the app downloads, it runs outside the browser, just like any other stand-alone Java application. In fact, a Java Web Start app is just an executable JAR that’s distributed over the Web.</blockquote><ol><li>The client clicks on a Web page link to your JWS application (a .jnlp file).</li><li>The Web server (HTTP) gets the request and sends back a .jnlp file (this is NOT the JAR).</li><li>Java Web Start (a small ‘helper app’ on the client) is started up by the browser. The JWS helper app reads the .jnlp file, and asks the server for the MyApp.jar file.</li><li>The Web server ‘serves’ up the requested .jar file.</li><li>Java Web Start gets the JAR and starts the application by calling the specified main( ) method (just like an executable JAR).</li></ol><h3>Thank you for reading! If you enjoyed please leave a clap and follow my page.</h3><p><a href="https://medium.com/u/993a59612273?source=post_page-----14a2b67a7b7a--------------------------------">Kishara Buddika</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=211a594cb0c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Head First Java by Keith Sierra Chapter 16. Data structures]]></title>
            <link>https://medium.com/@KisharaBuddika/head-first-java-by-keith-sierra-chapter-16-data-structures-c208bda6d43c?source=rss-993a59612273------2</link>
            <guid isPermaLink="false">https://medium.com/p/c208bda6d43c</guid>
            <category><![CDATA[head-first-java]]></category>
            <category><![CDATA[generic-class]]></category>
            <category><![CDATA[apis-collections]]></category>
            <category><![CDATA[generic-methods]]></category>
            <category><![CDATA[collection]]></category>
            <dc:creator><![CDATA[Kishara Jayasanka]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 18:01:55 GMT</pubDate>
            <atom:updated>2022-07-18T18:01:55.273Z</atom:updated>
            <content:encoded><![CDATA[<p>The purpose of this article is to highlight the key ideas covered in the chapter.</p><h3>Collection</h3><ul><li><strong>TreeSet</strong> avoids duplications and keeps the elements sorted</li><li><strong>HashMap</strong> Lets you store and access elements as name/value pairs.</li><li><strong>LinkedList</strong> Makes it easy to create structures like stacks or queues.</li><li><strong>HashSet</strong> Prevents duplicates in the collection, and given an element, can find that element in the collection quickly.</li><li><strong>LinkedHashMap</strong> Similar to a normal HashMap, with the exception that it may be customized to remember the order in which entries (name/value pairs) were most recently read.</li></ul><h4>Collections.sort() method</h4><p>The Strings (the song titles) would be alphabetically sorted and placed in the proper order if they were all entered into a TreeSet rather than an ArrayList. The list’s components would always appear in alphabetical order when printed.</p><pre>Collections.sort()</pre><h4>Generics</h4><p>Almost all of the generics-related code you write will be collection-related stuff. Although generics have other applications, their primary purpose is to enable the creation of type-safe collections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/0*4LBZQ5yqR2oVpZ1R.png" /></figure><ol><li>Creating instances of generified classes (like ArrayList)</li></ol><p>Like with regular arrays, you must specify the kind of objects you want to be allowed in an ArrayList when you create it.</p><pre>new ArrayList&lt;Song&gt;()</pre><p>2. Declaring and assigning variables of generic types</p><pre>List&lt;Song&gt; songList =  new ArrayList&lt;Song&gt;()</pre><p>3. Declaring (and invoking) methods that take generic types</p><pre>void foo(List&lt;Song&gt; list) <br>x.foo(songList)</pre><h4>Generic Classes</h4><p>In a generified class, the two important aspects to consider,</p><ol><li>The <em>class</em> declaration</li><li>The <em>method</em> declarations that let you add elements</li></ol><h4>Generic Methods</h4><p>A generic method is one that includes a type parameter in its signature in the method declaration. There are numerous methods to utilize type parameters in a method:</p><ol><li>Using a type parameter defined in the class declaration</li></ol><pre>public class ArrayList<strong>&lt;E&gt;</strong> extends AbstractList<strong>&lt;E&gt;</strong> ... {<br>     public boolean add(<strong>E</strong> o)</pre><p>2. Using a type parameter that was NOT defined in the class declaration</p><pre>public <strong>&lt;T extends Animal&gt;</strong> void takeThing(ArrayList<strong>&lt;T&gt;</strong> list)</pre><blockquote>In generics, the keyword “extends” really means “is-a”, and works for BOTH classes and interfaces.</blockquote><h3>We need a Set instead of a List</h3><ul><li><strong>LIST</strong> — when sequence matters Collections that know about index position. Lists know where something is in the list. You can have more than one element referencing the same object</li><li><strong>SET</strong> — when uniqueness matters Collections that do not allow duplicates. Sets know whether something is already in the collection. You can never have more than one element referencing the same object (or more than one element referencing two objects that are considered equal — we’ll look at what object equality means in a moment).</li><li><strong>MAP</strong> — when finding something by key matters Collections that use key-value pairs. Maps know the value associated with a given key. You can have two keys that reference the same value, but you cannot have duplicate keys. Although keys are typically String names (so that you can make name/value property lists, for example), a key can be any object.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/0*KouKLyTqtwyCQ_js.png" /></figure><h3>The Collection API</h3><p>Despite the fact that the Map interface does not technically extend the Collection interface, the “Collection Framework” (also known as the “Collection API”) nonetheless includes the Map interface. Therefore, even if Maps don’t include java.util, they are still collections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/0*FWuGsbOdNnYv1zMp.png" /></figure><h3>Thank you for reading! If you enjoyed please leave a clap and follow my page.</h3><p><a href="https://medium.com/u/993a59612273?source=post_page-----14a2b67a7b7a--------------------------------">Kishara Buddika</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c208bda6d43c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Head First Java by Keith Sierra Chapter 15. Make a Connection]]></title>
            <link>https://medium.com/@KisharaBuddika/head-first-java-by-keith-sierra-chapter-15-make-a-connection-bcfca9d62019?source=rss-993a59612273------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcfca9d62019</guid>
            <category><![CDATA[runnable]]></category>
            <category><![CDATA[socket-connection]]></category>
            <category><![CDATA[head-first-java]]></category>
            <category><![CDATA[threads]]></category>
            <category><![CDATA[multithreading]]></category>
            <dc:creator><![CDATA[Kishara Jayasanka]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 14:56:57 GMT</pubDate>
            <atom:updated>2022-07-18T14:56:57.103Z</atom:updated>
            <content:encoded><![CDATA[<p>The purpose of this article is to highlight the key ideas covered in the chapter.</p><h3>Connecting, Sending, and Receiving</h3><p>To get the client to work, we must learn the following three things:</p><ol><li>How to establish the initial <strong>connection</strong> between the client and server.</li><li>How to <strong>send</strong> messages to the server.</li><li>How to <strong>receive</strong> messages from the server</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/0*IwIYNE0RVI_OA92f" /><figcaption>Connecting, Sending, and Receiving — Head First Java, 2nd Edition by Kathy Sierra, Bert Bates</figcaption></figure><h3>Make a network Socket connection</h3><ul><li>We require a Socket connection in order to connect to another machine.</li><li>An object that represents a network connection between two machines is called a Socket (java.net.Socket class).</li></ul><blockquote>A connection is a relationship between two computers in which two software programs are aware of one another.</blockquote><p>Most significantly, the two pieces of software are capable of interacting with one another. They both know how to send bits to one another.</p><pre>Socket chatSocket = new Socket(“196.164.1.103”, 5000);</pre><p>IP address for the server</p><pre>196.164.1.103</pre><p>IP address for the server</p><pre>5000</pre><p>Our web(HTTP) server on the internet is known to run on port 80. It is impossible if you claim to lack a port number. because without a port number, a client cannot indicate the client application they wish to connect to on the server. In addition, each application could use a different protocol. For well-known services, the TCP port range of 0 to 1023 is set aside. Don’t use them for your own programs. Because we can only utilize ports 1024 to 65535, as was previously indicated, the socket we are creating uses port 5000.</p><h3>Reading from a Socket</h3><p>Streams are used for communication across a Socket connection.<br>I/O streams that are standard, like the ones we used in the last chapter. The fact that the majority of your I/O operations won’t care what your high-level chain stream is really linked to is one of Java’s finest features.</p><ol><li>Make a Socket connection to the server</li></ol><pre>Socket chatSocket = new Socket(“127.0.0.1”, 5000);</pre><p>2. Make an InputStreamReader chained to the Socket’s low-level (connection) input stream</p><pre>InputStreamReader stream = new InputStreamReader(chatSocket.getInputStream());</pre><p>3. Make a BufferedReader and read!</p><pre>BufferedReader reader = new BufferedReader(stream);<br>String message = reader.readLine();</pre><h3>Write data to a Socket</h3><p>Data may be written to a socket using PrintWriter. PrintWriter is the default option for writing one String at a time. You’ll also be able to identify PrintWriter’s two most important functions, print() and println().</p><ol><li>Make a Socket connection to the server</li></ol><pre>Socket chatSocket = new Socket(“127.0.0.1”, 5000);</pre><p>2. Make a PrintWriter chained to the Socket’s low-level (connection) output stream</p><pre>PrintWriter writer = new PrintWriter(chatSocket.getOutputStream());</pre><p>3. Write (print) something</p><pre>writer.println(“message to send”); <br>writer.print(“another message”);</pre><h3>Multithreading in Java</h3><p>Java’s multithreading functionality enables the concurrent execution of two or more software components for optimal CPU efficiency. A thread refers to each component of such a software. Thus, threads are quick processes contained within a process.</p><pre>Thread t = new Thread(); t.start();</pre><p>There are two ways available for creating threads:</p><ol><li>Extending the Thread class</li><li>Implementing the Runnable Interface</li></ol><h4>What does it mean to have more than one call stack?</h4><ol><li>The JVM calls the main( ) method.</li></ol><pre>public static void main(String[] args) {}</pre><p>2. main( ) starts a new thread. The main thread is temporarily frozen while the new thread starts running.</p><pre>Runnable r = new MyThreadJob();<br>Thread t = new Thread(r); <br>t.start(); <br>Dog d = new Dog();</pre><p>3. The JVM switches between the new thread (user thread A) and the original main thread, until both threads complete.</p><h4>Launch a new thread</h4><ol><li>Make a Runnable object (the thread’s job)</li></ol><pre>Runnable threadJob = new MyRunnable();</pre><p>2. Make a Thread object (the worker) and give it a Runnable (the job)</p><pre>Thread myThread = new Thread(threadJob);</pre><p>3. Start the Thread</p><pre>myThread.start();</pre><h4>Runnable interface</h4><pre>public class MyRunnable implements <strong>Runnable</strong></pre><p>A class whose instances can be executed as threads is described by the Runnable interface. The interface itself is quite straightforward and only describes the run function, which Java automatically invokes when the thread is started.</p><p>Typically, the Thread class is used in combination with the Runnable interface.</p><h4>The Thread Scheduler</h4><p>All decisions on who moves from runnable to running and when (and under what conditions) a thread exits the running state are made by the thread scheduler. When the scheduler chooses to remove threads from the state where they are currently running, it decides who runs, for how long, and where the threads go. There are two types of scheduling for threads.</p><ol><li><strong>Preemptive scheduling</strong></li></ol><p>With preemptive scheduling, tasks are often allocated according to their priority. Even while the lower priority operation is still in progress, it is occasionally essential to run the higher priority activity first. After that happens, the lower priority work is put on hold for a while before picking back up when the higher priority activity is finished.</p><p><strong>2. Time-Sliced Scheduling</strong></p><p>Java uses a technique called time slicing to distribute time among threads. The fundamental of time-slicing is non-priority scheduling. Every operating thread is given a set amount of time to complete its execution under this scheduling.</p><h4>BULLET POINTS</h4><ul><li>Client and server applications communicate over a Socket connection.</li><li>A Socket represents a connection between two applications which may (or may not) be running on two different physical machines.</li><li>A client must know the IP address (or domain name) and TCP port number of the server application.</li><li>A TCP port is a 16-bit unsigned number assigned to a specific server application. TCP port numbers allow different clients to connect to the same machine but communicate with different applications running on that machine.</li><li>The port numbers from 0 through 1023 are reserved for ‘well-known services’ including HTTP, FTP, SMTP, etc.</li><li>A client connects to a server by making a Server socket</li></ul><pre>Socket s = new Socket(“127.0.0.1”, 4200);</pre><ul><li>Once connected, a client can get input and output streams from the socket. These are low-level ‘connection’ streams.</li></ul><pre>sock.getInputStream(); <br>sock.getOutputStream();</pre><ul><li>To read text data from the server, create a BufferedReader, chained to an InputStreamReader, which is chained to the input stream from the Socket.</li><li>InputStreamReader is a ‘bridge’ stream that takes in bytes and converts them to text (character) data. It’s used primarily to act as the middle chain between the high-level BufferedReader and the low-level Socket input stream.</li><li>To write text data to the server, create a PrintWriter chained directly to the Socket’s output stream. Call the print() or println() methods to send Strings to the server.</li><li>Servers use a ServerSocket that waits for client requests on a particular port number.</li><li>When a ServerSocket gets a request, it ‘accepts’ the request by making a Socket connection with the client.</li></ul><h3>Thank you for reading! If you enjoyed please leave a clap and follow my page.</h3><p><a href="https://medium.com/u/993a59612273?source=post_page-----14a2b67a7b7a--------------------------------">Kishara Buddika</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcfca9d62019" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Head First Java by Keith Sierra Chapter 14. Saving Objects]]></title>
            <link>https://medium.com/@KisharaBuddika/head-first-java-by-keith-sierra-chapter-14-saving-objects-d8572b44b39a?source=rss-993a59612273------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8572b44b39a</guid>
            <category><![CDATA[serialization]]></category>
            <category><![CDATA[deserialization]]></category>
            <category><![CDATA[head-first-java]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[objects]]></category>
            <dc:creator><![CDATA[Kishara Jayasanka]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 10:47:16 GMT</pubDate>
            <atom:updated>2022-07-18T10:47:16.074Z</atom:updated>
            <content:encoded><![CDATA[<p>The purpose of this article is to highlight the key ideas covered in the chapter.</p><h3>Java Serialization</h3><p>Through a process called object serialization, which is provided by Java, an object may be represented as a sequence of bytes that contains the object’s contents as well as details about its type and the sorts of data it stores. A serialized object may be read from a file after it has been written there and deserialized, which means that it can be recreated in memory using the type information and bytes that describe the object and its contents. The fact that the entire procedure is JVM independent, allowing an object to be serialized on one platform and deserialized on a totally other platform, is what makes it so great.</p><h3>What are the Advantages of Serialization?</h3><ul><li>Used for marshaling (traveling the state of an object on the network)</li><li>To persist or save an object’s state</li><li>JVM independent</li><li>Easy to understand and customize</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/0*w2TYDd3qTJV35DHg.jpg" /></figure><h3><strong>Writing a serialized object to a file</strong></h3><ol><li>Make a FileOutputStream</li></ol><pre>FileOutputStream fileStream = new FileOutputStream(“MyGame.ser”);</pre><p>2. Make an ObjectOutputStream</p><pre>ObjectOutputStream os = new ObjectOutputStream(fileStream);</pre><p>3. Write the object</p><pre>os.writeObject(characterOne); <br>os.writeObject(characterTwo); <br>os.writeObject(characterThree);</pre><p>4. Close the ObjectOutputStream</p><pre>os.close();</pre><h3>Deserialization</h3><p>The purpose of serializing an object is to enable its restoration to its initial state at a later time, during a different “run” of the JVM (which could not even be the same JVM that was running at the time the object was serialized).<br>In many ways, deserialization is just serialization in reverse.</p><ol><li>Make a FileInputStream</li></ol><pre>FileInputStream fileStream = new FileInputStream(“MyGame.ser”);</pre><p>2. Make an ObjectInputStream</p><pre>ObjectInputStream os = new ObjectInputStream(fileStream);</pre><p>3. Read the objects</p><pre>Object one = os.readObject(); <br>Object two = os.readObject(); <br>Object three = os.readObject();</pre><p>4. Cast the objects</p><pre>GameCharacter elf = (GameCharacter) one;<br>GameCharacter troll = (GameCharacter) two;<br>GameCharacter magician = (GameCharacter) three;</pre><p>5. Close the ObjectInputStream</p><pre>os.close();</pre><h3>Thank you for reading! If you enjoyed please leave a clap and follow my page.</h3><p><a href="https://medium.com/u/993a59612273?source=post_page-----14a2b67a7b7a--------------------------------">Kishara Buddika</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8572b44b39a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Head First Java by Keith Sierra Chapter 13. Work on Your Swing]]></title>
            <link>https://medium.com/@KisharaBuddika/head-first-java-by-keith-sierra-chapter-13-work-on-your-swing-7a9acd298a50?source=rss-993a59612273------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a9acd298a50</guid>
            <category><![CDATA[constructor]]></category>
            <category><![CDATA[jframe]]></category>
            <category><![CDATA[jtextfield]]></category>
            <category><![CDATA[head-first-java]]></category>
            <category><![CDATA[layoutmanager]]></category>
            <dc:creator><![CDATA[Kishara Jayasanka]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 09:54:19 GMT</pubDate>
            <atom:updated>2022-07-18T09:54:19.555Z</atom:updated>
            <content:encoded><![CDATA[<p>The purpose of this article is to highlight the key ideas covered in the chapter.</p><h3>Swing components</h3><p>What we’ve been referring to as a widget is actually a component.<br>The elements you include in a GUI. The elements that a user interacts with and sees.</p><ul><li>Text fields</li><li>Buttons</li><li>Scrollable lists</li><li>Radio buttons</li></ul><p>They all extend <strong>javax.swing.JComponent</strong></p><h3>Layout Manager</h3><p>A Java object known as a layout manager is connected to a certain component, which is generally often a background component. The component with which the layout manager is related also contains other components under its control.</p><h3>Border, Flow, and box — The Big Three layout managers:</h3><p><strong>BorderLayout —</strong> Five areas are created on a background component by a BorderLayout manager. A BorderLayout manager-controlled background can only have one component added per region. This manager often doesn’t get to specify the exact size of the components. The frame’s default layout manager is called BorderLayout.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*rM_HfIgJQD362iqE.png" /></figure><p><strong>FlowLayout</strong> — A FlowLayout manager functions somewhat similarly to a word processor, but uses components rather of words. Each element is the size it desires, and with “word-wrap” enabled, they are arranged from left to right in the order that they are inserted. A component moves to the following “line” in the layout when it cannot fit horizontally. The panel’s default layout manager is FlowLayout.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/0*wqbnHIL20lOw29di.png" /></figure><p><strong>BoxLayout —</strong> Similar to a FlowLayout manager, a BoxLayout manager places the components in the order they are added and allows each component to have its own size. A BoxLayout manager, however, may stack the components vertically (or horizontally, but often we’re just concerned with vertically) unlike FlowLayout. Similar to a FlowLayout, except that you may enter a kind of “component return key” to force the components to begin a new line rather than having automated “component wrapping” occur.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/203/0*gHZpt5z5KmfbIkke.png" /></figure><h3>Playing with Swing components</h3><h4>JTextField</h4><p><strong>Constructors</strong></p><pre>JTextField field = new JTextField(20);<br>JTextField field = new JTextField(“Your name”);</pre><p><strong>How to use it</strong></p><ol><li>Get text out of it</li></ol><pre>System.out.println(field.getText());</pre><p>2. Put text in it</p><pre>field.setText(“whatever”); <br>field.setText(““);</pre><p>3. Get an ActionEvent when the user presses return or enter</p><pre>field.addActionListener(myActionListener); 3</pre><p>4. Select/Highlight the text in the field</p><pre>field.selectAll();</pre><p>5. Put the cursor back in the field (so the user can just start typing)</p><pre>field.requestFocus();</pre><h4>JTextArea</h4><p><strong>Constructor</strong></p><pre>JTextArea text = new JTextArea(10,20);</pre><p><strong>How to use it</strong></p><ol><li>Make it have a vertical scrollbar only</li></ol><pre>JScrollPane scroller = new JScrollPane(text); text.setLineWrap(true); scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); panel.add(scroller);</pre><p>2. Replace the text that’s in it</p><pre>text.setText(“Not all who are lost are wandering”);</pre><p>3. Append to the text that’s in it</p><pre>text.append(“button clicked”);</pre><p>4. Select/Highlight the text in the field</p><pre>text.selectAll();</pre><p>5. Put the cursor back in the field</p><pre>text.requestFocus();</pre><h4>JList</h4><p><strong>Constructor</strong></p><pre>String [] listEntries = {“alpha”, “beta”, “gamma”, “delta”,  “epsilon”, “zeta”, “eta”, “theta “};<br>JList list = new JList(listEntries);</pre><p><strong>How to use it</strong></p><ol><li>Make it have a vertical scrollbar</li></ol><pre>JScrollPane scroller = new JScrollPane(list); scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); panel.add(scroller);</pre><p>2. Set the number of lines to show before scrolling</p><pre>list.setVisibleRowCount(4);</pre><p>3. Restrict the user to selecting only ONE thing at a time</p><pre>list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);</pre><p>4. Register for list selection events</p><pre>list.addListSelectionListener(this);</pre><p>5. Handle events (find out which thing in the list was selected)</p><pre>public void valueChanged(ListSelectionEvent lse) {<br> if( !lse.getValueIsAdjusting()) {<br>  String selection = (String) list.getSelectedValue();<br>  System.out.println(selection);<br>  }<br>}</pre><h3>Thank you for reading! If you enjoyed please leave a clap and follow my page.</h3><p><a href="https://medium.com/u/993a59612273?source=post_page-----14a2b67a7b7a--------------------------------">Kishara Buddika</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a9acd298a50" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>