<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: saiteja623</title>
    <description>The latest articles on DEV Community by saiteja623 (@saitejaballa).</description>
    <link>https://dev.to/saitejaballa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F486595%2F24581394-53d8-4ee1-840d-abb4b465e37b.jpg</url>
      <title>DEV Community: saiteja623</title>
      <link>https://dev.to/saitejaballa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saitejaballa"/>
    <language>en</language>
    <item>
      <title>Multiprogramming vs Multiprocessing vs Multitasking vs  Multithreading</title>
      <dc:creator>saiteja623</dc:creator>
      <pubDate>Fri, 16 Oct 2020 08:15:30 +0000</pubDate>
      <link>https://dev.to/saitejaballa/multiprogramming-vs-multiprocessing-vs-multitasking-vs-multithreading-1ac2</link>
      <guid>https://dev.to/saitejaballa/multiprogramming-vs-multiprocessing-vs-multitasking-vs-multithreading-1ac2</guid>
      <description>&lt;p&gt;A CS Student must be aware of all the above terms. Let us have a clear explanation and clean difference between all of them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Multiprogramming
&lt;/h3&gt;

&lt;p&gt;So what is this multiprogramming ?. As the name says, Multiple programmes will get executed. So, let's understand this with example.&lt;/p&gt;

&lt;p&gt;Consider 4 programmes say P1,P2,P3,P4 are in the main memory and need the CPU to get processed. Let us get this through a conversation&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CPU&lt;/strong&gt;  :  Come on &lt;em&gt;P1&lt;/em&gt;,I will execute you .&lt;br&gt;&lt;br&gt;
( &lt;em&gt;P1&lt;/em&gt; executes for sometime and need to access I/O )&lt;br&gt;&lt;br&gt;
&lt;strong&gt;P1&lt;/strong&gt;     : Hey CPU, I need I/O.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;CPU&lt;/strong&gt; : Okay go for it. Come on &lt;strong&gt;P2&lt;/strong&gt; , Now I will execute you.&lt;br&gt;&lt;br&gt;
( &lt;strong&gt;P1&lt;/strong&gt; returns to &lt;em&gt;CPU&lt;/em&gt; after its I/O completion ).&lt;br&gt;&lt;br&gt;
&lt;strong&gt;CPU&lt;/strong&gt; : &lt;em&gt;P2&lt;/em&gt; You need to wait  as &lt;em&gt;P1&lt;/em&gt; got returned ,Again I will execute You Once if &lt;em&gt;P1&lt;/em&gt; gets processed or goes for I/O.&lt;/p&gt;

&lt;p&gt;In the above, when P1 goes for I/O, CPU is  idle. It will be executing the next process in the main memory i.e., P2 until P1 returns. Once P1 job is done P2 gets executed and this will go on..&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The main aim of multiprogramming is to maximize the CPU utilization.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Multiprocessing
&lt;/h3&gt;

&lt;p&gt;When you want to purchase a new laptop, Obviously you check the specifications of each laptop. In specifications there must be "dual-core",&lt;br&gt;
"octa-core", "quad-core" .Ever wondered what these cores are?&lt;/p&gt;

&lt;p&gt;Cores are the processors. Each core can execute a process.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;dual core   -   2 cores&lt;/li&gt;
&lt;li&gt;quad core  -   4 cores&lt;/li&gt;
&lt;li&gt;octa core   -   8 cores&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's understand this through an  example. &lt;/p&gt;

&lt;p&gt;You have a building to construct and You got only one worker. It takes much long time to build right?. What If you have 4 workers instead?. As the number of workers increases, the time to complete the work decreases.&lt;/p&gt;

&lt;p&gt;You can compare cores to the workers. If your OS is quad-core then 4 multiple core can work at a time on a single programme if and only if the programme needs 4 cores. If the  programme needs only two cores then other two cores will be idle. &lt;/p&gt;

&lt;h2&gt;
  
  
  Multitasking
&lt;/h2&gt;

&lt;p&gt;Okay. Let's say you want to listen to music and want to do coding simultaneously. This is achieved by multitasking.  Chewing a bubble gum while walking is an example of multitasking. &lt;/p&gt;

&lt;h3&gt;
  
  
  Multitasking in single core OS
&lt;/h3&gt;

&lt;p&gt;Do you think Your system really executes multiple programme concurrently?&lt;/p&gt;

