<?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 Sayan Paul on Medium]]></title>
        <description><![CDATA[Stories by Sayan Paul on Medium]]></description>
        <link>https://medium.com/@sayan-paul?source=rss-49a64a2d854a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7E2x_1GcfghVDPeJnB9o6g.jpeg</url>
            <title>Stories by Sayan Paul on Medium</title>
            <link>https://medium.com/@sayan-paul?source=rss-49a64a2d854a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 20 May 2026 12:53:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sayan-paul/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[Who are we?]]></title>
            <link>https://medium.com/@sayan-paul/who-are-we-a5d3023263e2?source=rss-49a64a2d854a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5d3023263e2</guid>
            <category><![CDATA[evolution]]></category>
            <category><![CDATA[philosophy]]></category>
            <category><![CDATA[science]]></category>
            <category><![CDATA[brain]]></category>
            <category><![CDATA[thinking]]></category>
            <dc:creator><![CDATA[Sayan Paul]]></dc:creator>
            <pubDate>Sun, 12 Jun 2022 18:22:03 GMT</pubDate>
            <atom:updated>2022-06-12T18:29:21.929Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f054QE8nWa9Z3AbX" /><figcaption>Photo by <a href="https://unsplash.com/@davidmatos?utm_source=medium&amp;utm_medium=referral">David Matos</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I woke up this morning, brushed my teeth, had breakfast, and then opened my laptop to attend my company training session. I was kind of frustrated with all the training and wanted to start with my job already. But here I was, stuck in the present.</p><p>Isn’t this familiar? Although this was an anecdote from my life, experiences like these are not out of the common. But have you ever wondered why people from so many different backgrounds, with different interests, hobbies and lifestyles undergo similar experiences? Can we say that we have such experiences because we are human beings? Are the feelings that we have hardwired into our biology?</p><p>I was always very much interested in studying evolution. And not only biological evolution, but also the evolution of societies, cultures, music, and science. One of my striking observations is that even though these belong to different academic fields, the basics of evolution remain the same. To understand evolution we need to understand a fundamental property that our universe exhibits — <em>Emergence</em>.</p><p>Emergence is the property by virtue of which simple small parts add up to create something too complex, and this complex structure would have properties that can only be formed by the interaction of these small parts. Our human body itself is one of the best examples of emergence. Our cells are not that complex structures (although they are if we look further into the molecular structure of a cell), but together they make up organs that can carry out complex tasks, and these organs coordinate with each other to give us life. Let’s take another example, a Corporate Organization. The organization is made of individuals who work collectively to create value. For example, a software engineer at Amazon would write some code, a quality assurance engineer would check for its credibility, and a marketing professional would advertise the service.</p><p>However, this gives rise to a question. We are made out of cells, and our body replaces all of its cells every 7 to 10 years. In the very same way, employees who constitute a company may change over the years. How can something stay the same even when all of its constituent elements have been changed? To understand this, let us take a simple example. You bought a new laptop, and now you want to take all your data from your previous laptop and store it on the new one. For simplicity, we will assume that both these laptops have the same operating system. Once the cloning process is complete, the constituent parts changed, but the programs and the software that you installed remained the same. Same data or information, but different underlying machinery.</p><p>Can we draw a parallel? A company is an independent entity and it exists in the market (or in the world) all by itself. People who constitute the company are primarily focused on their sustenance, and when each person works together for their sustenance, they ensure the sustenance of the company. In the same way, each cell in our body primarily has only one objective — to pass on their genetic material, and together when all the cells work for it, they ensure that the body functions optimally. The common thing between our body and a Corporate Company is that they are both information. There is nothing tangible. We cannot answer who we are by only considering tangible units like organs or cells. We are the outcome of the information that has been created from the quintillions of interactions that occur between our cells. Some of these interactions are impacted by the external world — demographics, economic class, status quo, experiences, and learnings.</p><p>Evolution is very much like emergence. One might even argue that evolution and emergence are synonymous. Evolution happens when small changes in a piece of information add up to create a totally different entity. In terms of biology, the cumulative effect of differences in the genetic material of a species can result in the formation of a new species. If we talk about our societies, small changes in the lifestyles of people add up and result in big revolutions. For example, the poor economic policies of France, weakened by the seven years of war and the American war of independence, the rising inequality between the bourgeoisie and the proletariats, and the rise of the concept of liberty and the constitutional governance gave rise to the French revolution, which created a worldwide movement towards the democratic form of governance.</p><p>We must understand that the way we are made out of the emerging properties of our cells, our society is made up of the emerging properties of our individual interactions with each other. We are the cells of our society. At an individual level, we are self-sustaining, smart, and calculative. But looking down from a societal level, we are small dumb parts of an abstract whole. We are not independent of each other. Everyone’s decision has an impact on every other in the society, no matter how minuscule that might be. And that might be the reason why we undergo similar experiences. Maybe there is something like a universal human experience, after all!</p><p>Thinking is also a very basic human experience. We all think, about something at every moment. But do you also think why everything is the way they are? Do you wonder if you knew all the secrets of this universe? Tell me in the comments section.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5d3023263e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What changed?]]></title>
            <link>https://medium.com/@sayan-paul/what-changed-6361da178aaa?source=rss-49a64a2d854a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6361da178aaa</guid>
            <category><![CDATA[college]]></category>
            <category><![CDATA[introspection]]></category>
            <category><![CDATA[schools]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[reflections]]></category>
            <dc:creator><![CDATA[Sayan Paul]]></dc:creator>
            <pubDate>Thu, 05 May 2022 15:57:03 GMT</pubDate>
            <atom:updated>2022-05-07T14:32:12.261Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Jaypee Institute of Information Technology (JIIT)" src="https://cdn-images-1.medium.com/max/1024/1*YJ4q6zJ_AX8kD_J7D4MDvQ.jpeg" /></figure><p>It was college after almost a week. In the last semester, you do not have a lot of classes, and the competence between students and the overall essence and spark of being in a class is at its minimum. It feels to me as if this is all life is now, monotonous, boring, and with no enthusiasm. But this wasn’t always the case, and this thought in itself concerns me a lot.</p><p>Back in my school days, and during the early semesters of college, life was bliss. I used to be enthusiastic, and full of energy. I wonder what has changed. Or if I went through a trauma and don’t know about it. Or maybe it’s just a phase that every person has to go through. Even possible, this feeling is cyclic, but as soon as it wears down, we forget about it.</p><p>We had three classes today from 10 a.m. to 3 p.m. with two hours in between with no classes at all. What a bummer it is to be alone for two hours under the scorching sun. The last class was Quality Issues in Engineering, which is the hardest subject for me this semester. I am dope at mathematics and analytical thinking, and this subject is basically a combination of the two.</p><p>Today, our professor was showing us the answer sheets from our exam the previous week. In our college, we have three exams called, T1, T2, and T3. T1 and T2 are like the internals, and T3 is like the externals. We need a total of thirty percent from all these exams combined to pass in that subject. Imagine how hard it must have been for me to explain this to my friends from other colleges.</p><p>I got twelve marks out of twenty, which is like sixty percent. I was so happy. I texted my boyfriend that very moment. It was as if I achieved something so unimaginably big (I still feel like that). But then this memory struck me so hard, that this kind of feeling wasn’t always the case. Getting twelve on twenty would be such a disappointment just two and a half years back.</p><p>I was quite above average in academics until my class twelfth. So getting sixty percent would be a great disappointment. But I remember that it wasn’t for everyone. When I was in tenth, there was this girl in our class who was not brilliant in academics. In one of our exams, she got some marks that wouldn’t satisfy me, but for her, it was such an achievement. And I could feel that today. I am not saying that I couldn’t understand her then. But there’s a difference between understanding and being in someone’s boots.</p><p>But this feeling today isn’t the first time. I have gotten low marks so many times now, that maybe now it doesn’t affect me at all. But I see people around me sobbing over their marks and even begging for increments whenever a teacher or a professor shows us our answer sheets. And more often than not, they are sobbing over something that is already too much. Why can’t people just be satisfied with what they get? Sometimes there can be errors in correcting a paper, but not every time, and not with everybody at the same time.</p><p>Although it might seem like a poorer version of me, I am grateful to have evolved like this. Because the world is not a pen and a paper exam, so worrying about marks or appreciation is not worthwhile. I believe that it is only important that I understand the concept and can visualize it in a real-world scenario. What do you think about this? When you look back at your life, how much difference can you see in yourself? Let me know in the comments below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6361da178aaa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basic tutorial for Browser Automation using Selenium]]></title>
            <link>https://medium.com/@sayan-paul/fill-google-forms-using-selenium-7818b93330c0?source=rss-49a64a2d854a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7818b93330c0</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[surveys]]></category>
            <category><![CDATA[google-forms]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Sayan Paul]]></dc:creator>
            <pubDate>Sun, 20 Feb 2022 17:27:39 GMT</pubDate>
            <atom:updated>2022-04-30T15:51:44.139Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rgiZNq-mxst8HOzY" /></figure><p>A lot of humankind’s tedious and monotonous workload has been relieved by the use of machines. Machines can be designed and made to work on a particular task, with high efficiency. The percentage of companies that have completely automated at least one function has grown from 29% in 2018 to 31% in 2020.</p><p>One of the uses of automation is in software testing utilities. Companies that create software need to check for bugs. Automation Testing is a technique that uses automated testing software to execute test case suites. Selenium is a popular open-source automation software, that lets you automate web browsers. It provides a single interface for writing scripts in many programming languages, like Ruby, Python, Java, Node.js, PHP, C#, and others.</p><p>But before we can dwell deep into programming a Google form automation software, we need to understand certain web basics.</p><h4>Inspect a webpage</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*fP1c-hCGY53xUezrPQ9HxQ.jpeg" /></figure><p>Open any random google form, then right-click anywhere on the page, and select inspect. This can be done on any webpage. You can try on this right now, on this page itself if you’re reading this blog on a PC or a laptop. Doing this opens up the background details of what is happening on that page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VLHQnXOyJMe0FTRsVAx7qA.jpeg" /><figcaption>Under the elements option, you can see the HTML elements that are used for making the webpage</figcaption></figure><h4>HTML element identifiers</h4><p>For any web application, identifying the HTML elements on a page is crucial for its working. HTML elements contain certain attributes that provide additional information about them. Some of these attributes help us provide identification to an HTML element. For example, a certain element on a webpage may belong to a certain class, or it may have a name or an ID.</p><pre>&lt;div&gt;<br> &lt;p id=”para01&quot; name=”description” class=”paragraph”&gt;<br>  This is a paragraph tag.<br> &lt;/p&gt;<br>&lt;/div&gt;</pre><p>Selenium requires some form of identity to access a tag on a webpage. To find these attributes of an element, you need to locate the HTML tag defining that element in the inspect page window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8R9QJ0-sYYfYPeUHL2BNog.png" /><figcaption>The highlighted tag defines the set of four options in the first question of the form</figcaption></figure><p>We need the value of the class name for our automation program. Classes generally denote a group of similar elements. The class that is highlighted in the picture, is the class of all questions within a google form.</p><h4>Web Driver</h4><p>A web driver drives a browser natively, emulating how a real-world user would use it. To automate a browser, we need a web driver corresponding to that browser. We should also be careful about the version of the browser while choosing a web driver. At first download the web driver. I will be using Chrome Driver for my program. You can download chrome driver from this website <a href="https://chromedriver.chromium.org/"><em>chromedriver.chromium.org</em></a>. Once you download it, unzip the file, and copy its path. If you want to use Gradle or Maven, find the dependencies on this <a href="https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver"><em>link</em></a>.</p><h4>Opening the Google form</h4><p>First set the system property for working with a browser (line-1). Then create an instance of the <em>ChromeDriver</em> class (line-2). Use the class corresponding to the browser that you wish to use. Use the <em>get</em> method to open the passed <em>URL </em>(line-3)<em>.</em></p><pre>String key = &quot;webdriver.chrome.driver&quot;, value=<br>    &quot;C:\\Program Files (x86)\\chromedriver_win32\\chromedriver.exe&quot;;</pre><pre>System.<em>setProperty(key, value</em>);                        <em>//line:1</em><br><br>WebDriver driver = <strong>new</strong> ChromeDriver();                 <em>//line:2</em><br>String url = &quot;https://forms.gle/jrcqccQErE9RaBS59&quot;;<br>driver.get(url);                                       <em>//line:3</em></pre><p>See the documentation of the interface <strong><em>WebDriver</em></strong> on this <a href="https://www.javadoc.io/doc/org.seleniumhq.selenium/selenium-api/2.50.1/org/openqa/selenium/WebDriver.html"><em>link</em></a>.</p><h4>Finding Elements on a webpage</h4><p>Selenium uses one of the following as a parameter to find elements on a webpage :</p><ul><li>ID</li><li>Name</li><li>Class Name</li><li>Tag Name</li><li>Link Text</li><li>Partial Link Text</li><li>XPath</li></ul><p>We can use either <em>findElement</em> or <em>findElements</em> method of the WebDriver interface for finding elements in a webpage. The difference between these two methods is that the former returns the first element of the page that matches the parameter, whereas the latter returns a list containing all the elements of the page that matches the parameter.</p><pre>WebElement ele = driver.findElement(By.<em>className</em>(&quot;some class&quot;));</pre><p>or</p><pre>WebElement ele = driver.findElement(By.<em>tag</em>(&quot;div&quot;));</pre><p>Note that these methods are also available for each WebElement instance. In that case, however, it only considers the elements within the element that called it.</p><p>Lets say this is the HTML page we want to automate :</p><pre>&lt;div class=&quot;division&quot;&gt;<br> &lt;p id=”para01&quot; name=”description” class=”paragraph”&gt;<br>  This is a paragraph tag.<br> &lt;/p&gt;<br> &lt;p id=”para02&quot; name=”usage” class=”paragraph”&gt;<br>  This is used to enclose a paragraph.<br> &lt;/p&gt;<br>&lt;/div&gt;</pre><p>And the following is the code we are writing to find elements on this page :</p><pre>WebElement ele = driver.findElement(By.<em>className</em>(&quot;division&quot;));<br>WebElement child = ele.findElement(By.className(&quot;paragraph&quot;));</pre><p>In this case, the instance ‘<em>ele’ </em>will contain the div of the class<em> ‘division’’</em>, and the instance child will contain the paragraph tag with the id <em>‘para01’</em>.</p><h4>Algorithm</h4><p>Once we open the URL, we need to fill in random values into the Google form. For simplicity, we will only consider two input types, Multiple choice, and Short text.</p><p>Here is a simple algorithm for this :</p><ul><li>Since all questions on a google form belong to the same class, we can use the <em>findelements </em>method to retrieve the list of all the questions that are there in the form.</li><li>Iterate through the list, and for each element check which type of question it contains. For this, again use the method <em>findelements </em>to retrieve a list of child elements. We can use class names for radio buttons, or text areas for this task.</li><li>If a list is empty, it means that there are no elements corresponding to that class name within the parent element.</li><li>If there are radio buttons, then select a random button to click. If there is a text area, then you can set any text within it. Check out the code below to see how to do these.</li><li>Once the iteration over all the questions is completed, find the <em>next/submit</em> button. Click the button.</li><li>If the above button was the <em>next</em> button, then repeat the above steps.</li></ul><p>The following is the program for the above algorithm.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2566436c2692097f639b96835482dc0e/href">https://medium.com/media/2566436c2692097f639b96835482dc0e/href</a></iframe><p>Similarly, we can add the usability of other kinds of Google form questions as well.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F0rFTLXJkEJs&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D0rFTLXJkEJs&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/193a28adb8250c1d7cc83512e8c77a5c/href">https://medium.com/media/193a28adb8250c1d7cc83512e8c77a5c/href</a></iframe><p>See the full project on this <a href="https://github.com/sayan-17/Google-form-automation">link</a>.</p><p>This article was a demonstration of how Selenium can be used for automating a Google form. Similarly, we can also automate a plethora of other websites on various web browsers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7818b93330c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Types of HTTP Request Methods]]></title>
            <link>https://medium.com/@sayan-paul/types-of-http-request-methods-9a515aecbe8c?source=rss-49a64a2d854a------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a515aecbe8c</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[servers]]></category>
            <dc:creator><![CDATA[Sayan Paul]]></dc:creator>
            <pubDate>Sun, 13 Feb 2022 13:55:02 GMT</pubDate>
            <atom:updated>2022-02-14T15:35:13.493Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_P3zfJVG1nfunm9r" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There is a wide array of resources on the internet, hosted on servers. To utilize these resources, a browser or a client program sends a request to the respective server. Most browsers access the World Wide Web which uses the HTTP protocol. Every message or request or response, communicated over the World Wide Web are essentially HTTP Requests. However, there are certain exceptions.</p><p>HTTP defines certain request methods that indicates the action to be performed. They are also referred to as HTTP verbs.</p><p>Have a look at the screenshot below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*F8GwEZe_fL1SDaiFCLxQcQ.jpeg" /><figcaption>Random Video from YouTube, skipped to 10 minutes (or 600 seconds)</figcaption></figure><p>Take a look at the URL of this video. After the name of the website (i.e., youtube.com), we can see something like a query. The URL doesn’t only specifies which website, it also contains the information about which video and a time stamp in that video.</p><p>The term ‘<strong><em>watch’ </em></strong>is used as a token for what kind of result we want (in this case a video that we want to watch), and after the question mark, there are two parameters separated by a logical <strong><em>‘&amp;’</em></strong>. The first part <strong><em>“v=24NrLl8EhDM”</em></strong>, acts as a video ID where as the second part <strong><em>“t=600s”</em></strong>, acts as a time stamp, i.e., if opened with this query attached, the video will open from 600 seconds (or 10 minutes).</p><p>This type of a URL is created when an HTTP request uses GET method. Various methods are used to denote what kind of action has to be performed. GET method is used to retrieve something from the server. As for our example, we are retrieving a video with that particular Video ID, opened to that particular time stamp.</p><p>A list of the HTTP request methods :</p><p><strong>GET<br></strong>To retrieve information from the given server using a given URL.</p><p><strong>HEAD<br></strong>Same as GET, but transfers the status line and header section only.</p><p><strong>POST<br></strong>To send some data to the server.</p><p><strong>PUT<br></strong>To store some data at a location specified by the given URL.</p><p><strong>DELETE<br></strong>To delete some file at the server end.</p><p><strong>CONNECT<br></strong>To establish a network with the server.</p><p><strong>OPTIONS<br></strong>To find out what methods are supported by the server.</p><p><strong>TRACE<br></strong>To echo the contents of the HTTP Request back to the requester that can be used for debugging.</p><p>Let us see where these methods are specified by looking at a Java Program.</p><pre><strong>public class</strong> RequestHandler <strong>implements</strong> HttpHandler {<br><em>@Override</em><br><strong>public void</strong> handle(HttpExchange httpExchange) <strong>throws</strong> IOException{<br>   <br>   String method = httpExchange.getRequestMethod();<br>   <br>   <strong>try</strong> {<br>      <strong>if</strong> (method.equals(<em>GET_METHOD</em>)) {<br>         //Code corresponding to GET method</pre><pre>      } <strong>else if</strong> (method.equals(<em>POST_METHOD</em>)) {<br>         //Code corresponding to POST method</pre><pre>      } <strong>else if</strong> (method.equals(<em>PUT_METHOD</em>)) {<br>         //Code corresponding to PUT method</pre><pre>      }<br>   }<strong>catch</strong> (Exception e){<br>      <br>   }<br>}<br>}</pre><p>The above method is an over-ridden method in the class that implements the interface <a href="https://docs.oracle.com/javase/8/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpHandler.html"><strong><em>HttpHandler</em></strong></a> . The method that is used can be simply extracted using the <strong><em>getRequestMethod()</em></strong> method of the <a href="https://docs.oracle.com/javase/8/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpExchange.html"><strong><em>HttpExchange</em></strong></a> class. To see the tutorial to create a Java Server, check my post <strong>“</strong><a href="https://medium.com/@noob-code/develop-an-http-server-in-java-2137071a54a1"><strong>Develop an HTTP Server in Java</strong></a><strong>”</strong>.</p><p>The following is an example of a server that can only handle GET and POST requests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8312e64ff612c7c1511d7e1a442fe14/href">https://medium.com/media/f8312e64ff612c7c1511d7e1a442fe14/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d035eb2be693e4e5204f9ffdab214eb/href">https://medium.com/media/9d035eb2be693e4e5204f9ffdab214eb/href</a></iframe><p>For the purpose of this tutorial, we store our data in a HashMap. However, in most original real world servers, data is retrieved from a database.</p><p>Here is a working demo for the above code :</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FLLKTIS9GTBc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DLLKTIS9GTBc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FLLKTIS9GTBc%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/38330f6d75680d368a2a9100afa560b3/href">https://medium.com/media/38330f6d75680d368a2a9100afa560b3/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a515aecbe8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Develop an HTTP Server in Java]]></title>
            <link>https://medium.com/@sayan-paul/develop-an-http-server-in-java-2137071a54a1?source=rss-49a64a2d854a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2137071a54a1</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[servers]]></category>
            <dc:creator><![CDATA[Sayan Paul]]></dc:creator>
            <pubDate>Sat, 05 Feb 2022 08:29:13 GMT</pubDate>
            <atom:updated>2022-02-13T14:18:18.439Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CqUzctwOpnGyf8UO" /><figcaption>Photo by <a href="https://unsplash.com/@6heinz3r?utm_source=medium&amp;utm_medium=referral">Gabriel Heinzer</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A lot of the World Wide Web is developed on the Client-Server model. According to this structure, a task or workload is divided into two parts; a service or a resource provider, called a server, and a requester who wants to utilize the resource or the service, called a client.</p><p>On the internet, there are many different protocols that are being used. A protocol is basically a set of instructions that two machines (or software) need to follow in order to communicate. For a Client to send a request to a server and for the server to understand it, they must follow the same protocol(s). In our example I would be demonstrating the Hyper Text Transfer Protocol (HTTP).</p><p>Java has an <a href="https://docs.oracle.com/javase/8/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpServer.html"><strong><em>HTTPServer</em></strong></a> class under the package <strong><em>com.sun.net.httpserver</em></strong> . We will create an object of this class, and then assign a port for the server to run on. A port is a virtual end-point within the operating system from where a network connection can start or end. Since our server has to establish communication with clients, it needs to be run on a port. We can use the class <a href="https://docs.oracle.com/javase/7/docs/api/java/net/InetSocketAddress.html"><strong><em>InetSocketAddress</em></strong></a> under the package <strong><em>java.net</em></strong> for this purpose.</p><pre><strong>private static void</strong> runServer() <strong>throws</strong> IOException{<br>   // Create a server that runs on the port 8000<br>   HttpServer server = HttpServerImpl.<em>create</em>(new<br>                                      InetSocketAddress(8000),0);<br>}</pre><p>When a request is received at the server, an instance of the <a href="https://docs.oracle.com/javase/8/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpContext.html"><strong><em>HTTPContext</em></strong></a> class is created. A Context describes all the HTTP-specific information about a single HTTP request.</p><p>Each HTTPContext has a path and an HTTP Request Handler. There are different types of requests that a client can make to a server. The Request Handler takes care of what needs to be done when a request is received at the server. We need to implement the <a href="https://docs.oracle.com/javase/8/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpHandler.html"><strong><em>HTTPHandler</em></strong></a> interface. Whenever a request is sent to the Server, the handle() method of the class that implements this interface is called. We can say that what happens at the server has to be defined in this method.</p><pre><strong>private static void</strong> runServer() <strong>throws</strong> IOException{<br>   HttpServer server = HttpServerImpl.<em>create</em>(<strong>new</strong><br>                                      InetSocketAddress(8000),0);</pre><pre>   //Create an HTTP Context and set it&#39;s path<br>   HttpContext context = server.createContext(&quot;/&quot;);<br>   <br>   //Create a Request Handler for the Server<br>   context.setHandler(<strong>new</strong> RequestHandler());<br>}</pre><pre><strong>class</strong> RequestHandler {<br>   <em>@Override</em><br>   <strong>public void</strong> handle(HttpExchange httpExchange) <strong>throws</strong> IOException{<br>      //Code for what happens at the server, here we simply print<br>      //the request message<br>      InputStream inStream = httpExchange.getRequestBody();<br>      Scanner scanner = <strong>new</strong> Scanner(inStream);<br>      String data = scanner.nextLine();<br>      System.<em>out</em>.println(data);<br>   }<br>}</pre><p>Every HTTP request has certain fields, that contain the information about it, like the time of arrival, the protocol used and many more along with a request body that contains some data. There are different kinds of requests like GET, POST, PUT etc. Once the request is received and processed, a response is sent back to the client, which contains all the data that it requested for. The <a href="https://docs.oracle.com/javase/8/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpExchange.html"><strong><em>HTTPExchange</em></strong></a> class contains all the data of the request that is received and the data of the response that would be sent back.</p><p>After setting up the Request Handler, use the method start() of HTTPServer to start running your server on the port.</p><p>Here’s the full code for making the sever :</p><pre><strong>public class</strong> Server {<br>   <strong>private class</strong> RequestHandler {<br>      <em>@Override</em><br>      <strong>public void</strong> handle(HttpExchange httpExchange) <strong>throws<br>                                                    </strong>IOException{<br>         InputStream inStream = httpExchange.getRequestBody();<br>         Scanner scanner = <strong>new</strong> Scanner(inStream);<br>         String data = scanner.nextLine();<br>         System.<em>out</em>.println(data);<br>      }<br>   }<br>   <strong>private void</strong> runServer() <strong>throws</strong> IOException {<br>      HttpServer server = HttpServerImpl.<em>create</em>(<strong>new</strong><br>                                         InetSocketAddress(8000),0);<br>      HttpContext context = server.createContext(&quot;/&quot;);<br>      context.setHandler(new RequestHandler());<br>      server.start();<br>   }<br>   <br>   <br>   <strong>public static void</strong> main(String[] args){<br>      <strong>try</strong> {<br>         Server server = new Server();<br>         server.<em>runServer</em>();<br>      } <strong>catch </strong>(IOException e) {<br>         e.printStackTrace();<br>      }<br>   }<br>}</pre><p>Check out my next post about making a server, <strong>“</strong><a href="https://medium.com/@noob-code/types-of-http-request-methods-9a515aecbe8c"><strong>Types of HTTP Request Methods</strong></a><strong>”</strong> .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2137071a54a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>