<?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 Thanislaus Cleman on Medium]]></title>
        <description><![CDATA[Stories by Thanislaus Cleman on Medium]]></description>
        <link>https://medium.com/@Thanislaus_Cleman?source=rss-b5f207733a82------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*KnFzTxrHejO8ArpM</url>
            <title>Stories by Thanislaus Cleman on Medium</title>
            <link>https://medium.com/@Thanislaus_Cleman?source=rss-b5f207733a82------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 18:55:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Thanislaus_Cleman/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Memento Design Pattern]]></title>
            <link>https://medium.com/@Thanislaus_Cleman/memento-design-pattern-ae0ec137b7b5?source=rss-b5f207733a82------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae0ec137b7b5</guid>
            <category><![CDATA[memento]]></category>
            <dc:creator><![CDATA[Thanislaus Cleman]]></dc:creator>
            <pubDate>Sat, 16 Jul 2022 07:05:13 GMT</pubDate>
            <atom:updated>2022-07-16T07:07:00.832Z</atom:updated>
            <content:encoded><![CDATA[<p>The <strong>Memento Design Pattern</strong> is implemented with the help of ({[ <strong>the <em>originator</em>, a <em>caretaker,</em> and a <em>memento</em></strong><em> </em>]}) these objects</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IZilrDniR26wgu5Ty2hPyw.png" /></figure><ul><li><strong>Originator — </strong>The originator is the object whose internal state we want to save. To store its internal state, the Originator object creates a memento object. As a result, the Originator object understands how to save and restore itself. The object responsible for getting and setting the values of Memento objects.</li><li><strong>Caretaker</strong> — The object that understands why and when the Originator must save and restore itself. The object operates on the Originator while allowing for rollback. It preserves the history of the Memento objects that have been created. Before operating, the caretaker takes a picture of Originator.</li><li><strong>Memento</strong> — A simple Java object with basic state storage and retrieval capabilities. In general, the Memento object is unchangeable. The object stores the Originator’s internal state and allows it to be restored.</li></ul><p>Following code snippets shows how Memento Design Pattern works</p><p>Originator Class —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*l4kZg8a-nNc0xS0NLYafIQ.png" /></figure><p>CareTaker Class —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*NGQzO_QVDxRy0AzMKRJcpQ.png" /></figure><p>Memento Class —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*g7NTWKH7BPUDGMJ--Xbllg.png" /></figure><p>Main Class —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*7uSCGlkg-pbmKTYsQazhUw.png" /></figure><p>Output —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*h19Xip8zKiYlbBgyfuvb_A.png" /></figure><p>Advantages</p><ul><li>You can produce snapshots of the object’s state without violating its encapsulation.</li><li>You can simplify the originator’s code by letting the caretaker maintain the history of the originator’s state.</li></ul><p>Disadvantages</p><ul><li>The app might consume lots of RAM if clients create mementos too often.</li><li>Caretakers should track the originator’s lifecycle to be able to destroy obsolete mementos.</li><li>Most dynamic programming languages, such as PHP, Python and JavaScript, can’t guarantee that the state within the memento stays untouched.</li></ul><h3>Reference —</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FPwm-jrG2ZVA%3Flist%3DPLD-mYtebG3X86i3uyAXwZKfVtUy2gMDdo&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DPwm-jrG2ZVA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FPwm-jrG2ZVA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/34fdcd99b2f9deb4532c3aa6e924a8d2/href">https://medium.com/media/34fdcd99b2f9deb4532c3aa6e924a8d2/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae0ec137b7b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chain of Responsibility Design Pattern]]></title>
            <link>https://medium.com/@Thanislaus_Cleman/chain-of-responsibility-design-pattern-764ceb6ee426?source=rss-b5f207733a82------2</link>
            <guid isPermaLink="false">https://medium.com/p/764ceb6ee426</guid>
            <category><![CDATA[chain-of-responsibility]]></category>
            <dc:creator><![CDATA[Thanislaus Cleman]]></dc:creator>
            <pubDate>Sat, 16 Jul 2022 06:45:45 GMT</pubDate>
            <atom:updated>2022-07-16T07:06:25.292Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>The Chain of Responsibility design pattern allows you to pass requests along a chain of handlers. When a request arrives, each handler decides whether to process it or pass it on to the next handler in the chain.</strong></p><h4>When and Where the Chain of Responsibility Pattern Applies:</h4><ul><li>When you want to separate the sender and receiver of a request</li><li>A request can be handled by multiple objects that are determined at runtime.</li><li>When you don’t want to explicitly specify handlers in your code</li><li>When you want to send a request to one of several objects without explicitly specifying the receiver.</li></ul><p><strong>Send a request in the application using the Chain of Responsibility</strong></p><ul><li>The Client in need of a request to be handled sends it to the chain of handlers which are classes that extend the Handler class.</li><li>Each of the handlers in the chain takes its turn trying to handle the request it receives from the client.</li><li>If ConcreteHandler1 can handle it, then the request is handled, if not it is sent to the handler <strong>ConcreteHandler2</strong>, the next one in the chain.</li></ul><p>Consider a situation where ATM works in a bank</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*OkqpR9Y93lMVSgppqGGSGQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*pkMUJ5dGXaHEWZHfpEyEqg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*j5LQX562jHEJyS7XjG91qg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*YNEvAO7qOcrD85389LsWuA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*TfGj6swpSD5N9MQeas1FFQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*w1O66MhqYx14PCKOb2VR3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*YzUVqTEt0l8xV5X6BrI7ZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*KsECUTeM3h2o9CzCDu17SA.png" /></figure><p>Output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*71POF3u3CvdDyFqZ8ZQ82w.png" /></figure><p>Let’s discuss what are the pros and cons in this design pattern:</p><blockquote><strong>Advantages</strong></blockquote><blockquote>You can control the order of request handling.</blockquote><blockquote><em>Single Responsibility Principle</em>. You can decouple classes that invoke operations from classes that perform operations.</blockquote><blockquote><em>Open/Closed Principle</em>. You can introduce new handlers into the app without breaking the existing client code.</blockquote><blockquote><strong>Disadvantages</strong></blockquote><blockquote>Some requests may end up unhandled.</blockquote><h3>Reference —</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FiOOnctEDp84%3Flist%3DPLD-mYtebG3X86i3uyAXwZKfVtUy2gMDdo&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DiOOnctEDp84&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FiOOnctEDp84%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/35d766f7b82749dec2ca8f76ae1940fa/href">https://medium.com/media/35d766f7b82749dec2ca8f76ae1940fa/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=764ceb6ee426" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Division by Zero is NOT Infinity]]></title>
            <link>https://medium.com/@Thanislaus_Cleman/why-division-by-zero-is-not-infinity-50ce018c70ab?source=rss-b5f207733a82------2</link>
            <guid isPermaLink="false">https://medium.com/p/50ce018c70ab</guid>
            <category><![CDATA[division-by-zero]]></category>
            <dc:creator><![CDATA[Thanislaus Cleman]]></dc:creator>
            <pubDate>Thu, 14 Jul 2022 05:07:25 GMT</pubDate>
            <atom:updated>2022-07-14T05:09:08.764Z</atom:updated>
            <content:encoded><![CDATA[<p>When a <strong>computer divides numbers</strong> it simply <strong>subtracts the given number from the total until it reaches zero</strong>. As with the multiplication number, keep adding to get the answer.</p><p>20 / 5 = 4</p><p>How the computer Solve this : —</p><pre>20 / 5 = <strong>?</strong></pre><pre>20 - <strong>5       </strong>-<strong> </strong>(1)<br>    15 - <strong>5</strong>   - (2)<br>    10 - <strong>5   </strong>-<strong> </strong>(3)<strong><br></strong>     5 - <strong>5</strong>   - (4)<strong>//</strong><br>       = <strong><em>0</em></strong> </pre><pre>So 20 / 5 = <strong>4</strong></pre><p>what if we divide 1 / 0 ? what would be the answer? let’s have a look at example.</p><pre>1 / 0 = ? </pre><pre>1 - 0<strong>      </strong>-<strong> </strong>(1)<br>    1 - <strong>0</strong>   - (2)<br>    1 - <strong>0   </strong>-<strong> </strong>(3)<strong><br></strong>    1 - <strong>0</strong>   - (4)...<br>    ........................</pre><pre>1 / 0 = <strong>∞</strong> (infinity) </pre><p>In mathematics, this is known as if any number is divided by zero, the answer should be <strong>infinite</strong>. As you can see, we can’t use zero because it leads to an infinite zero, which we can’t count.</p><h4>let’s check it another way around</h4><pre>1 / 1 = 1</pre><pre>1 / 0.1 = 10</pre><pre>1 / 0.01 = 100</pre><pre>1 / 0.001 = 1000</pre><p>This leads to 1/0= ∞ at one point, and we cannot define its answer at that point. Because it can be an uncountable number, it is referred to as an infinite number.</p><h4>Consider another number, such as 3 divided by 0</h4><pre>3 / 1 = 3</pre><pre>3 / 0.1 = 30</pre><pre>3 / 0.01 = 300</pre><pre>3 / 0.001 = 3000</pre><p>In above example that also leads to infinite number when dividing 3 / 0 = ∞<strong> </strong>that we cannot count.</p><blockquote><strong>However — — Consider multiplying an other number, such as 3 / 0 = ∞ and 1/ 0 = ∞ therefore As a result, the computer will consider (1 = 3) theoretically, <em>but this is not ture</em>.</strong></blockquote><h3>Positive and Negative</h3><pre><strong>Positive</strong>                            <strong>Negative</strong></pre><pre>1/1=1                                -1/1=-1<br>1/0.1=10                             -1/0.1=-10<br>1/0.01=100                           -1/0.01=-100<br>1/0.001=1000                         -1/0.001=-1000<br>1/0.0001=10000                       -1/0.0001=-10000<br>1/0= ∞                               -1/0= -∞</pre><pre>                          <strong>∞ = -∞</strong></pre><p>1 / 0 = ∞ and -1 / 0 =∞ and now it become ∞ = -∞ which is not again true.</p><h4>This doesn’t exactly come as it is but when we apply the logic we getting in the graph result.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*iAk32_6YU675WJD8hyOk_g.png" /></figure><p>The curves are now going in the opposite direction and will never meet. Considering all of the points, I believe this is conceptually and theoretically incorrect.</p><p>Finally graph with lines separating from one another and never stopping, indicating that this is undefinable. As a result, we can say that any number divided by 0 is undefined.</p><p>Reference —</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FsCW5dbk4C_o%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DsCW5dbk4C_o&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FsCW5dbk4C_o%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf8e4f548daa6d4365f3ad7d1885316c/href">https://medium.com/media/cf8e4f548daa6d4365f3ad7d1885316c/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50ce018c70ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Troubleshoot SLOW backends using TCP dump and Wireshark]]></title>
            <link>https://medium.com/@Thanislaus_Cleman/how-to-troubleshoot-slow-backends-using-tcp-dump-and-wireshark-4458ed1b1292?source=rss-b5f207733a82------2</link>
            <guid isPermaLink="false">https://medium.com/p/4458ed1b1292</guid>
            <category><![CDATA[make-fast-backend]]></category>
            <dc:creator><![CDATA[Thanislaus Cleman]]></dc:creator>
            <pubDate>Wed, 06 Jul 2022 10:59:01 GMT</pubDate>
            <atom:updated>2022-07-06T11:04:46.942Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*nOqYUL34DonFYwHwCoCgYA.jpeg" /></figure><p>The majority of developers experiencing a problem claim that the system is slow or that it IS SLOW AT TIMES. However, the developers are not the only ones to blame for this issue. However, developers bear the burden because we are the ones who create these systems.</p><blockquote><strong>Demo</strong></blockquote><p>In this demo I have used the js code which I have included in my <a href="https://medium.com/@Thanislaus_Cleman/every-software-engineer-must-know-about-http-cb14e4e3f202">previous article</a>. If you read previous article then more easy to understand.</p><p><strong>Following snapshot given below. Instead of get I have used post in here.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*4tgs3XwmWUQYERsy9U9O9w.png" /></figure><p><strong>Copy this code to use easy:</strong></p><pre>const express=require(&#39;express&#39;);<br>const app=express();</pre><pre>app.get(&#39;/wait&#39;,async(req,res)=&gt;{<br>    res.send(&#39;Job Done&#39;);<br>});</pre><pre>app.listen(8191);</pre><p>In the screenshot below, I’m using the application Insomnia to send a large file and a small text to the backend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*0CvEPcIx7K7JaIVM.png" /></figure><p>Let’s run the server and send the first transaction from Insomnia to Wireshark.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KicSee_PdJ433focji1A4Q.png" /></figure><p>The initial connection is shown in the first 3 lines. TCP 3 way handshake as usual. I’ve also added two new columns:<strong> “Delta Time” </strong>and<strong> “Calculated Window Size.”</strong></p><p>Window size is mentioned in line 3 of the preceding screenshot. <strong>“<em>Win=2619648”</em></strong> is the value in this case. The initial window size requested is <strong><em>65535</em></strong>. Simply put, window size refers to the maximum receive buffer size available to us. If it is client, the size of the client receive buffer; if it is server, the size of the server receive buffer.</p><p><strong>If we select line number 7. If we look carefully,</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/0*_bwpedhkOBFCSgyV.png" /></figure><p>Client to the server. It says Window is <strong>10233</strong>. If we get the initial one Window size it says <strong>65535</strong>. This <strong>65535</strong> bytes means a huge amount. What if we upload or download 2gb file just imagine we send 65535bytes and then ACK and we send again 65535bytes and then ACK again and again it will take forever to download. Because it is very slow.</p><p>With the protocol or with the network growth when we tried to deal with huge files, we wanted to have more space. So what they have done is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LS9Fe3R6qjgCwSeSmPrzhg.png" /></figure><p>When it comes to options, there is a flag called Window scale. Window scale means 8 this is 2⁸ which is = to 256. That means though our negotiation is 65535 I am okay to accept 256 times as this.</p><p>In Wireshark look at line number 7. We don’t see the Window scale option. Because that only happens during the handshake. If analyzing our slowness we need to make sure we capture SYN SYN-ACK ACK packets. Because we need to make sure bandwidth is using in the full scale.</p><p><strong>Lets upload a large file and see what’s happen</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*lsTkyVpXNtnxnDsI.png" /></figure><p><strong>So the upload file size is 458kb. After we upload the file by clicking send</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*RchhnUQiNK42ugaK.png" /></figure><p>normal 3 way handshake connection happened in first 3 lines. Just look carefully line number <strong>333</strong> to <strong>343</strong> Window size 2619648 dropping gradually. again 344 line comes to the value 2619648 which is vey important.</p><p>When we talk about calculated buffer window size, it means that the server opens for a certain amount of window size. Because the server indicates that I have 100 size, the client sends 100 size data to the server. The Server now has 100. However, the server is running another application on the application. Because the Server is just a protocol and an application in layer 7, the application pumps something to the Client, and the Client sends it to the Server.<br>As a result, the application on the Server reads it from the buffer. When the client sends 100 to the server and the server responds with an ACK. In the meantime, the Server application consumes 90 from the buffer. There are 10 left. Again Server can ask from Client is 90 in order to maintain buffer size.<br>Now the Client sends 90 and Server application consumes 70. Again Server asks 70 from the client. So we can see this is keep dropping.</p><pre><strong>Next Accept = Full Size (-) Remain in Buffer</strong></pre><p>So the issue arises as a result of the constant dropping and its hit rate being zero. We must exercise caution in this regard. Because, even though we transmit data at high speeds, the Server application at layer 7 does not consume data at the same rate.</p><p>It is now known as a zero window situation if something hits zero for some reason. Therefore, the server informs the client that all available buffer space is full and that the client must wait. Say the server asks the client to send 30 after the window updates 30 sizes one second later. The zero by zero window shows that there is a lag, which is why we can see it.<br>You need to fix the issue if you notice that your system is slow and you see no window packets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*WSj4HdngVZaL88Uf.png" /></figure><p>If we carefully examine the 3-way handshake in the first 3 lines, we can see that the Delta Time column responses or RTT is within milliseconds. If there is a delay here, we must investigate. We take this amount of time to send the packet to the server and return from the server. As a result, every handshake is taking this time.</p><p>The issue is that if the server sends 100 bytes, the SYN is 1. Client must ACK 101bytes, which is the time it takes for the server to clear out the send buffer until the data is in the server’s send buffer. If the server takes a long time to respond, this means that the server needs to keep more data in the send buffer without clearing it even though it has sent it. The next data that arrives at the server cannot be placed because the server’s send buffer is full. As a result, transmission is now slow.</p><p>TCP Retransmission is a method. Consider the previous example. The server sends 100 bytes, but the client does not acknowledge. So the Server is waiting. When the Server timeout occurs but the Client sends an ACK to the Server, the Server sends the same SEQ and ACK to the Client. If the connection is slow, the Server may send multiple retransmissions to the Client.</p><h3>Reference —</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FCa9ZRyzeauo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DCa9ZRyzeauo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FCa9ZRyzeauo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9f4ef67621cdc4fba178f39c884d229/href">https://medium.com/media/a9f4ef67621cdc4fba178f39c884d229/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4458ed1b1292" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Every Software Engineer Must Know About HTTP.]]></title>
            <link>https://medium.com/@Thanislaus_Cleman/every-software-engineer-must-know-about-http-cb14e4e3f202?source=rss-b5f207733a82------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb14e4e3f202</guid>
            <category><![CDATA[https]]></category>
            <dc:creator><![CDATA[Thanislaus Cleman]]></dc:creator>
            <pubDate>Wed, 06 Jul 2022 07:41:09 GMT</pubDate>
            <atom:updated>2022-07-06T07:45:45.695Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*bQTC5-c_mXV6HqMVpXKJoQ.png" /></figure><p>As a software engineer, particularly as a backend developer, you will hear a variety of system complaints, such as System is slow, System is not responding, System is occasionally slow, and so on. We must determine why this is occurring. If you believe you can scale it by adding more instances, go ahead and do so. It may exacerbate existing issues rather than resolving them. You must have clear evidence to solve these problems. As a result, you must understand the <strong>HTTP</strong> keep alive method.</p><p><strong>HTTP</strong> is an abbreviation for Hyper Text Transfer Protocol, which is the protocol used to deliver all World Wide Web resources. HTTP specifies how messages are formatted and transmitted. When a client requests information (for example, by clicking on a hyperlink), the browser sends a request message to the HTTP server for the requested objects. The server receives the requests and sends the response message along with the objects. However, the HTTP server keeps no information about the clients, and if the client requests the same object again, the server resends the object. As a result, HTTP can make use of both <strong>nonpersistent </strong>and<strong> persistent connections</strong>.</p><p>After the server sends the requested object to the client, a <strong>nonpersistent connection is closed</strong>. To put it another way, the connection is only used for one request and one response. HTTP uses nonpersistent connections by default (1.0). This is not commonly used, but it may be necessary when working with legacy systems. However, when we work with it, we want to send a message to establish a connection and then wait for the server’s response. Finally, we disconnect the cable. This was sometimes referred to as RTT (Round Trip Time).</p><p>But this system has some problems. Think about wanting to open an HTML page where it has 10 JavaScript files. Now you have to send 10 different requests to the server in order to get these files. This procedure is slow. With persistent connections, the performance is improved speed by 20%.</p><p>We can divide Persistence HTTP into two parts. <strong>With</strong> <strong>Tunneling</strong> and <strong>Without Tunneling. </strong>Mainly, <strong>HTTP 1.1 go with Tunneling</strong>. The way this works is that you establish a connection, send messages, receive responses, and then disconnect. This procedure is identical to TCP. However, But there is a tricky part in here.<br>If you send a request to the backend server, it is doing something or is busy with something. Because the server is not responding, HTTP closes the connection. To avoid this, we employ a unique technique known as Keep Alive. This means we simply send a ping to the server to tell it to keep the connection open. If we send a request and receive a response, we can send another request and tell the server to keep the connection open.</p><h3>Wireshark Demonstration</h3><p>First you need to write below Node code (Server.js) Then run the code. As second step Open Wireshark and open loopback interface and filter 8191 port traffics.(tcp.port==8191).then open your browser and load the code (localhost:8191/wait) like this images and you can copy code below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/0*0vrmNEqjkwiJc7cw.png" /></figure><pre>const express=require(&#39;express&#39;);<br>const app=express();</pre><pre>app.get(&#39;/wait&#39;,async(req,res)=&gt;{<br>    res.send(&#39;Job Done&#39;);<br>});</pre><pre>app.listen(8191);</pre><h4><em>Wireshark Status</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*orRVccwafEmtNgcx.png" /></figure><p>Above first 3 lines are start with <strong>SYN</strong> then <strong>SYN ACK</strong> and <strong>ACK </strong>in TCP 3 way handshake. After that we can see that HTTP send the request and get the response. Later Server <strong>sending a FIN</strong> to close the connection and for the response client also send a ACK but <strong>client did not close the connection. </strong>After sometime client send Keep-alive in order to keep the connection. So what the server doing is <strong>sending a reset packet to the client</strong> (Final line in red color).</p><h4><em>What is the scenario when you send requests continuously,</em></h4><p><strong><em>lets check that</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*SwZzujXzdGF2vMX1.png" /></figure><p>Connection opens in first 3 lines and we request a connection on HTTP and get respond and continuing. We can see <strong>there is no FIN.<br></strong>What happened here is,<strong> client just skipped talking to the backend and backend not trying to close the connection. </strong>That is what the <strong>Persistence HTTP</strong> means.</p><p><strong><em>Next Scenario is close the browser after send a request, get the respond.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*7RxcsgNwE6cLlwVX.png" /></figure><p>We can see that Connection initializing as usual before the send message. After that HTTP send a message and client get the respond. This is an important part. After that Sever <strong>closing the connection sending a FIN</strong> and client responds and <strong>when we close the browser</strong>, it means that <strong>client also close the connection by sending FIN packet to the server</strong>. This is a full cycle.</p><p><strong>now we do a small modification in the code.</strong></p><p>Sample code is given below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/0*qTJL3FRCZcYmrq2K.png" /></figure><pre>const express=require(&#39;express&#39;);<br>const app=express();</pre><pre>app.get(&#39;/wait&#39;,async(req,res)=&gt;{<br>    await new Promise((resolve)=&gt;setTimeout(resolve,60000))<br>    res.send(&#39;Job Done&#39;);<br>});</pre><pre>app.listen(8191);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*m3h-fI7uSAQG5tG5.png" /></figure><p>After 1 min client gets the respond from the server:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*qiJxwKCE2py8hw9a2tX06w.png" /></figure><h3>Reference —</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FYf06faA5-JY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DYf06faA5-JY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FYf06faA5-JY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1c7afd4743444f4776c8b73290f8e39/href">https://medium.com/media/d1c7afd4743444f4776c8b73290f8e39/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb14e4e3f202" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JAVA developers know about the Date & Time zone]]></title>
            <link>https://medium.com/@Thanislaus_Cleman/java-developers-know-about-the-date-time-zone-cb0441f1080f?source=rss-b5f207733a82------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb0441f1080f</guid>
            <category><![CDATA[date]]></category>
            <category><![CDATA[time]]></category>
            <dc:creator><![CDATA[Thanislaus Cleman]]></dc:creator>
            <pubDate>Sat, 02 Jul 2022 06:34:36 GMT</pubDate>
            <atom:updated>2022-07-02T06:34:36.947Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MVsnyn3wXKbwuoqTOKcR7g.png" /></figure><h3>What is a Time zone? — <strong>a geographic region within which the same standard time is used</strong>.</h3><p>Time zone is a uniform area mapping method to observe the standard time for legal, commercial, and social purposes. This is terrestrial body is used to map around the globe using 15 degrees longitude that extend from the North pole to the south pole. It tends to follow through country boundaries and subdivisions rather than wide longitude.</p><p>As a Java developer, you should be aware of how the language handles dates and times. Because java supports multiple data types for handling date and time. To handle date and time in Java, three different packages are primarily used.</p><h4><a href="https://www.dariawan.com/tutorials/java/java-date-examples/"><strong>java.util.Date</strong></a>:</h4><ul><li><a href="https://www.dariawan.com/tutorials/java/java-sql-date-examples/"><strong>java.sql.Date</strong></a> represents <strong>SQL DATE</strong>, stores <em>years, months and days</em> without time components. java.sql.Date is disregarding time zones.</li><li><a href="https://www.dariawan.com/tutorials/java/java-sql-time-examples/"><strong>java.sql.Time</strong></a> represents <strong>SQL TIME</strong> and only contains information about <em>hour, minutes, seconds and milliseconds</em> without date component.</li><li><a href="https://www.dariawan.com/tutorials/java/java-sql-timestamp-examples/"><strong>java.sql.Timestamp</strong></a> represents <strong>SQL TIMESTAMP</strong> which contains both Date and Time information to the nanoseconds precision.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/0*kQvcx0QIZ0EJKJ7v.png" /></figure><h3>Date-Time API</h3><p>This is a main API for dates, times, instants, and durations. It is designed to be type-safe where reasonable in the main high-level API.</p><p>The Date-Time APIs, introduced in JDK 8, are a set of packages that model the most important aspects of date and time. The core classes in the java.time package use the calendar system defined in ISO-8601 (based on the Gregorian calendar system) as the default calendar. Other non-ISO calendar systems can be represented using the java.time.chrono package and several predefined chronologies, such as Hijrah and Thai Buddhist are provided.</p><h4>most of the applications are using <strong>five date-time</strong> types.</h4><ul><li><strong>Instant</strong>- A timestamp</li><li><strong>LocalDate</strong>- a date without a time, or any reference to an offset or time-zone</li><li><strong>LocalTime</strong>- a time without a date, or any reference to an offset or time-zone</li><li><strong>LocalDateTime</strong>- combines date and time, but still without any offset or time-zone</li><li><strong>ZonedDateTime</strong>- a “full” date-time with time-zone and resolved offset from UTC/Greenwich</li></ul><p>Also this may appear to be a large number of <strong>classes,</strong></p><ul><li>java.time.LocalDate class</li><li>java.time.LocalTime class</li><li>java.time.LocalDateTime class</li><li>java.time.MonthDay class</li><li>java.time.OffsetTime class</li><li>java.time.OffsetDateTime class</li><li>java.time.Clock class</li><li>java.time.ZonedDateTime class</li><li>java.time.ZoneId class</li><li>java.time.ZoneOffset class</li><li>java.time.Year class</li><li>java.time.YearMonth class</li><li>java.time.Period class</li><li>java.time.Duration class</li><li>java.time.Instant class</li><li>java.time.DayOfWeek enum</li><li>java.time.Month enum</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/0*zrKY0tgIQQRAueIr.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb0441f1080f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chapter 18 — Distributed Computing]]></title>
            <link>https://medium.com/@Thanislaus_Cleman/chapter-18-distributed-computing-6f8a784e7f12?source=rss-b5f207733a82------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f8a784e7f12</guid>
            <category><![CDATA[mir]]></category>
            <dc:creator><![CDATA[Thanislaus Cleman]]></dc:creator>
            <pubDate>Sat, 02 Jul 2022 06:05:14 GMT</pubDate>
            <atom:updated>2022-07-02T06:06:09.524Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chapter 18 — Distributed Computing</h3><h3>Remote Deployment with RMI:</h3><p>For design a remote method call we have to create four things such as,</p><ul><li>Server</li><li>Client</li><li>Server helper</li><li>Client helper.</li></ul><ol><li>Create a client app and a server app with a remote service that has an object with the method that the client wants to invoke.</li><li>Create client and server helpers to handle low-level networking and input/output details.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*khCURTnI1Sx_5CIF.png" /></figure><h4>How the method call happens</h4><p>The client object invokes the client helper object’s dobigthing method. Then client helper packages up information about the call and ship it to service helper over the network. Then service helper unpacks information from the client helper find which method to call and invoke real method in the real service object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*pdzWZ_XOwsiVrvI0.png" /></figure><p>Java RMI builds the client helper and service helper for you. Client helper is known as stub while the service helper known as skeleton.</p><p><strong>Making a remote service</strong></p><p>1. Make a remote interface</p><ul><li>Extend java.rmi.remote</li></ul><pre><strong>public interface MyRemote extends Remote {</strong></pre><ul><li>Declare all methods throw a remote exception</li></ul><pre><strong>import java.rmi.*;</strong></pre><pre><strong>public interface MyRemote extends Remote {</strong></pre><pre><strong>public String sayHello() throws RemoteException;</strong></pre><pre><strong>}</strong></pre><ul><li>Make sure arguments and return values are primitives and serializable</li></ul><pre><strong>public String sayHello() throws RemoteException;</strong></pre><p>2. Make a remote implementation</p><ul><li>Implement the remote interface</li></ul><pre><strong>public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote {</strong></pre><pre><strong>public String sayHello() {</strong></pre><pre><strong>return “Server says, ‘Hey’”;</strong></pre><pre><strong>} // more code in class }</strong></pre><ul><li>Extend unicast remote object</li></ul><pre><strong>public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote {</strong></pre><ul><li>Write no arg constructor that declares a remote exception</li></ul><pre><strong>public MyRemoteImpl() throws RemoteException { }</strong></pre><ul><li>Register service with the RMI registry</li></ul><pre><strong>try {</strong></pre><pre><strong>MyRemote service = new MyRemoteImpl();</strong></pre><pre><strong>Naming.rebind(“Remote Hello”, service);</strong></pre><pre><strong>} catch(Exception ex) {…}</strong></pre><p>3. Generate stub and skeletons using rmic</p><ul><li>Run rmic on remote implementation class not remote interface</li></ul><p>4. Start the RMI registry</p><ul><li>Bring up a terminal and start the rmiregistry</li></ul><p>5. Start the remote service</p><ul><li>Bring up another terminal and start your service</li></ul><h4><strong>Server side</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*82swMIEphcR6miw-.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*P7r8jOQAVP1b5YY6.png" /></figure><h4>Client get the stub object by</h4><ul><li>Client look up on the rmi registry</li></ul><pre><strong>Naming.lookup(“rmi://127.0.0.1/Remote Hello”);</strong></pre><ul><li>Rmi registry returns stub object</li><li>Client invokes a method on the stub as though stub is the real service.</li></ul><h4><strong>Client side(how client get stub class)</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*r01NtmnQzpcLD4F0.png" /></figure><h4><strong>Servlets</strong></h4><p>Java programs that run on an HTTP web server. To run a servlet, you must have a web server that supports servlets, such as the Tomcat server from apache.org.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/0*vhkKXfp8i9vOA2vb.png" /></figure><h4>Steps to make and run a servlet</h4><ul><li>Find out where servlet need to be placed</li><li>Get the servlet.jar and add it to the classpath</li><li>Write servlet class by extending httpservlet</li></ul><pre><strong>public class MyServletA extends HttpServlet { … }</strong></pre><ul><li>Write an html page that invokes your servlet</li></ul><pre><strong>&lt;a href=”servlets/MyServletA”&gt; This is the most amazing servlet.&lt;/a&gt;</strong></pre><ul><li>Make servlet and html page available to server</li></ul><h4><strong>Universal service browser</strong></h4><ol><li>Client start and look for service called seviceserver in the rmi registry and gets back the stub</li><li>Client calls getservicelist on stub. Service layer returns an array of services.</li><li>Client displays the list of services in a GUI.</li><li>User select from list, client call getservice method on remote service. It returns a serialized object.</li><li>Client call getguipane on serialized object it got from remote service. Gui for that service is display inside the browser and user can interact with it locally.</li></ol><h4>The classes and interfaces:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*2uZkBJpa89GEHcMErUIZqg.png" /></figure><h3>References —</h3><p><a href="https://www.rcsdk12.org/cms/lib/NY01001156/Centricity/Domain/4951/Head_First_Java_Second_Edition.pdf">https://www.rcsdk12.org/cms/lib/NY01001156/Centricity/Domain/4951/Head_First_Java_Second_Edition.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f8a784e7f12" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chapter 17 — Release Your Code]]></title>
            <link>https://medium.com/@Thanislaus_Cleman/chapter-17-release-your-code-9213f2d55718?source=rss-b5f207733a82------2</link>
            <guid isPermaLink="false">https://medium.com/p/9213f2d55718</guid>
            <category><![CDATA[jar]]></category>
            <category><![CDATA[package]]></category>
            <dc:creator><![CDATA[Thanislaus Cleman]]></dc:creator>
            <pubDate>Sat, 02 Jul 2022 05:33:17 GMT</pubDate>
            <atom:updated>2022-07-02T05:33:17.143Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chapter 17 — Release Your Code</h3><h3>Package, Jars and Deployment</h3><p>Java program is a bunch of classes.</p><p>Deploy a java program into <strong>local</strong>, <strong>combination of local and remote</strong> and <strong>fully remote.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*gNUQMMk9mYRwyGYVL3XiOg.png" /></figure><p><strong>JAR</strong> is <strong>J</strong>ava <strong>Ar</strong>chive it is pkzip file format which has all the classes which is needed for a program to run.</p><p>We can run a Java program by executing a JAR file. A jar file contains a file called manifest that contains the information needed to make the java program executable. The manifest tells the JVM where the main method is located.</p><p>1. Make sure all of the class files are inside the classes directory.</p><p>2. Create a manifest.txt that states which class has the main() method.</p><pre><strong>Main-Class: MyApp</strong></pre><p>3. Run a jar tool to create a jar file.</p><pre><strong>%cd MyProject/classes </strong></pre><pre><strong>%jar -cvmf manifest.txt app1.jar *.class </strong></pre><pre>OR </pre><pre><strong>%jar -cvmf manifest.txt app1.jar MyApp.class</strong></pre><h4><strong>Compiling with the -d flag</strong></h4><p>To make compiled class land in the correct package directory structure under class classes directory.</p><pre><strong>%cd MyProject/source</strong></pre><pre><strong>%java com.headfirstjava.PackageExercise</strong></pre><p>The -d flag tells compiler to put class into its package directory. Using the class specified after the -d as the root directory.</p><p>Making an executable JAR</p><p>1. Make sure all of class files within the correct package structure.</p><p>2. Create manifest.txt file that that state which class has main method.</p><pre><strong>Main-Class: com.wickedlysmart.Foo</strong></pre><p>3. Run jar tool to create jar file that contains package directories plus the manifest.</p><h4><strong>JAVA Web Start (JWS)</strong></h4><p>Java web start app is an file which is similar to executable jar file. The difference is that JWS file is distributed over the web.</p><p>How java web start works</p><ol><li>Client click web page link to jws application (.jnlp file)</li><li>Web server gets http request and send back a .jnlp file</li><li>Browser start the jws. Jws helper app read the .jnlp file and ask myapp.jar file from the server.</li><li>Web server then serve requested .jar file.</li><li>Jws get the jar and start the application by calling main method.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/0*vHQRQ4iDWqj0vXTp.png" /></figure><p><strong>.jnlp (Java Network Launch Protocol)</strong> file describe the jws application.</p><h4>Create and deploy jws app</h4><ol><li>Make an executable jar for application</li><li>Write .jnlp file</li><li>Place both jar and jnlp file on web server</li><li>Add a new mime type to web server which make server to send the jnlp file with the correct header.</li></ol><pre><strong>application/x-java-jnlp-file</strong></pre><p>5. Create a web page with a link to the .jnlp file.</p><pre>&lt;HTML&gt;<br>   &lt;BODY&gt;<br>      &lt;a href=&quot;MyApp2. jnlp&quot;&gt; Launch My Application &lt;/a&gt;<br>   &lt;/BODY&gt;<br>&lt;/HTML&gt;</pre><h3>References —</h3><p><a href="https://www.rcsdk12.org/cms/lib/NY01001156/Centricity/Domain/4951/Head_First_Java_Second_Edition.pdf">https://www.rcsdk12.org/cms/lib/NY01001156/Centricity/Domain/4951/Head_First_Java_Second_Edition.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9213f2d55718" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chapter 16 — Data Structures]]></title>
            <link>https://medium.com/@Thanislaus_Cleman/chapter-16-data-structures-317b4d02b7d1?source=rss-b5f207733a82------2</link>
            <guid isPermaLink="false">https://medium.com/p/317b4d02b7d1</guid>
            <category><![CDATA[generics]]></category>
            <category><![CDATA[collection]]></category>
            <dc:creator><![CDATA[Thanislaus Cleman]]></dc:creator>
            <pubDate>Fri, 01 Jul 2022 05:50:30 GMT</pubDate>
            <atom:updated>2022-07-01T05:50:30.661Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chapter 16 — Data Structures</h3><h3>Collections and Generics:</h3><p>Arraylist doesn’t include sort method.</p><ul><li><strong>Treeset</strong> — sort elements and avoid duplication</li><li><strong>Hashmap</strong> — store and access elements as name/value pairs</li><li><strong>Linkedlist</strong> — create structures like stacks or queues</li><li><strong>Hashset</strong> — prevents duplicates in the collection</li><li><strong>Linkedhashmap</strong> — remember the order of element insertion.</li></ul><p>When using generics in collection framework you can caught many errors at compile time rather than runtime.</p><ol><li>Creating instances of generified classes</li></ol><pre><strong>new ArrayList&lt;Song&gt;()</strong></pre><p>2. Declaring and assigning variables of generic types</p><pre><strong>List&lt;Song&gt;songList = new ArrayList&lt;Song&gt;()</strong></pre><p>3. Declaring methods that take generic types</p><pre><strong>void foo(List&lt;Song&gt;list)<br>x.foo(songList)</strong></pre><h4>2 key areas to look at in a generified class</h4><ol><li>Class declaration</li><li>The method declaration</li></ol><pre><strong>public class ArrayList&lt;E&gt; extends AbstractList&lt;E&gt; implements List&lt;E&gt;</strong></pre><p>The “E” stands for type of elements that this collection hold and returns.</p><p>A generic class means that class declaration include type parameters while generic method means method declaration use type parameters in it’s signature.</p><p>Sort method only get list of comparable objects.</p><h4><strong>Using a comparator</strong></h4><p>By passing a comparator to sort method, sort order is done by comparator rather elements own comparato() method.</p><ul><li>Invoking one argument sort(List o) method mean list elements’ compare to method determines the order</li><li>Invoking 2 argument sort(List o, Comparator c) means list elements compare to method will not be called and comparators compare method will be used instead.</li></ul><p>We use List collection when we care about the sequence. It uses index positions. Set collection use when we care about the uniqueness of the elements while Map collection use to find elements using a key. We can use key value pair to find the elements.</p><h4><strong>Collection API</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*8Z223rl5e-c2VuqlEvZ70Q.png" /></figure><h4><strong>Object equality</strong></h4><ul><li>Reference equality — where 2 objects reference to the same object which is in the heap. This can be check using the == operator. It checks if the 2 references points to the same object.</li><li>Object equality — where the references are not equal and the objects are different but the value that holds by those 2 objects are equal. This can be checks using the equal method.</li></ul><p>Hashset checks the duplicate values in below manner by using hashcode</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*Ao92nisyrpp7E3cx.png" /></figure><h4>Elements in treeset is comparable.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*945UhIH8hxyZ1gEBfddcjg.png" /></figure><p>Each element is Map collection is 2 objects key and value. Keys in map should be unique while the values can be same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*0sp2IMJGJ5ndqhhtyqhdLw.png" /></figure><h3>References —</h3><p><a href="https://www.rcsdk12.org/cms/lib/NY01001156/Centricity/Domain/4951/Head_First_Java_Second_Edition.pdf">https://www.rcsdk12.org/cms/lib/NY01001156/Centricity/Domain/4951/Head_First_Java_Second_Edition.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=317b4d02b7d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chapter 15 — Make a Connection]]></title>
            <link>https://medium.com/@Thanislaus_Cleman/chapter-15-make-a-connection-21446c2667dd?source=rss-b5f207733a82------2</link>
            <guid isPermaLink="false">https://medium.com/p/21446c2667dd</guid>
            <category><![CDATA[threads]]></category>
            <category><![CDATA[massage]]></category>
            <dc:creator><![CDATA[Thanislaus Cleman]]></dc:creator>
            <pubDate>Fri, 01 Jul 2022 05:31:51 GMT</pubDate>
            <atom:updated>2022-07-01T05:31:51.584Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chapter 15 — Make a Connection</h3><h3>Networking and Threads:</h3><p>We require a <strong>Socket connection</strong> in order to connect to another machine. A Socket ( java.net.Socket class) is an object that represents a network connection between two machines.</p><p>What’s a connection? A <em>relationship</em> between two machines, where two pieces of software know about each other. Most importantly, those two pieces of software know how to send bits to each other.</p><p>To make a Socket connection, you need to know about IP address and TCP port number; this two things about the server who it is, and which port it’s running on.</p><ol><li>The way to<strong> Establishing</strong> socket connection between the Client and server</li><li>The way to Client <strong>send</strong> a messages to the server</li><li>The way to Client <strong>receive</strong> message from a server</li></ol><pre><strong>Socket chatSocket = new Socket(“196.164.1.103”, 5000);</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*ojJvX_e7SCb_l8jcxQYyZg.png" /></figure><p>TCP port number is a 16 bit number which identifies a specific program which run on the server. TCP ports 0 to 1023 are reserved for some essential services. We can use a port number between 1024 to 65535 as a chat server.</p><p>A TCP port is just a number, 16-bit number that identifies a specific program on the server</p><ul><li>0 to 1023 TCP port numbers are reserved for well-known services.</li><li>So we just picked a number between 1024 and 65535.</li></ul><h4><strong>To read data from a socket</strong></h4><p>Use a <strong>BufferedReader</strong></p><p>1. Make a socket connection to server</p><pre><strong>Socket chatSocket = new Socket(“127.0.0.1”, 5000);</strong></pre><p>2. Make an inputstreamreader chained to the socket’s input stream</p><pre><strong>InputStreamReader stream = new InputStreamReader(chatSocket.getInputStream());</strong></pre><p>3. Make a bufferreader and read</p><pre><strong>BufferedReader reader = new BufferedReader(stream);</strong></pre><pre><strong>String message = reader.readLine();</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*OPNE6SddTRmGLxUMCi4OrA.png" /></figure><p>Input stream reader is act like a bridge which takes in bytes and convert them into text data.</p><h4><strong>To write data to a socket</strong></h4><p>Use a PrintWriter</p><p>1. Make a socket connection to the server.</p><pre><strong>Socket chatSocket = new Socket(“127.0.0.1”, 5000);</strong></pre><p>2. Make a printwriter chained to the socket’s low level output stream</p><pre><strong>PrintWriter writer = new PrintWriter(chatSocket.getOutputStream());</strong></pre><p>3. Print something</p><pre><strong>writer.println(“message to send”);</strong></pre><pre><strong>writer.print(“another message”);</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*O61WmMVvqFFrjeXy.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*_gaCaIJEEBRMKYfha6GASQ.png" /></figure><h4>launching a thread</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*fdqGF-jwx0RuHTelxusO4w.png" /></figure><ol><li>make a runnable object</li></ol><pre><strong>Runnable threadJob = new MyRunnable();</strong></pre><p>2. make a thread object and make it runnable</p><pre><strong>Thread myThread = new Thread(threadJob);</strong></pre><p>3. start the thread</p><pre><strong>myThread.start(); </strong></pre><p>Runnable is to a Thread what a job is to a worker. A Runnable is the job a thread is supposed to run. A Runnable holds the method that goes on the bottom of the new thread’s stack: run().</p><p>The Runnable interface defines only one method, public void run(). (Remember, it’s an interface so the method is public regardless of whether you type it in that way)</p><p>Determine which threads are executed and which are not is the task of the thread scheduler. After that, it will allow one thread to run while starving the other.</p><p>A thread can be put to sleep so that other threads can run. when a thread returns to a runnable state and waits for the thread scheduler to select it for another run.</p><p>The synchronized keyword indicates that a key is required for a thread to access the synchronized code.</p><p>A Java object includes a lock and a key. The majority of the time, objects are unlocked and no one is aware of it. If an object has synchronized methods, a thread can only enter one of the synchronized methods if the object’s key is available. If another thread has already taken the key, it will not work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*FdwxjlJpQgDJfNpD.png" /></figure><p>Using the <strong>setname</strong> method we can name a thread</p><p>When two or more threads access the same object, data corruption occurs. This can be avoided by synchronizing keywords. Even if an object contains several synchronized methods, there is only one key. Once a thread has entered a synchronized method on that object, no other thread can enter another synchronized method on the same object. This restriction allows you to protect your data by synchronizing any technique that manipulates the data.</p><h3>References —</h3><p><a href="https://www.rcsdk12.org/cms/lib/NY01001156/Centricity/Domain/4951/Head_First_Java_Second_Edition.pdf">https://www.rcsdk12.org/cms/lib/NY01001156/Centricity/Domain/4951/Head_First_Java_Second_Edition.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21446c2667dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>