&lt;p&gt;Obviously No!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1602765904344%2F2poalBBFm.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1602765904344%2F2poalBBFm.jpeg" alt="multitask+on+single+core_550.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;what your OS really does is, It executes each programme for a little amount of time and switches to another programme.&lt;/p&gt;

&lt;p&gt;For example, Your OS executes Music for 5ns and it switches to editor in which you are coding and executes it for 5ns and again switches to music and executes for 5ns and this will go on.....This context switching between programmes is so fast that we humans  get the illusion of multiple programmes executing at a time.Actually it is not!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Multitasking OS is also called time-sharing OS.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Multitasking in Multicore OS
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1602766107543%2Frg72vH9DQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1602766107543%2Frg72vH9DQ.jpeg" alt="multitask+on+multiple+cores_550.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here above you have 4 tasks to run simultaneously. we have dual-core OS and each core is assigned to two tasks. In the above first core needs to run wordprocessor and E-mail. As one core can't do two programmes it uses the concept of multitasking and runs it concurrently. &lt;/p&gt;

&lt;p&gt;### Multithreading&lt;/p&gt;

&lt;p&gt;Threads are the main execution of a process. IN multithreading multiple threads execute a process and makes the process get executed faster.&lt;/p&gt;

&lt;p&gt;Okay, You have opened a browser and you are surfing the web while downloading a song.&lt;/p&gt;

&lt;p&gt;Here, One threads controls the downloading of song another thread controls the requests to the server. Other thread controls opening of new tab and these are done concurrently.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A single core OS with threads can work like dual-core. &lt;br&gt;&lt;br&gt;
A dual core OS with threads can work like quad-core. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's it. If still you are unclear with the concepts, Please let  me know.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Let's connect on  &lt;a href="https://twitter.com/saiteja0413" rel="noopener noreferrer"&gt;twitter&lt;/a&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Happy coding :)&lt;/p&gt;

</description>
      <category>100daysofcode</category>
      <category>codenewbie</category>
      <category>os</category>
      <category>howthingswork</category>
    </item>
    <item>
      <title>HTML5 Tags at a glance</title>
      <dc:creator>saiteja623</dc:creator>
      <pubDate>Thu, 15 Oct 2020 11:34:00 +0000</pubDate>
      <link>https://dev.to/saitejaballa/html5-tags-at-a-glance-h3o</link>
      <guid>https://dev.to/saitejaballa/html5-tags-at-a-glance-h3o</guid>
      <description>&lt;p&gt;Let us have a look at common HTML5 tags.&lt;/p&gt;

