<?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 Dan Dias Abeyesinghe on Medium]]></title>
        <description><![CDATA[Stories by Dan Dias Abeyesinghe on Medium]]></description>
        <link>https://medium.com/@dandiasabeyesinghe?source=rss-c69cd41223f5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*k-W5mY6wdk4F1smRda8BEw.jpeg</url>
            <title>Stories by Dan Dias Abeyesinghe on Medium</title>
            <link>https://medium.com/@dandiasabeyesinghe?source=rss-c69cd41223f5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 01:04:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dandiasabeyesinghe/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[States and Life Cycle of a Java Thread]]></title>
            <link>https://medium.com/javarevisited/states-and-life-cycle-of-a-java-thread-6f9187ece4da?source=rss-c69cd41223f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f9187ece4da</guid>
            <category><![CDATA[java-thread]]></category>
            <category><![CDATA[thread-synchronization]]></category>
            <category><![CDATA[thread-safe]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[multithreading]]></category>
            <dc:creator><![CDATA[Dan Dias Abeyesinghe]]></dc:creator>
            <pubDate>Sun, 14 Jan 2024 10:32:38 GMT</pubDate>
            <atom:updated>2024-01-14T10:32:38.651Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QzVnGlWJHH7xYeq6" /><figcaption>Photo by <a href="https://unsplash.com/@ikukevk?utm_source=medium&amp;utm_medium=referral">Kevin Ku</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>What are Java Threads? A Java thread can be defined as the smallest unit of execution in a Java program, representing an independent path of execution. This allows concurrent execution of many tasks within the same program which results in parallel processing and utilization of system resources. To get a clearer understanding of what Java Threads are and how those are implemented check out my article on <a href="https://medium.com/javarevisited/basics-of-multithreading-in-java-1f3c2f3b6d31">Basics of MultiThreading in Java</a>.</p><p>Moving on to the life cycle of a Java Thread, a thread could be in many states during its lifetime, it can be divided into 6 states namely,</p><p>· <strong>NEW</strong></p><p>· <strong>RUNNABLE</strong></p><p>· <strong>WAITING</strong></p><p>· <strong>TIMED_WAITING</strong></p><p>· <strong>BLOCKED</strong></p><p>· <strong>TERMINATED</strong></p><p>Below diagram is an overview of the life cycle of a Thread at a high level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*_DhYGW-rOiNipsiQwqfrag.png" /></figure><p>We will go through each state and see what each state is about.</p><p><strong>NEW STATE</strong></p><p>This state is the initial state where a thread could be in, this is the state where a thread is when the Thread object is created but not yet started. In this state, no resources are allocated to it and its <strong><em>run()</em></strong> method is not yet invoked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*JJxPJGGWwHkXHAyyMKipFQ.png" /></figure><p>As shown in the above code snipped a thread can be in the <strong>NEW</strong> state when an object is created. When a thread is in this state it is considered to be an empty object and when in this state a thread can only be started by calling the <strong><em>start()</em></strong> method. Keep in mind that calling any other method except for the <strong><em>start()</em></strong> method will not work and will cause an <em>IllegalThreadStateExpression</em>.However, it is important to call the<strong><em> start()</em></strong> method instead of the <strong><em>run()</em></strong> and its importance is further discussed in the <a href="https://medium.com/javarevisited/basics-of-multithreading-in-java-1f3c2f3b6d31">Basics of Multithreading</a> article.</p><p><strong>RUNNABLE</strong> <strong>STATE</strong></p><p>The transition to this state happens when a newly created thread calls the <strong><em>start()</em></strong> method, when called the<strong><em> start()</em></strong> method the system will first allocate resources to the thread, schedule it and finally it will invoke the <strong><em>run()</em></strong> method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*9UOAFMYzl6ZZmiAqySUdSg.png" /></figure><p>However, it is important to note that being in the <strong>RUNNABLE</strong> state doesn’t necessarily mean that a thread is executing. It is totally up to the JVM scheduler which uses the Fixed Priority Pre-emptive Scheduling approach. An example of a thread being in the <strong>RUNNABLE</strong> state and not running is when a thread is waiting for the processor or other resources from the system. The JVM uses context switching to switch between processes in the Ready and Running states. A clear explanation of it is given below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*IXpWaPxtH8JyFQY4fmiAPQ.png" /><figcaption>Inside the Runnable state</figcaption></figure><p>As seen above there are two states inside the <strong>RUNNABLE</strong> state which are called ready and running respectively, simply when a thread is executing it is in the running state and for any reasons mentioned in the diagram above it has to wait, then it will move to the ready state letting another thread begin its execution, it is important to remember when a thread is pre-empted it does not go to the <strong>BLOCKED</strong> state but instead it will move the ready state.</p><p><strong>BLOCKED STATE</strong></p><p>This state is considered a “<strong>NON-RUNNABLE STATES</strong>” as threads in these states are not available for execution and are usually waiting for some operation completion. states <strong>WAITING</strong> and <strong>TIME_WAITING</strong> fall under this category.</p><p>When a thread is in the <strong>BLOCKED</strong> state, it means that the thread is waiting to obtain a monitor lock to enter or re-enter a synchronized block or method. The thread is temporarily unable to run because it is trying to access a resource that is currently held by another thread and will be in the <strong>BLOCKED</strong> state until it acquires the lock.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*nV36nNAcXpu9J_oKeYhQNQ.png" /></figure><p>As shown above, the increment method is a <em>synchronized</em> method which means at any given time only a single thread can access the method and it is made possible by acquiring the monitor synchronization lock. When multiple threads compete to get the lock, only the thread that acquires it will be able to enter into the body of the synchronized method (<em>critical section</em>) while other threads that are in the <strong>RUNNABLE</strong> state will move to the <strong>BLOCKED</strong> state and will remain until the thread with the object lock is done performing and releases the lock.</p><p><strong>WAITING STATE</strong></p><p>There are various reasons why a thread in the <strong>RUNNABLE</strong> state goes into the <strong>WAITING</strong> state. One is when the thread calls the<strong><em> wait()</em></strong> method on itself it will release the lock and go into the <strong>WAITING</strong> state until <strong><em>notify()</em></strong> or <strong><em>notifyAll()</em></strong> is called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*mcIGyuDLtpOlLEcfY3q8bg.png" /></figure><p>In the above code snippet the <strong><em>wait()</em></strong> method is called and it will release its lock and move from the <strong>RUNNABLE</strong> state to the <strong>WAITING</strong> state until <strong><em>notify()</em></strong> and <strong><em>notifyAll()</em></strong> is called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*TSWZywLkFUlJpFTUNnVHvw.png" /></figure><p>The difference between <strong><em>notify()</em></strong> and <strong><em>notfiyAll()</em></strong> is that notify will wake up one random thread only and <strong><em>notifyAll()</em></strong> will wake up all threads in the <strong>WAITING</strong> state.</p><p>Another reason for a thread to go into the <strong>WAITING</strong> state is the use of the <strong><em>join()</em></strong> method which is used to make a thread wait for another thread to complete its execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*aw71HjC4wHoSAEP-ZmGIUA.png" /></figure><p><strong>TIMED_WAITING STATE</strong></p><p>A thread that is waiting for a specific time can be found in the <strong>TIMED-WAITING</strong> state. This state often occurs when a thread invokes methods like <strong><em>sleep(t)</em></strong>, <strong><em>wait(t)</em></strong>, or <strong><em>join(t) </em></strong>with a specified timeout. During <strong>TIMED_WAITING </strong>state, the thread is waiting for either the specified time to elapse or until <strong><em>notify()</em></strong>, <strong><em>notify()</em></strong> is called to wake the threads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*zsK6Ysnu1bYJM7qFvl2XZQ.png" /></figure><p>Here a thread can be put into sleep for a specific time which makes it release its resources and move from the <strong>RUNNABLE</strong> to <strong>TIMED_WAITING</strong> state and <strong><em>wait(t)</em></strong> is similar to this as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*IOD7UN3TB_TbrkTqar5e8Q.png" /></figure><p>Here the <strong><em>join()</em></strong> method can also be used with a specific time to indicate that the join would occur after time expiration.</p><p><strong>TERMINATED STATE</strong></p><p>The final state a thread could be in is this state. This state indicates that a thread has completed its execution. Once a thread finishes running its <strong><em>run()</em></strong> method or if an uncaught exception terminates its execution, the thread enters the <strong>TERMINATED</strong> state. A thread in the <strong>TERMINATED</strong> state cannot be restarted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*KMwRYtoS1F9yTUoOgT3asQ.png" /></figure><p>So in the above, we covered all the states and the life cycle of a Thread from the time it is created until its termination. I hope this article was beneficial and helped you to get a better and clearer understanding of what the states and the life cycle of a Thread are about. Please do feel free to provide feedback on the above and follow for more articles related to this and many more!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f9187ece4da" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/states-and-life-cycle-of-a-java-thread-6f9187ece4da">States and Life Cycle of a Java Thread</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generics and wild card concepts]]></title>
            <link>https://medium.com/javarevisited/generics-and-wild-card-concepts-711d5d0b1b26?source=rss-c69cd41223f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/711d5d0b1b26</guid>
            <category><![CDATA[java-development]]></category>
            <category><![CDATA[introduction-to-java]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[generics-in-java]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Dan Dias Abeyesinghe]]></dc:creator>
            <pubDate>Mon, 08 May 2023 15:46:01 GMT</pubDate>
            <atom:updated>2023-05-08T15:46:01.781Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Go9XSYc1lPKGZBbM" /><figcaption>Photo by <a href="https://unsplash.com/@writecodenow?utm_source=medium&amp;utm_medium=referral">Boitumelo Phetla</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Generics can be considered as a facility of generic programming. This was mainly designed to extend Java’s type system to allow a type or method to operate on objects of various types while providing compile-time type safety.</p><p>The word Generics means parameterized types. This means that it will allow the type (String, Integer, user-designed types… etc.) to be a parameter in interfaces, classes and methods. So, any interface, class or method can use any datatype (only reference types) with this concept of generics. In simple words it allows the user to decide the data type that can be used by a constructor of a class, and method which makes it possible dynamically. finally, we can conclude that it is possible to create classes that work with different data types using generics.</p><h3>Generic Class</h3><p>We can use &lt;&gt; to specify the parameter type when we are creating a generic class. However, it is important to note that we cannot use primitive data types like int, char or double. Look at the below code where we have created a Generic Class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YpUJWQFiYFv0AlHxoPr_4A.png" /></figure><pre>Output<br>50<br>Hello world</pre><p>As we can see above, we have created a class called “GenericClass where the type of the class is set to” Type”, and we have declared an object of type “Type”. Then in the main class, we have created an instance of the class of Integer type first and then of String type and the output of those two can be seen respectively as the output.</p><p>Also, note that it is possible to have multiple Type parameters passed to the Generic Class. In simple words, we can have multiple parameters with different types passed into a class. Look at the below example code snippet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SwwSjFtd_uCPXKOZFHFl_g.png" /></figure><pre>Output<br>50<br>Hello World</pre><p>As we can see in the above code snippet, we have declared 2 types of objects, one being of type “Type” and the other being of type “S”. We can see we can use multiple Type of parameters in the Generic class too.</p><h3>Wild card concepts</h3><p>The wild card concept follows the procedure of allowing an unknown type to be passed as a parameter instead of a type parameter used in generics.</p><p>The only limitation or restriction of the wild card concept is that it cannot be used as type argument as generics while invoking it.</p><p>Java has 3 types of Wild card concepts, those are,</p><p>· <strong>Upper bounded</strong></p><p>· <strong>Lower bounded</strong></p><p><strong>· Unbounded</strong></p><h4><strong>Upper bounded</strong></h4><p>This is similar to bounded types in generics. This method allows us to use all the subtypes of the defined class as a typed parameter.</p><p>This restricts the unknown type to a specific type or a subtype.</p><p>For example, if a certain function wants to accept the Number type and its subtypes of it, we can make it possible by just adding a <strong><em>“?”</em></strong> followed by the <strong><em>“extend”</em></strong> keyword and the class name.</p><p>Look at the code snippet below to understand it better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zbnzfQlHGv4OP0dsKhrPMA.png" /></figure><p>In the above code snippet, a collection object is accepted as a parameter with the type of the parameter as a subclass of the Number class. However, if you pass any other type other than the subclass type of a Number you will get an error. (<strong><em>“passing a String would cause an error”</em></strong>).</p><h4>Lower bounded</h4><p>As the upper bounded allows to use of all subtypes of a class as a typed parameter, the same way lower bound restricts the unknown type to a particular type or supertype of the class.</p><p>To create a lower bounded card, we can do it by adding a “?” followed by a super keyword and the class name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OW6wzvCznY-_hkjHms06bw.png" /></figure><p>In the above code snippet, a collection object is accepted as earlier with the type of the parameter being of a superclass of the Integer class. Again, as before if a collection object with a different type parameter than the integer class and its supertype is passed, the code will generate a compile error.</p><h4>Unbounded</h4><p>This allows the usage of all the subtypes of an unknown type. Here any object type of parameter is accepted.</p><p>To use this, we simply add<strong><em> “?”</em></strong> as the typed parameter inside brackets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LfyRI8ucJWpE9CIG_xtTEQ.png" /></figure><p>As seen above if you want to accept an ArrayList of object type as a parameter we can use the unbounded method. However, if we pass a list object created from arrays and it contains <strong>primitive types,</strong> a compile-time error will be generated.</p><p>I hope this article on the brief introduction to Generics and wild card concepts helped you to get a better and clear understanding of the discussed topics. Please do feel free to provide feedback on the above and do follow for more articles related to this and many more!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=711d5d0b1b26" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/generics-and-wild-card-concepts-711d5d0b1b26">Generics and wild card concepts</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basics of Multithreading in Java]]></title>
            <link>https://medium.com/javarevisited/basics-of-multithreading-in-java-1f3c2f3b6d31?source=rss-c69cd41223f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f3c2f3b6d31</guid>
            <category><![CDATA[java-thread]]></category>
            <category><![CDATA[multithreading-in-java]]></category>
            <category><![CDATA[runnable]]></category>
            <category><![CDATA[java-multithreading]]></category>
            <category><![CDATA[threading-in-java]]></category>
            <dc:creator><![CDATA[Dan Dias Abeyesinghe]]></dc:creator>
            <pubDate>Wed, 26 Jan 2022 14:10:52 GMT</pubDate>
            <atom:updated>2022-01-26T15:31:41.699Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HkozV8PpZfnSuy9M91AHlA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@lucabravo">Luca Bravo</a> on <a href="https://unsplash.com/">Unsplash</a></figcaption></figure><h3>Basics in creating Threads in Java</h3><p>What is multi-threading? In simple terms multithreading is the process of parallel execution of two or more parts of a program with the intention of maximum utilization of the CPU.</p><p>Nowadays a computer can perform more than one task at a time and that is thanks to the multithreading concept. There are two ways this process can be handled by the computer, one is using a single processor where time shifting is used, and the other is using multiple processors where multiple tasks are run.</p><p>There are two types of multi-tasking,</p><p>· Process based</p><p>· Thread based</p><p>Process based multitasking is something like you could listen to music using your music player, working on a project using VS code and at the same time use your browser to surf the internet.</p><p>Thread based multitasking could be something like you could surf through the internet while downloading some files from the internet at the same time. Here surfing and downloading are done on two different threads at the same time.</p><h3>Types of threads</h3><p>As we all know the Java virtual machine consists of number of threads. It mainly consists of Application threads and system threads.</p><p>System threads can be broken down into Garbage Collector thread, Virtual Machine thread and complier thread.</p><p>However, the developer is allowed to create many threads as they wish in the application but that also depends on the type of JVM used.</p><h3>Creating a Thread</h3><p>There are two ways of creating a thread.</p><p>1. By extending the Thread class</p><p>2. By implementing the Runnable interface</p><h4>By extending the Thread class</h4><p>Here what we do is we create a class where it extends the Thread class and the run() method in the Thread class is overridden by the class created. Next we create a new object of the class we created and call the start() method to start the execution of the Thread. The run() method is what is executed when the start() method is called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*0nPPH4gPCMkaBMynBz1NUQ.png" /><figcaption>Extending the Thread class</figcaption></figure><p>Here as it is clear from the above code snippet, a class named ‘MyThread’ extends the Thread class and overrides the run()method. Then a new object called ‘myThreadObject’ is created and the start()method is called on that object resulting in invoking the run() method on the Thread object</p><h4>By implementing the runnable interface</h4><p>In this approach we create a class that implements the Runnable interface. The class overrides the run() method and we create a new thread object and call the start() method on that object.</p><p>It is important to note that the Runnable interface has only one single method called run().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*8j_yoCflJWc2NTSqi2iRFQ.png" /><figcaption>Implementation the Runnable Interface</figcaption></figure><p>As show in the above code, the class ‘MyRunnable’ implements the Runnable class and it overrides the run() method. Then a new instance of the MyRunnable class is created and is passed into the Thread constructor as show above. Finally the start() method is classed on the Thread object.</p><p>When the thread is started by calling the start() method the MyRunnable run() method will be executed as it overridden the run() method in the Runnable interface.</p><h3>What we need to consider when choosing one of these ways of implementing a thread.</h3><p>· It’s always a good idea to use the Runnable interface to start a new thread. Otherwise, the thread class will lose the inheritance feature.</p><p>· If we extend the Thread class in our project, we cannot extend any other classes as we all know java does not support multiple inheritance. therefore, we could implement the Runnable interface which will allow us to extend other classes.</p><h3>Important:</h3><p>When creating and starting a thread a common mistake many do is that they call the run() method instead of the start() method. This however will execute the code given inside the run() method but a new thread will be not be created and it will continue on the current thread where the previous lines of code were executed. Because when a program invokes the start() method, it creates a new thread and then calls the run() method.</p><p>However, if we call the run() method directly, no new thread is created and the run() method is executed as a normal method on the current thread with no multi-threading.</p><p>I hope this short article on the brief introduction to Basics of Multithreading helped you to get a better and a clear understanding of the discussed topic. Please do feel free to provide feedback on the above and do follow for more articles related to this and many more!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f3c2f3b6d31" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/basics-of-multithreading-in-java-1f3c2f3b6d31">Basics of Multithreading in Java</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Differences between Imperative Programming and Declarative Programming]]></title>
            <link>https://medium.com/javarevisited/differences-between-imperative-programming-and-declarative-programming-fff6c63d8c1c?source=rss-c69cd41223f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/fff6c63d8c1c</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[declarative-programming]]></category>
            <category><![CDATA[programming-paradigms]]></category>
            <category><![CDATA[imperative-programming]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Dan Dias Abeyesinghe]]></dc:creator>
            <pubDate>Wed, 08 Sep 2021 14:22:58 GMT</pubDate>
            <atom:updated>2021-09-12T15:35:01.930Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pUi3vkj06Vqp_sXeiI-UbQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@jstrippa">James Harrison</a> on<a href="https://unsplash.com/@jstrippa"> Unsplash</a></figcaption></figure><h4>A brief introduction to Programming Paradigms.</h4><p>As we all are well aware of all the different kinds of programming languages that are used by developers, they all follow an important thing when it comes to programming and that is the method or the strategy they follow.</p><p>This can be simply defined as paradigms. Programming paradigms are a method or a strategy that is followed using all the tools that are available following a certain approach to do a certain task or solve any kind of a problem.</p><figure><a href="https://javarevisited.blogspot.com/2020/05/top-10-udemy-courses-to-learn-python-programming.html"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DC-m3s58xA3elYN6IShY7w.png" /></a></figure><h4>Imperative programming</h4><p>This is a paradigm where a programmer instructs <strong>on how to </strong>achieve the required task or goal.</p><p>This is based on the Von Neumann architecture and contains assignment statements to change the state of the program and thereby finally storing the result at the end of the program.</p><p>This describes the control flow of the computation and the user is allowed to make decisions and commands to the compiler.</p><p>This is further divided into 3 categories namely, Procedural Programming Paradigm, <a href="https://medium.com/swlh/5-free-object-oriented-programming-online-courses-for-programmers-156afd0a3a73">Object-Oriented Programming</a>, and parallel processing Approach.</p><h4>Declarative programming</h4><p>This paradigm is where the programmer explains the logic (logic of computation) behind the desired output rather than focusing on how to actually do it.</p><p>This mainly focuses <strong>on what needs to be done </strong>rather than how i<strong>t should be done </strong>which is going into detail on how the code works. In this the compiler is allowed to make decisions.</p><p>This is also further divided into 3 main categories namely, Logic Programming Paradigm, <a href="https://medium.com/javarevisited/5-best-java-functional-programming-books-for-beginners-and-experienced-programmers-4daecd159756">Functional Programming</a>, and Database Processing Approach.</p><p>The main difference between Imperative programming and Declarative programming is that Imperative programming focuses on <strong>how to do it</strong> and Declarative programming focuses on<strong> what to do</strong>.</p><p>I hope this short article on the brief introduction to Programming paradigms and differences between Imperative and Declarative programming helped you to get a better and a clear understanding of the discussed topics. Please do feel free to provide feedback on the above and do follow for more articles related to this and many more!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fff6c63d8c1c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/differences-between-imperative-programming-and-declarative-programming-fff6c63d8c1c">Differences between Imperative Programming and Declarative Programming</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Differences between JVM, JRE and JDK]]></title>
            <link>https://levelup.gitconnected.com/differences-between-jvm-jre-and-jdk-25fa4ea6aff4?source=rss-c69cd41223f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/25fa4ea6aff4</guid>
            <category><![CDATA[jvm]]></category>
            <category><![CDATA[jre]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[jdk]]></category>
            <category><![CDATA[jvm-architecture]]></category>
            <dc:creator><![CDATA[Dan Dias Abeyesinghe]]></dc:creator>
            <pubDate>Tue, 07 Sep 2021 17:24:49 GMT</pubDate>
            <atom:updated>2021-09-07T17:24:49.188Z</atom:updated>
            <content:encoded><![CDATA[<h3>Differences between JVM, JRE, and JDK</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RIzNp-TiXtc4-OpvCiU8-w.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@blakeconnally">Blake Connally</a> on <a href="https://unsplash.com/">Unsplash</a></figcaption></figure><h3>Java Virtual Machine</h3><p>This is an abstract machine (as it is not physically there) which provides a runtime environment for Java bytecode.</p><p>This loads the code, verifies, and execute the code.</p><p>This also can run other programs written in different languages which are compiled in Java bytecode.</p><p><strong>JVM, JRE, and JDK all are platform dependent</strong> as it requires different configuration for different OS. However, it is important to note that <strong>Java is platform independent.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*kFzWpXLFEZZByxp3CYk15A.png" /><figcaption>Java Virtual Machine</figcaption></figure><p>The JIT (Just in time) complier coverts Java bytecode to machine code.</p><p>You can refer my article on Java Virtual Machine and Its architecture to get a better and more detailed understanding of this <a href="https://dandiasabeyesinghe.medium.com/java-virtual-machine-and-its-architecture-2d8de5599500">here.</a> I have in depth discussed about the Class loader, Execution engine and many more in that article.</p><h3>Java Runtime Environment</h3><p>The JRE(Java Runtime Environment ) is software that is used to develop Java applications.</p><p>This is used to provide a runtime environment and it is an implementation of the Java Virtual Machine.</p><p>This however exists physically unlike the Java Virtual Machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*nChkd-ZeBhmy5qoqpBjv3w.png" /><figcaption>Java Runtime Environment</figcaption></figure><h3>Java Development Kit</h3><p>The JDK (Java Development Kit) is a software development environment where Java applications are developed.</p><p>This contains the JRE + Development tools</p><p>This also exist physically.</p><p>There are several different types of platforms released by Oracle as well.</p><p>The JDK is like the full package that is necessary to develop a Java application as it has its own private Java Virtual Machine, an interpreter, a compiler, an archiver etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*RwgVYFTGMpkfVOfBczJGiA.png" /><figcaption>Java Development Kit</figcaption></figure><p>I hope this article has helped you to understand better about the differences between the JVM,JRE and JDK as it is confused by many mostly. You can also check my other article I have written on <a href="https://dandiasabeyesinghe.medium.com/java-virtual-machine-and-its-architecture-2d8de5599500">Java Virtual Machine and its architecture</a> to get a clear and a better in-depth understanding of it and if you wish to gain more knowledge about JVM.</p><p>Please do feel free to provide a feedback on the above and do follow for more articles related to this and many more!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/284/1*D85A-oAbxDhAiRNiGbsnyg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25fa4ea6aff4" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/differences-between-jvm-jre-and-jdk-25fa4ea6aff4">Differences between JVM, JRE and JDK</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object-Oriented Programming and Java OOP Concepts]]></title>
            <link>https://medium.com/javarevisited/object-oriented-programming-and-java-oop-concepts-1e38928a88e7?source=rss-c69cd41223f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e38928a88e7</guid>
            <category><![CDATA[programming-paradigms]]></category>
            <category><![CDATA[basic-training]]></category>
            <category><![CDATA[oop-concepts]]></category>
            <category><![CDATA[beginner-coding]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Dan Dias Abeyesinghe]]></dc:creator>
            <pubDate>Mon, 12 Jul 2021 05:10:05 GMT</pubDate>
            <atom:updated>2021-09-02T13:17:34.468Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jZcSJvqh3CxxCi6W" /><figcaption>Photo by <a href="https://unsplash.com/@ffstop?utm_source=medium&amp;utm_medium=referral">Fotis Fotopoulos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Object-oriented programming is a fundamental programming paradigm used by almost every developer. This is considered to be one of the most famous programming paradigms that is taught to a programmer as a standard way of coding from the early days of their careers.</p><p>The concept of OOP is a concept that can be seen in our day to day lives but what we fail to see or make a note of it. <a href="https://medium.com/swlh/5-free-object-oriented-programming-online-courses-for-programmers-156afd0a3a73">Object-Oriented Programming</a> basically deals with real-life objects and how they are incorporated and replicated in the programming world. This concept mainly relies on the concept of Classes and Objects.</p><h4>Classes</h4><p>Classes can be simply defined as simple, abstract code which acts as a blueprint to create different instances of an object of that respective <a href="https://javarevisited.blogspot.com/2011/10/class-in-java-programming-general.html">class</a>, it can also be termed as the broader concept from which objects are instantiated. These classes have attributes and functions which are inherited to the objects when instantiating. These methods are only available to that respective Object type and not for other types.</p><h4>Objects</h4><p>Objects can be defined as an instance of a Class. An <a href="https://javarevisited.blogspot.com/2012/12/what-is-object-in-java-or-oops-example.html">Object </a>can contain attributes and relevant methods that are in the Class and it is mostly a software representation of real-life objects.</p><h4>Attributes</h4><p>Attributes are the information that is stored in the class. These attributes will hold data of the Objects that are instantiated and the data held by these attributes can differ from object to objects that are created using the respective class.</p><h4>Methods</h4><p>Methods represent the behavior of a Class. They can perform actions or even update Objects of the respective Class.</p><p>If I was to explain the concepts of Classes and Objects through a real-life example, we can take pet, and to be more precise we can take a dog, a dog has common attributes that are common to all the dogs like the Breed, Age, Size, Color, and some functionalities that common as well like Bark, Run, Sit, Eat. So, in order to represent this real-life model in a software entity we can use the dog as Class which acts as blueprint of which dog objects can be created from.</p><p>As attributes of the Class, we can assign the dog attributes mentioned above and we can do the same by assigning the methods of the class the functionalities of the dog which we discussed earlier.</p><figure><a href="https://www.java67.com/2018/02/5-free-object-oriented-programming-online-courses.html"><img alt="" src="https://cdn-images-1.medium.com/max/521/1*7EzglXTSjb5_UpcGkvm8qw.png" /></a></figure><h3>OOP Concepts</h3><p>There are 3 main Object-Oriented Concepts when It comes to Object-Oriented Programming. These Can be simply listed as,</p><p>1. <a href="https://javarevisited.blogspot.com/2010/10/abstraction-in-java.html#axzz6oOeSmpNw">Abstraction</a></p><p>2. <a href="https://javarevisited.blogspot.com/2012/03/what-is-encapsulation-in-java-and-oops.html">Encapsulation</a></p><p>3. <a href="https://javarevisited.blogspot.com/2012/10/what-is-inheritance-in-java-and-oops-programming.html">Inheritance</a></p><p>4. <a href="https://www.java67.com/2012/10/difference-between-polymorphism-overloading-overriding-java.html">Polymorphism</a></p><h4>Abstraction</h4><p>Abstraction can be simply explained as the form of hiding all unnecessary data and only shows the essential data of an Object. A-Class is the perfect example for an abstract representation of an Object as it will only showcase the relevant fields and methods of the class and will omit the unwanted details of an Object.</p><p>Example:</p><p>In the above example, the Dog class that was created contained characteristics and functionalities of all dogs. Here the Class Dog serves as an abstract model for the concept for the dog.</p><h4>Encapsulation</h4><p><a href="http://www.java67.com/2012/08/difference-between-abstraction-and-encapsulation-java-oops.html">Encapsulation </a>can define as the process of connecting and binding together the data and objects and keeps them safe from outside interference and misuse. This can be implemented or achieved by making the fields of the class <a href="https://javarevisited.blogspot.com/2012/10/difference-between-private-protected-public-package-access-java.html#axzz6j8KhisSX">Private </a>and providing access to those fields using public methods. The below code snippet will make you understand this more clearly.</p><figure><a href="https://www.java67.com/2019/02/can-you-add-non-abstract-method-on-interface-in-java.html"><img alt="" src="https://cdn-images-1.medium.com/max/781/1*4umX5kqynOVYn4Jctx35IQ.png" /></a></figure><p>In the above code snippet, we can see that all the attributes of the class are made private, hence these attributes cannot be accessed directly outside of the class. To access them these getters and setter methods. The setter methods initialize or change the value of an attribute and getters return the value of an attribute.</p><h4>Access Modifiers</h4><p>Java supports 4 types of access modifiers that we can use to define the visibility of classes, attributes or even methods. We can use these modifiers according to our logic and the requirements of the system.</p><figure><a href="http://www.java67.com/2012/12/what-is-public-private-protected-package-default-private-access-modifier-java.html"><img alt="" src="https://cdn-images-1.medium.com/max/785/1*v5IeZbsmnAYJ5n9FWLmp0g.png" /></a></figure><h4>Inheritance</h4><p>Inheritance can be defined as the process where one objects acquire the properties of another. with the use of this information is made manageable in a hierarchical order. This concept helps in reducing duplication of code by taking out the common codes in multiple classes and assigning it to a one super class.</p><p>There are 3 types of inheritance</p><p>1. Single Inheritance</p><p>2. Hierarchical Inheritance</p><p>3. Multiple Inheritance</p><p>However <a href="https://javarevisited.blogspot.com/2011/07/why-multiple-inheritances-are-not.html">Multiple inheritances cannot be implemented in Java</a> due to the Diamond problem.</p><figure><a href="https://www.java67.com/2016/03/top-21-java-inheritance-interview-Questions-Answer-Programming.html"><img alt="" src="https://cdn-images-1.medium.com/max/785/1*FvcgWgkWt6yVt6DnLe45CQ.png" /></a></figure><p>In the above code snippet, we can see that the GermanShepherd Class is created by extending the Dog class, by doing this the sub-class which is the GermanShepherd Class inherits all the attributes and methods of the parent class which is the Dog class in this instance. Here the constructor of the parent class is mentioned as “super” in the subclass. The number / types of parameters passed to super must match parameters of one of the superclass’s constructors. If present, must be the first statement.</p><h4>Polymorphism</h4><p>Polymorphism can be defined as the process which allows different objects to react to the same message in different ways.</p><p>This can be achieved through <a href="https://javarevisited.blogspot.com/2011/12/method-overloading-vs-method-overriding.html#axzz5Y4Kd7uK1">method Overloading</a> and <a href="http://www.java67.com/2012/08/what-is-method-overriding-in-java-example-tutorial.html">Method Overriding</a>.</p><h4>Method Overloading</h4><p>Method Overloading is the process of methods having the same method name but different types of parameters and number of parameters. These methods may or may not have return types. See the code below for better understanding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*b5uTqQW2FZ4-R_Ue3vyEdQ.png" /></figure><p>This above code snipper depicts the use of Method overloading. Here the same method with the same name is used but with different parameters and number of parameters. The complier treats overloaded methods as different methods altogether and the complier knows which method to call based on the number and type of parameters used.</p><h4>Method Overriding</h4><p>Method Overriding is the process that is used if a subclass wants to override a method defined in the super class. This can be done by writing the same exact method in the sub class and changing the body of the method accordingly. The method written in the sub class to override the method in the super class should have the same method name, same arguments, same return types as the method of the super class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*NkfmEeQHIGQiKcaFBuPH2g.png" /></figure><p>In this above code snippet, we can see that the Bark () method is overridden in the GermanShepherd. At the method call, the method defined in the subclass is invoked and executed instead of the one in the superclass.</p><p>I hope this article helped you to get a better understanding of all the basics and concepts explained. Please do feel free to provide feedback on the above. That would be much appreciated.</p><p>Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e38928a88e7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/object-oriented-programming-and-java-oop-concepts-1e38928a88e7">Object-Oriented Programming and Java OOP Concepts</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Virtual Machine and its Architecture]]></title>
            <link>https://medium.com/javarevisited/java-virtual-machine-and-its-architecture-2d8de5599500?source=rss-c69cd41223f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d8de5599500</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[jvm-memory]]></category>
            <category><![CDATA[jvm-architecture]]></category>
            <category><![CDATA[jvm]]></category>
            <dc:creator><![CDATA[Dan Dias Abeyesinghe]]></dc:creator>
            <pubDate>Mon, 05 Jul 2021 08:07:39 GMT</pubDate>
            <atom:updated>2021-09-02T13:05:49.235Z</atom:updated>
            <content:encoded><![CDATA[<h4>Java Virtual Machine</h4><p>The JVM can be simply known as the engine that provides a runtime environment for Java and its applications. The JVM is considered to be a part of the JRE (Java Runtime Environment). Its commonly and famously known for its process of converting java code to bytecode and then interpreting the bytecode into machine language.</p><p>However, the java compiler complies with a code to be used in the virtual machine which is also known as the <a href="https://www.java67.com/2013/02/difference-between-jit-and-jvm-in-java.html">Java Virtual Machine</a>, unlike other programming languages where the compiler produces machine code for a particular system.</p><p>Java applications are also known as “write once run anywhere” as a Java code can be written in one system and is able to run in many Java-enabled systems without any changes made with the help of the JVM.</p><p>The Java JVM is platform-dependent (Mac JVM, Linux JVM, Windows JVM) whereas the Java code is platform independent.</p><h4>JVM Architecture</h4><figure><a href="https://javarevisited.blogspot.com/2011/12/jre-jvm-jdk-jit-in-java-programming.html"><img alt="" src="https://cdn-images-1.medium.com/max/624/1*Q09YW_fcabpnlzGJXO1s7A.png" /></a></figure><p>The internal architecture of the JVM can be broken down into 3 main parts namely,</p><p>· The <a href="https://javarevisited.blogspot.com/2021/05/java-classloader-interview.html">Classloader</a></p><p>· Memory Area</p><p>· Execution Engine</p><h4>ClassLoader</h4><p>This is considered as a subsystem of <a href="https://medium.com/javarevisited/7-best-courses-to-learn-jvm-garbage-collection-and-performance-tuning-for-experienced-java-331705180686">JVM </a>and it is responsible for loading the class files when a program is run.</p><p>There are<a href="https://javarevisited.blogspot.com/2012/12/how-classloader-works-in-java.html"> three inbuilt class loaders</a> in Java namely,</p><p>· Bootstrap ClassLoader</p><p>· Extension ClassLoader</p><p>· System/Application ClassLoader</p><p>These perform three main functions.</p><p><strong>Loading</strong></p><p>The class loader reads the <em>.class</em> file and generates the required binary data which is stored in the method area. It also stores details like,</p><p>· the fully qualified name of the loaded class and its immediate parent class.</p><p>· If the generated <a href="https://javarevisited.blogspot.com/2012/05/10-points-about-class-file-in-java.html">.class file</a> Is a Class, Interface or Enum</p><p>· Variables, modifiers, and method information.</p><p>After loading the <em>.class</em> file the JVM creates an object of type Class to represent this file in the <a href="https://javarevisited.blogspot.com/2013/01/difference-between-stack-and-heap-java.html">heap</a>.</p><p><strong>Linking</strong></p><p>This is where all the verifications, preparations, and resolutions are done. The verification process ensures the correctness of the file.</p><p>Preparation is the process of the JVM allocating memory for class variables and assigning default values in the memory.</p><p>Resolution is the process of converting symbolic references to direct references. This is done by going through the method area to locate the referenced entity. However, this function is optional</p><p><strong>Initialization</strong></p><p>Here all static variables and blocks are assigned with values mentioned in the code. This code is executed from top to bottom hierarchy.</p><h4>JVM Memory</h4><p>The JVM memory main consists of the following sectors,</p><p>· Method Area</p><p>· <a href="https://javarevisited.blogspot.com/2011/05/java-heap-space-memory-size-jvm.html#axzz5SDsAfcC8">Heap</a></p><p>· <a href="https://www.java67.com/2016/10/difference-between-heap-and-stack-memory-in-java-JVM.html">Stacks</a></p><p>· PC Register</p><p>· Native Method Stack</p><p><strong>Method Area</strong></p><p>Here all the class level information is found (Class name, <a href="https://www.java67.com/2016/05/difference-between-static-and-nonstatic-member-variable-in-java.html">Class variables</a>, immediate parent Class name etc.). It is important to note that there is only one method area per JVM and therefore it is considered to be a shared resource in the memory.</p><p><strong>Heap</strong></p><p>All the information related to Objects is stored here. This memory is also common and therefore shared among multiple threads.</p><p><strong>Stacks</strong></p><p>This store&#39;s <a href="https://javarevisited.blogspot.com/2012/02/difference-between-instance-class-and.html">local variables</a> and the partial results. Each thread has its own runtime stack created when the thread is created. A new frame is created whenever a method is invoked and all the local variables of that method is stored in that corresponding frame. This is deleted when the method invocation is completed. This is not a shared resource .</p><p><strong>PC Register</strong></p><p>Also known as the program count register holds the current address of the JVM instruction currently being executed.</p><p><strong>Native Method Stack</strong></p><p>This holds all the native methods used in the application as implied by the name.</p><h4>Execution Engine</h4><p>This executes the <em>.class </em>file by reading the byte code line by line, using its data and information present in various memory areas, and executes instructions. It can be further broken down into 3 parts,</p><p>·<strong> Interpreter</strong></p><p>This interprets the code line by line and executes, however, if one method is called multiple times it has the interpreted again and this can be considered as a disadvantage of it.</p><p>· <strong>Just-In-Time Compiler (JIT)</strong></p><p>This is used as a remedy for the above problem where this increases the efficiency of the interpreter by compiling the entire byte code and changing it to native code, so when there is a repeat method call the JIT compiler will provide the native code for that part so that a re-interpretation is not needed.</p><p><strong>· Garbage collector</strong></p><p>This is used to destroy or get rid of un-referenced Objects.</p><h4>Java Native Interface</h4><p>JNI is a framework that provides an interface to communicate with other applications written in other languages. It allows <a href="https://www.java67.com/2020/03/how-to-write-clean-code-using-java-8.html">Java code</a> that is running in a JVM to call by libraries and native applications.</p><figure><a href="https://javarevisited.blogspot.com/2017/11/top-5-free-java-courses-for-beginners.html"><img alt="" src="https://cdn-images-1.medium.com/max/338/1*lSCMqK_h-kzJYRYcnmWTqA.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d8de5599500" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/java-virtual-machine-and-its-architecture-2d8de5599500">Java Virtual Machine and its Architecture</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>