&lt;h3&gt;
  
  
  Document Outline
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;!&lt;/span&gt;&lt;span class="na"&gt;DOCTYPE&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;         &lt;span class="c"&gt;&amp;lt;!-- Version of (X)HTML --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;                &lt;span class="c"&gt;&amp;lt;!--HTML Document--&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;               &lt;span class="c"&gt;&amp;lt;!--page information --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;               &lt;span class="c"&gt;&amp;lt;!-- Page Contents --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Page Information
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;base/&amp;gt;&lt;/span&gt;       &lt;span class="c"&gt;&amp;lt;!-- Base URL --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta/&amp;gt;&lt;/span&gt;       &lt;span class="c"&gt;&amp;lt;!-- Meta data --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;          &lt;span class="c"&gt;&amp;lt;!--Title --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;link/&amp;gt;&lt;/span&gt;         &lt;span class="c"&gt;&amp;lt;!-- Relevant resource --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nt"&gt;Style&lt;/span&gt; &lt;span class="nt"&gt;resource&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;       &lt;span class="o"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nt"&gt;script&lt;/span&gt; &lt;span class="nt"&gt;resources&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Links
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;                   &lt;span class="c"&gt;&amp;lt;!-- Page link --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"mailto:"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;        &lt;span class="c"&gt;&amp;lt;!-- Email link --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;        &lt;span class="c"&gt;&amp;lt;!-- Anchor --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;        &lt;span class="c"&gt;&amp;lt;!-- Link to a anchor --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Document Structure
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&amp;lt;h6&amp;gt;&lt;/span&gt;       &lt;span class="c"&gt;&amp;lt;!-- Headings --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;               &lt;span class="c"&gt;&amp;lt;!-- Page section or a division --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt;            &lt;span class="c"&gt;&amp;lt;!-- Inline section --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;                  &lt;span class="c"&gt;&amp;lt;!-- Paragraph --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;br/&amp;gt;&lt;/span&gt;                &lt;span class="c"&gt;&amp;lt;!--Line break --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;hr/&amp;gt;&lt;/span&gt;                &lt;span class="c"&gt;&amp;lt;!-- Horizontal line --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Forms
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&amp;gt;&lt;/span&gt;        &lt;span class="c"&gt;&amp;lt;!-- form --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;    &lt;span class="c"&gt;&amp;lt;!--collection of fields --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;     &lt;span class="c"&gt;&amp;lt;!-- Form legend --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;         &lt;span class="c"&gt;&amp;lt;!-- Label for Input --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;      &lt;span class="c"&gt;&amp;lt;!-- Input fields--&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;select&amp;gt;&lt;/span&gt;       &lt;span class="c"&gt;&amp;lt;!-- Drop-down box --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;optgroup&amp;gt;&lt;/span&gt;  &lt;span class="c"&gt;&amp;lt;!--Group of options --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;option&amp;gt;&lt;/span&gt;     &lt;span class="c"&gt;&amp;lt;!--Drop down options --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;textarea&amp;gt;&lt;/span&gt;   &lt;span class="c"&gt;&amp;lt;!--Large text Input --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;       &lt;span class="c"&gt;&amp;lt;!-- A button  --&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Tables
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;table&amp;gt;&lt;/span&gt;              &lt;span class="c"&gt;&amp;lt;!-- Table --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;caption&amp;gt;&lt;/span&gt;          &lt;span class="c"&gt;&amp;lt;!-- For Caption --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;thread&amp;gt;&lt;/span&gt;           &lt;span class="c"&gt;&amp;lt;!--Thread --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;tbody&amp;gt;&lt;/span&gt;            &lt;span class="c"&gt;&amp;lt;!-- Table body --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;tfoot&amp;gt;&lt;/span&gt;              &lt;span class="c"&gt;&amp;lt;!-- Table foot --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;colgroup&amp;gt;&lt;/span&gt;      &lt;span class="c"&gt;&amp;lt;!-- Column Group --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;col/&amp;gt;&lt;/span&gt;                &lt;span class="c"&gt;&amp;lt;!-- column --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;                   &lt;span class="c"&gt;&amp;lt;!-- table row--&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;                   &lt;span class="c"&gt;&amp;lt;!-- Header Cell --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;                  &lt;span class="c"&gt;&amp;lt;!-- Table cell --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Lists
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ol&amp;gt;&lt;/span&gt;       &lt;span class="c"&gt;&amp;lt;!-- Ordered List --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;       &lt;span class="c"&gt;&amp;lt;!-- UnOrdered List --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;        &lt;span class="c"&gt;&amp;lt;!-- List Item --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;dl&amp;gt;&lt;/span&gt;       &lt;span class="c"&gt;&amp;lt;!-- Definition List --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;dt&amp;gt;&lt;/span&gt;      &lt;span class="c"&gt;&amp;lt;!-- Definition term --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;dd&amp;gt;&lt;/span&gt;     &lt;span class="c"&gt;&amp;lt;!-- Term description --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay, I think I almost covered all common HTML Tags we often use. If I miss one in case ?, Please DO let me know!&lt;/p&gt;

&lt;p&gt;Thanks for the read.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Lets connect on  &lt;a href="https://twitter.com/saiteja0413"&gt;Twitter&lt;/a&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Happy Coding :)&lt;/p&gt;

</description>
      <category>html</category>
      <category>100daysofcode</category>
      <category>codenewbie</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What exactly "static" keyword is in Java?</title>
      <dc:creator>saiteja623</dc:creator>
      <pubDate>Thu, 15 Oct 2020 11:29:42 +0000</pubDate>
      <link>https://dev.to/saitejaballa/what-exactly-static-keyword-is-in-java-1lnj</link>
      <guid>https://dev.to/saitejaballa/what-exactly-static-keyword-is-in-java-1lnj</guid>
      <description>&lt;p&gt;Many of us still get confused with the keyword static. Now, we will discuss how static keyword is used? and how it helps to save lots of code  from rewriting?&lt;/p&gt;

&lt;p&gt;Look at the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;staticDemo&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[]){&lt;/span&gt;
                     &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello world!"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;//prints "Hello world"&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"Hello world" is the basic programme right ?.It is how someone starts learning java. Do you ever noticed that the main method has a keyword &lt;code&gt;static&lt;/code&gt;?. What this static does?. &lt;/p&gt;

&lt;p&gt;By using &lt;code&gt;static&lt;/code&gt; keyword in  &lt;code&gt;main()&lt;/code&gt; method , we can call the &lt;code&gt;main()&lt;/code&gt; method without any instance of object i.e., We can call the &lt;code&gt;static&lt;/code&gt; methods using class name. &lt;/p&gt;

&lt;p&gt;Let's have another example -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;A&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
     &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;  &lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
         &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"static method in class A"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;  
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;staticDemo&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[]){&lt;/span&gt;
                     &lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;show&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// prints  "static method in class A"&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  static variable in Java
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;static&lt;/code&gt; variables are the variables which are applicable to the all instances of the class declared it. When a variable is &lt;code&gt;static&lt;/code&gt; its value is same for the all instances. If any one of the instance changes the static variable value it reflects to all other instances too.&lt;/p&gt;

&lt;p&gt;consider the following code -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;A&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt; 
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;staticDemo&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[]){&lt;/span&gt;
        &lt;span class="no"&gt;A&lt;/span&gt; &lt;span class="n"&gt;obj1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="no"&gt;A&lt;/span&gt; &lt;span class="n"&gt;obj2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="no"&gt;A&lt;/span&gt; &lt;span class="n"&gt;obj3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;obj3&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; 
       &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;i&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 10&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOTE - &lt;code&gt;static&lt;/code&gt; variables can be accessed in non-static methods. But non-static variables can't be accessed in &lt;code&gt;static&lt;/code&gt;  methods. Why that is so?, Since non-static variables need for an instance to call the variables and we can assign different values for non-static variables by creating multiple objects. So there will be an ambiguity for the compiler to understand for which value instance value I should access.&lt;/p&gt;

&lt;p&gt;##  static block in java -&lt;/p&gt;

&lt;p&gt;&lt;code&gt;static&lt;/code&gt; block is used for initializing the static variables. &lt;code&gt;static&lt;/code&gt; block is executed only when the class is loaded into the memory i.e., only once.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;A&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;static&lt;/span&gt;  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;static&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
          &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"static block in A"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;   
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;staticDemo&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;static&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
     &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"static block in main"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
     &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[]){&lt;/span&gt;
              &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;i&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
               &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"static in main"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;


    &lt;span class="o"&gt;}&lt;/span&gt;  
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Always static blocks are executed first. static block gets executed and then &lt;code&gt;main()&lt;/code&gt; method gets executed. In  &lt;code&gt;main()&lt;/code&gt; method we have &lt;code&gt;A.i&lt;/code&gt; here A class gets loaded into the memory and when memory is loaded static block gets executed  and then the value of &lt;code&gt;i&lt;/code&gt; gets printed, at last "static in main" gets printed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// output of above code&lt;/span&gt;
&lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;
&lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="no"&gt;A&lt;/span&gt;
&lt;span class="mi"&gt;9&lt;/span&gt;
&lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;variables and methods with the &lt;code&gt;static&lt;/code&gt; keyword do not need an instance to access it. They can be accessed using  class name.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;static&lt;/code&gt; blocks are executed before  constructors and methods.&lt;/li&gt;
&lt;li&gt;If there are multiple &lt;code&gt;static&lt;/code&gt; blocks, they are executed as per the sequence in the code.&lt;/li&gt;
&lt;li&gt;non-static variables can't be accessed in &lt;code&gt;static&lt;/code&gt; methods.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for the read!. I hope  you have learnt something about &lt;code&gt;static&lt;/code&gt;. If you  feel something wrong please let me know :)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Let's get connect on  &lt;a href="https://twitter.com/saiteja0413"&gt;Twitter&lt;/a&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Happy coding :) &lt;/p&gt;

</description>
      <category>java</category>
      <category>codenewbie</category>
      <category>static</category>
    </item>
    <item>
      <title>Multithreading in java
</title>
      <dc:creator>saiteja623</dc:creator>
      <pubDate>Sat, 10 Oct 2020 09:20:49 +0000</pubDate>
      <link>https://dev.to/saitejaballa/multithreading-in-java-1487</link>
      <guid>https://dev.to/saitejaballa/multithreading-in-java-1487</guid>
      <description>&lt;p&gt;Multithreading  is the one which we often come across in java. So, What actually Multithreading is?, What it does?, why it is needed?.&lt;/p&gt;

&lt;p&gt;Let us consider the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Multithreading&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
          &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[]){&lt;/span&gt;
             &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code we can see Output is "hello"&lt;/p&gt;

&lt;p&gt;So how this code is running? , Every Java programme has main Method and the main method gets executed. Here main method is a thread.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to create Threads in Java?
&lt;/h2&gt;

&lt;p&gt;Now Let us make multiple threads in java&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;A&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hi"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;B&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;multithreading&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[]){&lt;/span&gt;
            &lt;span class="no"&gt;A&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="no"&gt;B&lt;/span&gt; &lt;span class="n"&gt;obj1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;B&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;start&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="n"&gt;obj1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;start&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
java&lt;br&gt;
In the above code ,We have two classes :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Class A&lt;/li&gt;
&lt;li&gt;Class B&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In order to provide a single thread for each class. We need to extend the Thread class and the code which thread should work upon will be written in the run() method and how do we call this run method? .We create a Object for each class and we call start() method. start()method is located in the Thread class. This start() method starts the execution of the thread. &lt;/p&gt;

&lt;p&gt;The output is different in different cases as we can't print different outputs at the same time .One is choosen between them based on some criteria and priorities.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;//output1&lt;/span&gt;
&lt;span class="n"&gt;hi&lt;/span&gt;
&lt;span class="n"&gt;hello&lt;/span&gt;
&lt;span class="n"&gt;hi&lt;/span&gt;
&lt;span class="n"&gt;hello&lt;/span&gt;
&lt;span class="n"&gt;hi&lt;/span&gt;
&lt;span class="n"&gt;hello&lt;/span&gt;
&lt;span class="n"&gt;hi&lt;/span&gt;
&lt;span class="n"&gt;hello&lt;/span&gt;
&lt;span class="n"&gt;hi&lt;/span&gt;
&lt;span class="n"&gt;hello&lt;/span&gt;

&lt;span class="c1"&gt;//output2&lt;/span&gt;
&lt;span class="n"&gt;hi&lt;/span&gt;
&lt;span class="n"&gt;hello&lt;/span&gt;
&lt;span class="n"&gt;hello&lt;/span&gt;
&lt;span class="n"&gt;hi&lt;/span&gt;
&lt;span class="n"&gt;hello&lt;/span&gt;
&lt;span class="n"&gt;hi&lt;/span&gt;
&lt;span class="n"&gt;hi&lt;/span&gt;
&lt;span class="n"&gt;hello&lt;/span&gt;
&lt;span class="n"&gt;hi&lt;/span&gt;
&lt;span class="n"&gt;hello&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have 3 Threads&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;class A thread&lt;/li&gt;
&lt;li&gt;class B thread&lt;/li&gt;
&lt;li&gt;main() thread&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;we should not override the start() method in Thread class by defining it  in class A and B. This calls the start() method in the child class rather than parent class and which no longer acts like a thread.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's the problem here?
&lt;/h2&gt;

&lt;p&gt;So we have a problem here :(. What if I want to extend both Thread and other class. Let's say I want other  class C  which extends class A and Thread.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;C&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="c1"&gt;//code&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait!. This is multiple Inheritence. Unfortunately we don't have multiple Inheritence in Java. Then how to overcome this?.&lt;/p&gt;

&lt;p&gt;Multiple Inheritence can be overcome by Interfaces. We do have a interface called Runnable Interface in Which a class can implement Runnable Interface.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;C&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="no"&gt;A&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Runnable&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;//code&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are not getting into the Runnable Interface. We will discuss it in the next Article in depth. &lt;/p&gt;

&lt;h2&gt;
  
  
  Applications of Multithreading
&lt;/h2&gt;

&lt;p&gt;There are lots of applications of Multithreading. Let's say you are playing game like PUBG. You can move and your friend can move and the sound effects when someone shoot these actions are performed simultaneously by different threads.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Threads are like workers who are need to construct a building&lt;/li&gt;
&lt;li&gt;Multiple Threads can work at a same time.&lt;/li&gt;
&lt;li&gt;Class should extends the Thread class and should have a run() method defined inorder to work as a seperate Thread.&lt;/li&gt;
&lt;li&gt;Create a object(obj) for the class. Call the run() method by obj.start()&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for the read!. If something feels wrong, please let me know.&lt;/p&gt;

&lt;p&gt;Happy coding :)&lt;/p&gt;

</description>
      <category>java</category>
      <category>codenewbie</category>
      <category>oop</category>
    </item>
  </channel>
</rss>
