<?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"><channel><title><![CDATA[DSA and Dev Days: Arun's Learning Blog]]></title><description><![CDATA[👨‍💻 Full Stack Developer in the Making | 🧠 DSA Enthusiast | 📚 Lifelong Learner | ✨ Passionate about Technology]]></description><link>https://arunkumar0203.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sun, 20 Sep 2026 19:18:07 GMT</lastBuildDate><atom:link href="https://arunkumar0203.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Day 8: Exploring the Power of PHP]]></title><description><![CDATA[Introduction
Welcome to our PHP-centric space, where we embark on a comprehensive journey to unravel the incredible world of web development. Whether you're a budding programmer or a seasoned developer looking to expand your skill set, PHP (Hypertext...]]></description><link>https://arunkumar0203.hashnode.dev/day-8-exploring-the-power-of-php</link><guid isPermaLink="true">https://arunkumar0203.hashnode.dev/day-8-exploring-the-power-of-php</guid><category><![CDATA[PHP]]></category><category><![CDATA[Databases]]></category><category><![CDATA[databasemanagement]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Server side rendering]]></category><dc:creator><![CDATA[Arun Kumar]]></dc:creator><pubDate>Sat, 23 Dec 2023 14:51:28 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/gAe1pHGc6ms/upload/186ff6b18897d8ba86e816c1871bd24a.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction"><strong>Introduction</strong></h2>
<p>Welcome to our PHP-centric space, where we embark on a comprehensive journey to unravel the incredible world of web development. Whether you're a budding programmer or a seasoned developer looking to expand your skill set, PHP (Hypertext Preprocessor) stands as a general-purpose server-side scripting language widely used for building dynamic and interactive websites.</p>
<h2 id="heading-chapter-1-getting-started-with-php"><strong>Chapter 1: Getting Started with PHP</strong></h2>
<h3 id="heading-11-why-php"><strong>1.1 Why PHP?</strong></h3>
<p>PHP is a versatile scripting language known for its ease of integration, powerful features, and robust community support. Learning PHP opens the door to building dynamic web applications, managing databases, and creating a wide range of interactive features for websites.</p>
<p><strong>PHP in web development</strong></p>
<ul>
<li><p>It is easily embedded into HTML.</p>
</li>
<li><p>It is compatible with Apache web server.</p>
</li>
<li><p>It doesn't need to be pre-compiled.</p>
</li>
<li><p>It has built-in integration with DBMS - MySQL.</p>
</li>
</ul>
<p>Here are some examples of well-known websites and applications built with PHP: Facebook, WordPress, Wikipedia, Yahoo, Flickr, etc.</p>
<h3 id="heading-12-setting-up-your-development-environment"><strong>1.2 Setting Up Your Development Environment</strong></h3>
<p>Before we jump into coding, let's ensure your development environment is ready.</p>
<h4 id="heading-121-installing-a-web-server">1.2.1 Installing a Web Server</h4>
<p>PHP is typically run on a web server. You can choose popular options like Apache or Nginx, depending on your preferences.</p>
<h4 id="heading-122-installing-php">1.2.2 Installing PHP</h4>
<p>Head over to the official PHP website (<a target="_blank" href="http://php.net">php.net</a>) to download and install the latest version of PHP. The website provides clear instructions for various operating systems.</p>
<h4 id="heading-123-choosing-a-code-editor">1.2.3 Choosing a Code Editor</h4>
<p>Selecting a suitable code editor is crucial for an efficient coding experience. Consider using Visual Studio Code, Sublime Text, or PHPStorm, which are widely used in the PHP development community.</p>
<h3 id="heading-13-your-first-php-script"><strong>1.3 Your First PHP Script</strong></h3>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
  <span class="hljs-keyword">echo</span> <span class="hljs-string">"Hello, World!"</span>;
<span class="hljs-meta">?&gt;</span>
</code></pre>
<p>Here's a breakdown of the code:</p>
<ul>
<li><p><code>&lt;?php</code>: This is the opening tag for PHP code. It indicates the start of the PHP script.</p>
</li>
<li><p><code>echo "Hello, World!";</code>: The <code>echo</code> statement is used to output text. In this case, it outputs the string "Hello, World!". The semicolon <code>;</code> is used to terminate the statement.</p>
</li>
<li><p><code>?&gt;</code>: This is the closing tag for PHP code. It indicates the end of the PHP script.</p>
</li>
</ul>
<p>Save this code in a file with a <code>.php</code> extension (for example, <code>hello.php</code>). You can then run this script on a server with PHP installed by accessing it through a web browser.</p>
<h3 id="heading-14-php-html-integration-for-web-dynamism"><strong>1.4 PHP-HTML Integration for Web Dynamism</strong></h3>
<ul>
<li><p>We can write both PHP and HTML code inside a PHP file.</p>
</li>
<li><p>HTML code must be written outside the PHP tags.</p>
</li>
<li><p>And, PHP code must always be written inside the PHP tags.</p>
</li>
<li><p>But we cannot write PHP code inside an HTML file.</p>
</li>
</ul>
<h2 id="heading-chapter-2-php-basics"><strong>Chapter 2: PHP Basics</strong></h2>
<h3 id="heading-21-php-syntax"><strong>2.1 PHP Syntax</strong></h3>
<ul>
<li><p>The most commonly used tags are <code>&lt;?php</code> to open a PHP block and <code>?&gt;</code> to close it.</p>
</li>
<li><p>All PHP statements must end with a semicolon.</p>
</li>
<li><p>All our PHP code must be written inside the PHP tags.</p>
</li>
<li><p>PHP code must be written in a file with extension ".php"</p>
</li>
<li><p>Single-line comments start with <code>//</code>.</p>
</li>
<li><p>Multi-line comments start with <code>/*</code> and end with <code>*/</code>.</p>
</li>
</ul>
<h3 id="heading-22-variables-and-data-types"><strong>2.2 Variables and Data Types</strong></h3>
<ul>
<li><p>Variables start with a dollar ($). <code>$a, $str, $arr</code></p>
</li>
<li><p>A variable name can contain alpha-numeric characters and the underscore, but not any other special characters.</p>
</li>
<li><p>A variable name cannot start with a number.</p>
</li>
<li><p>It must start with either an alphabet or the underscore.</p>
</li>
<li><p>Variable names are case sensitive. Meaning, $a and $A are two different variables.</p>
</li>
<li><p>Common data types in PHP (integers, strings, float, arrays, booleans, object, NULL).</p>
</li>
</ul>
<h3 id="heading-23-operators"><strong>2.3 Operators</strong></h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1703296166328/99634da7-0867-41e0-a6e1-f764a22ce77b.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-24-conditional-statements-if-else-elseif"><strong>2.4</strong> Conditional statements (if, else, elseif)</h3>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
    $num = <span class="hljs-number">10</span>;
    <span class="hljs-keyword">if</span>($num&gt;<span class="hljs-number">0</span>){
        <span class="hljs-keyword">echo</span> <span class="hljs-string">"Positive integer"</span>;
    }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>($num&lt;<span class="hljs-number">0</span>){
        <span class="hljs-keyword">echo</span> <span class="hljs-string">"Negative integer"</span>;
    }<span class="hljs-keyword">else</span>{
        <span class="hljs-keyword">echo</span> <span class="hljs-string">"Zero"</span>;
    }
<span class="hljs-meta">?&gt;</span>
</code></pre>
<h3 id="heading-25-switch-statements"><strong>2.5</strong> Switch statements</h3>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
    <span class="hljs-keyword">switch</span> ($variable) {
        <span class="hljs-keyword">case</span> <span class="hljs-string">'value'</span>:
            <span class="hljs-comment">// code...</span>
            <span class="hljs-keyword">break</span>;

        <span class="hljs-keyword">default</span>:
            <span class="hljs-comment">// code...</span>
            <span class="hljs-keyword">break</span>;
<span class="hljs-meta">?&gt;</span>
</code></pre>
<h3 id="heading-26-looping-structures-for-while-do-while-foreach"><strong>2.6</strong> Looping structures (for, while, do-while, foreach)</h3>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
    <span class="hljs-keyword">while</span>(<span class="hljs-comment">/*--condition--*/</span>){
        <span class="hljs-comment">// code...</span>
    }

    <span class="hljs-keyword">for</span> (<span class="hljs-comment">/*--initialization--*/</span>; <span class="hljs-comment">/*--condition--*/</span>; <span class="hljs-comment">/*--iteration--*/</span>){  
        <span class="hljs-comment">// code...</span>
    }

    <span class="hljs-keyword">do</span>{
        <span class="hljs-comment">// code...</span>
    }<span class="hljs-keyword">while</span>(<span class="hljs-comment">/*--condition--*/</span>);

    <span class="hljs-keyword">foreach</span>($array <span class="hljs-keyword">as</span> $element){
        <span class="hljs-comment">// code... </span>
    }

    <span class="hljs-comment">//Example for foreach...</span>
    $arr= <span class="hljs-keyword">array</span>(<span class="hljs-number">2</span>,<span class="hljs-number">4</span>,<span class="hljs-number">6</span>,<span class="hljs-number">8</span>,<span class="hljs-number">10</span>);
    <span class="hljs-keyword">foreach</span> ($arr <span class="hljs-keyword">as</span> $i){
        <span class="hljs-keyword">echo</span> $i.<span class="hljs-string">" "</span>;

    }
<span class="hljs-meta">?&gt;</span>
</code></pre>
<h3 id="heading-27-arrays"><strong>2.7</strong> Arrays</h3>
<ul>
<li><p>Numeric indexed array</p>
<pre><code class="lang-php">  <span class="hljs-meta">&lt;?php</span>
      $arr = <span class="hljs-keyword">array</span>(<span class="hljs-number">0</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>); 
      <span class="hljs-comment">// $arr = [0,1,2,3,4,5,6,7,8,9] -- is also correct</span>
      <span class="hljs-comment">// index starts from zero -- $arr[0] = 0;</span>
      <span class="hljs-comment">// append value 10 -- $arr[10] = 10;</span>
  <span class="hljs-meta">?&gt;</span>
</code></pre>
</li>
<li><p>Associative indexed array</p>
<pre><code class="lang-php">
  <span class="hljs-meta">&lt;?php</span>
  <span class="hljs-comment">// they have strings or texts as its indices</span>
  <span class="hljs-comment">// it more like a key value pair</span>
      $years = <span class="hljs-keyword">array</span>(<span class="hljs-string">"Bill"</span> =&gt; <span class="hljs-number">1993</span>, <span class="hljs-string">"George"</span> =&gt; <span class="hljs-number">2001</span>, <span class="hljs-string">"Barack"</span> =&gt; <span class="hljs-number">2009</span>);

      <span class="hljs-keyword">foreach</span> ($years <span class="hljs-keyword">as</span> $name =&gt; $year) {
          <span class="hljs-keyword">echo</span> $name . <span class="hljs-string">" was first elected in "</span> . $year . <span class="hljs-string">"\n"</span>;
      } 

      $years[<span class="hljs-string">"Joe"</span>] = <span class="hljs-number">2021</span>; <span class="hljs-comment">// appends a new pair</span>
  <span class="hljs-meta">?&gt;</span>
</code></pre>
</li>
<li><p>Multidimensional array</p>
<pre><code class="lang-php">  <span class="hljs-meta">&lt;?php</span>
      $matrix = [
          [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>],
          [<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>],
          [<span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>]
      ];

      <span class="hljs-keyword">foreach</span>($matrix <span class="hljs-keyword">as</span> $row){
          <span class="hljs-keyword">foreach</span>($row <span class="hljs-keyword">as</span> $element){
              <span class="hljs-keyword">echo</span> $element.<span class="hljs-string">" "</span>;
          }
      }
  <span class="hljs-meta">?&gt;</span>
</code></pre>
</li>
</ul>
<h3 id="heading-27-strings"><strong>2.7</strong> Strings</h3>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-comment">// Escape characther (/) either adds a special meaning to the following character or if the following character is already special, the escape character removes its special meaning and treats it like a normal text character.</span>
<span class="hljs-comment">// double quotes (") - remove special char while printing</span>
    <span class="hljs-keyword">echo</span> <span class="hljs-string">"I am Arun \n I love Dogs"</span>; 
    <span class="hljs-comment">//I am Arun </span>
    <span class="hljs-comment">//I love Dogs</span>

<span class="hljs-comment">// single quotes (') - print entire content within it </span>
    <span class="hljs-keyword">echo</span> <span class="hljs-string">'I am Arun \n I love Dogs'</span>; 
    <span class="hljs-comment">//I am Arun \n I love Dogs</span>

<span class="hljs-comment">//dot (.) operator is used for concatenation</span>
<span class="hljs-meta">?&gt;</span>
</code></pre>
<h2 id="heading-chapter-3-functions-in-php"><strong>Chapter 3: Functions in PHP</strong></h2>
<h3 id="heading-31-introduction-to-functions"><strong>3.1 Introduction to Functions</strong></h3>
<p>In the realm of programming, functions play a pivotal role in organizing and streamlining code. Let's delve into the fundamentals.</p>
<p><strong>Functions:</strong> A function is a self-contained block of code designed to perform a specific task. It encapsulates a sequence of operations, takes inputs (if necessary), and produces an output.</p>
<p><strong>Built-In Functions:</strong> These functions are pre-built and come with the programming language or specific libraries.</p>
<p><strong>User-Defined Functions:</strong> These functions are created by the programmer based on specific requirements.</p>
<h3 id="heading-32-creating-and-using-functions"><strong>3.2 Creating and Using Functions</strong></h3>
<p><strong>User defined functions</strong></p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">addNumbers</span>(<span class="hljs-params">$a=<span class="hljs-number">0</span>, $b=<span class="hljs-number">0</span></span>) </span>{ <span class="hljs-comment">//here a=0 and b=0 are given as default values</span>
    <span class="hljs-keyword">return</span> $a + $b;
}
$result = addNumbers(<span class="hljs-number">5</span>, <span class="hljs-number">7</span>);
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Sum: <span class="hljs-subst">$result</span>"</span>; <span class="hljs-comment">// Output: Sum: 12</span>
<span class="hljs-meta">?&gt;</span>
</code></pre>
<p><strong>Local Scope</strong></p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">localVarExample</span>(<span class="hljs-params"></span>) </span>{
    $localVariable = <span class="hljs-string">"I am local"</span>;
    <span class="hljs-keyword">echo</span> $localVariable;
}
localVarExample(); <span class="hljs-comment">// Output: I am local</span>
<span class="hljs-comment">// echo $localVariable; // This would result in an error</span>
<span class="hljs-meta">?&gt;</span>
</code></pre>
<p><strong>Global Scope</strong></p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
    $globalVariable = <span class="hljs-string">"I am global"</span>;
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">globalVarExample</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">global</span> $globalVariable; <span class="hljs-comment">//accesses this global variable using the global keyword within the function</span>
        <span class="hljs-keyword">echo</span> $globalVariable;
    }
    globalVarExample(); <span class="hljs-comment">// Output: I am global</span>
    <span class="hljs-keyword">echo</span> $globalVariable; <span class="hljs-comment">// Output: I am global</span>
<span class="hljs-meta">?&gt;</span>
</code></pre>
<p><strong>Call by value</strong></p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">incrementValue</span>(<span class="hljs-params">$number</span>) </span>{
        $number++;
        <span class="hljs-keyword">echo</span> $number; <span class="hljs-comment">//6</span>
    }
    $originalNumber = <span class="hljs-number">5</span>;
    incrementValue($originalNumber);
    <span class="hljs-keyword">echo</span> $originalNumber; <span class="hljs-comment">//5</span>
<span class="hljs-meta">?&gt;</span>
</code></pre>
<p><strong>Call by reference</strong></p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">incrementReference</span>(<span class="hljs-params">&amp;$number</span>) </span>{
        $number++;
        <span class="hljs-keyword">echo</span> $number; <span class="hljs-comment">//6</span>
    }
    $originalNumber = <span class="hljs-number">5</span>;
    incrementReference($originalNumber);
    <span class="hljs-keyword">echo</span> $originalNumber; <span class="hljs-comment">//6</span>
<span class="hljs-meta">?&gt;</span>
</code></pre>
<h3 id="heading-33-common-built-in-functions"><strong>3.3 Common Built-in Functions</strong></h3>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
    $str = <span class="hljs-string">'abcdef'</span>;
    <span class="hljs-keyword">echo</span> strlen($str); <span class="hljs-comment">// 6    </span>

    <span class="hljs-comment">// explode function is similar to .split()</span>
    $pizza  = <span class="hljs-string">"piece1 piece2 piece3 piece4 piece5 piece6"</span>;
    $pieces = explode(<span class="hljs-string">" "</span>, $pizza);
    <span class="hljs-keyword">echo</span> $pieces[<span class="hljs-number">0</span>]; <span class="hljs-comment">// piece1</span>
    <span class="hljs-keyword">echo</span> $pieces[<span class="hljs-number">1</span>]; <span class="hljs-comment">// piece2</span>

    <span class="hljs-comment">//implode function is similar to .join()</span>
    $words = <span class="hljs-keyword">array</span>(<span class="hljs-string">"Hello"</span>, <span class="hljs-string">"World"</span>, <span class="hljs-string">"PHP"</span>, <span class="hljs-string">"is"</span>, <span class="hljs-string">"awesome"</span>);
    $result = implode(<span class="hljs-string">" "</span>, $words);
    <span class="hljs-keyword">echo</span> $result; <span class="hljs-comment">// Hello World PHP is awesome</span>

    <span class="hljs-comment">/* Commonly used built-in functions
    String Functions:
        strlen() - Returns the length of a string.
        strpos() - Finds the position of the first occurrence of a substring in a string.
        str_replace() - Replaces all occurrences of a search string with a replacement string.
        strtolower() - Converts a string to lowercase.
        strtoupper() - Converts a string to uppercase.
        trim() - Removes whitespace or other predefined characters from both ends of a string.
        substr() - Returns a part of a string.
    Array Functions:
        count() - Counts the number of elements in an array.
        array_push() - Pushes one or more elements onto the end of an array.
        array_pop() - Pops the element off the end of an array.
        array_merge() - Merges two or more arrays.
        array_keys() - Returns all the keys or a subset of the keys of an array.
        array_values() - Returns all the values of an array.
    Math Functions:
        round() - Rounds a floating-point number.
        rand() - Generates a random number.
        floor() - Rounds fractions down to the nearest whole number.
        ceil() - Rounds fractions up to the nearest whole number.    
    Miscellaneous Functions:
        echo() - Outputs one or more strings.
        print() - Outputs a string.
        isset() - Checks if a variable is set and is not NULL.
        empty() - Checks if a variable is empty.
        htmlspecialchars() - Converts special characters to HTML entities.
    */</span>    
<span class="hljs-meta">?&gt;</span>
</code></pre>
<h2 id="heading-chapter-4-php-and-databases"><strong>Chapter 4: PHP and Databases</strong></h2>
<h3 id="heading-41-introduction-to-databases"><strong>4.1 Introduction to Databases</strong></h3>
<p>In web development, databases play a pivotal role in storing, managing, and retrieving data. They provide a structured and efficient way to organize information for dynamic web applications. Databases are essential for handling user data, content management, and various other aspects of web development.</p>
<h3 id="heading-42-database-related-functions"><strong>4.2 Database related Functions</strong></h3>
<ul>
<li><p><strong>mysqli_connect()</strong></p>
<p>  It is used to establish a connection with MySQL server.</p>
<p>  <code>$conn = mysqli_connect($db_hostname, $db_username, $db_password, $db_name);</code></p>
<p>  It returns false, if there is any error in connecting with server.</p>
</li>
<li><p><strong>mysqli_connect_error()</strong></p>
<p>  It is used to return the last error message from the last call to mysqli_connect().</p>
<p>  <code>echo mysqli_connect_error();</code></p>
</li>
<li><p><strong>mysqli_query()</strong></p>
<p>  It is used to execute an SQL query on the selected database.</p>
<p>  <code>$result = mysqli_query($conn, $sql);</code></p>
<p>  <code>$conn</code> - &gt; reference object</p>
<p>  <code>$sql</code> - &gt; SQL query in string format</p>
</li>
<li><p><strong>mysqli_fetch_assoc()</strong></p>
<p>  It is used to fetch all the data from the reference object that we get from the mysqli_query() function in case of SELECT queries.</p>
<p>  <code>$row = mysqli_fetch_assoc($result);</code></p>
</li>
<li><p><strong>mysqli_error()</strong></p>
<p>  It returns the last error message for the last call to mysqli_query()</p>
<p>  <code>echo mysqli_error($conn);</code></p>
</li>
<li><p><strong>mysqli_close()</strong></p>
<p>  It closes the previously opened connections with the MySQL server.</p>
<p>  <code>mysqli_close($conn);</code></p>
</li>
</ul>
<h3 id="heading-43-super-globals"><strong>4.3 Super Globals</strong></h3>
<p>Superglobals in PHP are predefined associative global arrays that are accessible from any part of the script, including functions, classes, and files. These arrays contain various types of data, such as form input, session information, server details, and more. Here are some commonly used superglobals:</p>
<ol>
<li><p><code>$_GET</code>:</p>
<ul>
<li>Contains data sent to the script via URL parameters using the HTTP GET method.</li>
</ul>
</li>
<li><p><code>$_POST</code>:</p>
<ul>
<li><p>Contains data sent to the script via the HTTP POST method, often used with HTML forms.</p>
</li>
<li><p>POST method is preferred over GET method due to safety concerns.</p>
</li>
</ul>
</li>
<li><p><code>$_REQUEST</code>:</p>
<ul>
<li>Contains data from both <code>$_GET</code>, <code>$_POST</code>, and <code>$_COOKIE</code>. The values are determined by the request method.</li>
</ul>
</li>
<li><p><code>$_SESSION</code>:</p>
<ul>
<li>Contains session variables that are accessible across multiple pages during a user's session.</li>
</ul>
</li>
<li><p><code>$_COOKIE</code>:</p>
<ul>
<li>Contains values sent to the script via HTTP cookies.</li>
</ul>
</li>
<li><p><code>$_SERVER</code>:</p>
<ul>
<li>Contains information about the server environment and the execution environment of the current script.</li>
</ul>
</li>
<li><p><code>$_FILES</code>:</p>
<ul>
<li>Contains information about file uploads submitted through HTML forms.</li>
</ul>
</li>
<li><p><code>$_ENV</code>:</p>
<ul>
<li>Contains environment variables.</li>
</ul>
</li>
<li><p><code>$_GLOBALS</code>:</p>
<ul>
<li>Contains all global variables in the global scope.</li>
</ul>
</li>
</ol>
<p>These superglobals provide a convenient way to access and manipulate various types of data commonly used in web development. It's important to note that the data in these superglobals should be validated and sanitized before using it in your scripts to prevent security vulnerabilities such as injection attacks.</p>
<p>Here's a simple example using <code>$_GET</code>:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-comment">// Assuming the URL is: http://example.com/index.php?name=John</span>
$name = $_GET[<span class="hljs-string">'name'</span>];
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Hello, <span class="hljs-subst">$name</span>!"</span>; <span class="hljs-comment">// Output: Hello, John!</span>
<span class="hljs-meta">?&gt;</span>
</code></pre>
<p>In this example, <code>$_GET</code> is used to retrieve the value of the 'name' parameter from the URL.</p>
<h2 id="heading-chapter-5-advanced-php-concepts-to-be-continued"><strong>Chapter 5: Advanced PHP Concepts (to be continued...)</strong></h2>
<h3 id="heading-51-registration-identification-authentication"><strong>5.1 Registration, Identification, Authentication</strong></h3>
<h3 id="heading-52-cookies"><strong>5.2 Cookies</strong></h3>
<h3 id="heading-53-sessions"><strong>5.3 Sessions</strong></h3>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>In conclusion, our PHP journey delved into fundamental web development aspects, guiding both beginners and experts through PHP's versatile landscape. From syntax basics to dynamic PHP-HTML integration, functions, and seamless MySQL interaction, this guide laid a strong foundation. Emphasizing the significance of superglobals and validation, our journey anticipates exploring advanced PHP concepts like registration, authentication, cookies, and sessions. Stay tuned for insights into PHP's capabilities in upcoming chapters.</p>
<p>In closing, I'd like to express my gratitude to all our readers. Thank you for joining us on this PHP exploration. Your curiosity and enthusiasm drive us to continue sharing insights into the dynamic world of web development. Stay engaged, and we look forward to continuing this journey together.</p>
]]></content:encoded></item><item><title><![CDATA[Day 7: Mastering DBMS]]></title><description><![CDATA[Introduction
In the ever-evolving world of technology, effective data management is crucial for businesses and organizations to thrive. Database Management Systems (DBMS) play a pivotal role in organizing and managing vast amounts of data efficiently...]]></description><link>https://arunkumar0203.hashnode.dev/day-7-mastering-dbms</link><guid isPermaLink="true">https://arunkumar0203.hashnode.dev/day-7-mastering-dbms</guid><category><![CDATA[SQL]]></category><category><![CDATA[#SQLtutorial ]]></category><category><![CDATA[SQL Server]]></category><category><![CDATA[MySQL]]></category><category><![CDATA[DBMS]]></category><category><![CDATA[Databases]]></category><category><![CDATA[databasemanagement]]></category><category><![CDATA[database design]]></category><dc:creator><![CDATA[Arun Kumar]]></dc:creator><pubDate>Fri, 22 Dec 2023 12:30:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1703234930362/9aab78d0-296f-4bd9-a9b9-58e36aff378d.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>In the ever-evolving world of technology, effective data management is crucial for businesses and organizations to thrive. Database Management Systems (DBMS) play a pivotal role in organizing and managing vast amounts of data efficiently. In this tutorial, we will delve into the fundamentals of DBMS, with a focus on MySQL, one of the most popular relational database management systems, and the Structured Query Language (SQL), the standard language for interacting with relational databases.</p>
<h2 id="heading-what-is-dbms">What is DBMS?</h2>
<p>A Database Management System (DBMS) is a software suite that facilitates the creation, maintenance, and manipulation of databases. It provides an interface for users and applications to interact with the database without dealing with the complexities of data storage and retrieval. DBMS ensures data integrity, security, and efficient management of information.</p>
<h2 id="heading-why-mysql">Why MySQL?</h2>
<p>MySQL is an open-source relational database management system that has gained widespread popularity for its reliability, performance, and ease of use. It is suitable for a variety of applications, ranging from small-scale projects to large enterprise-level systems. MySQL supports SQL, making it a powerful choice for developers and database administrators.</p>
<h2 id="heading-distinguish-between-sql-and-mysql">Distinguish between SQL and MySQL</h2>
<p>SQL serves as the language for interacting with databases, offering a common syntax across various systems (SQL is case insensitive and end with ';'). On the other hand, MySQL is one of several database systems that implement SQL. Think of SQL as the language and MySQL as a fluent speaker of that language.</p>
<h2 id="heading-understanding-basic-terminologies">Understanding Basic Terminologies</h2>
<p><img src="https://miro.medium.com/max/736/0*kBYg1f1lVSFE5cY6.PNG" alt="Visualizing SQL: A Beginners Guide to Relational Databases | by Oliver ..." /></p>
<p>Database: A Database is where all the data (table) is stored.</p>
<p>Table: A Table is an arrangement of data in rows and columns.</p>
<p>Attribute: Attribute specify the kind of information a table stores.</p>
<p>Record/Data value: A record represent an instance of the entity the table represens.</p>
<h2 id="heading-sql-commands"><strong>SQL Commands</strong></h2>
<p>These <strong>SQL</strong> commands are mainly categorized into five categories:</p>
<ol>
<li><p>DDL – Data Definition Language</p>
</li>
<li><p>DQL – Data Query Language</p>
</li>
<li><p>DML – Data Manipulation Language</p>
</li>
<li><p>DCL – Data Control Language</p>
</li>
<li><p>TCL – Transaction Control Language</p>
</li>
</ol>
<p><img src="https://media.geeksforgeeks.org/wp-content/uploads/20210920153429/new.png" alt="Lightbox" /></p>
<h2 id="heading-operations-on-database"><strong>Operations on Database</strong></h2>
<h3 id="heading-display-all-the-databases-present">Display all the databases present</h3>
<p>SQL query to show all the database in the system.</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SHOW</span> <span class="hljs-keyword">DATABASES</span>;
</code></pre>
<h3 id="heading-creating-a-database">Creating a database</h3>
<p>SQL query to create a database named "college".</p>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">DATABASE</span> college;
</code></pre>
<h3 id="heading-selecting-a-database">Selecting a database</h3>
<p>SQL query to select the college database to perform operations on it.</p>
<pre><code class="lang-sql"><span class="hljs-keyword">USE</span> college;
</code></pre>
<h3 id="heading-check-which-database-is-selected">Check which database is selected</h3>
<p>SELECT DATABASE(); is the query to check which database is selected.</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">DATABASE</span>();
</code></pre>
<h3 id="heading-delete-a-database">Delete a database</h3>
<p>DROP DATABASE &lt;database_name&gt;; is the query to delete a database.</p>
<pre><code class="lang-sql"><span class="hljs-keyword">DROP</span> <span class="hljs-keyword">DATABASE</span> &lt;college&gt;;
</code></pre>
<h2 id="heading-operations-of-table"><strong>Operations of Table</strong></h2>
<h3 id="heading-display-all-the-tables">Display all the Tables</h3>
<p>SHOW TABLES; (note the plural form) is the query to display all the tables present in the selected database.</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SHOW</span> <span class="hljs-keyword">TABLES</span>;
</code></pre>
<h3 id="heading-creating-a-table">Creating a table</h3>
<p>Creating a table need concern is three things</p>
<ul>
<li><p>Datatype - what type of data is going to be present in the column ( int, float, varchar, etc.).</p>
</li>
<li><p>Constraint - size of varchar, AUTO_INCREMENT, not null, etc.</p>
</li>
<li><p>Default value - It is applied in case the user doesn't give any input.</p>
</li>
</ul>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> students (
    s_no <span class="hljs-built_in">INT</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> AUTO_INCREMENT,
    <span class="hljs-keyword">name</span> <span class="hljs-built_in">VARCHAR</span>(<span class="hljs-number">255</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span>,
    registration_number <span class="hljs-built_in">VARCHAR</span>(<span class="hljs-number">255</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span>,
    gender <span class="hljs-built_in">VARCHAR</span>(<span class="hljs-number">255</span>),
    department <span class="hljs-built_in">VARCHAR</span>(<span class="hljs-number">255</span>),
    no_of_compartment <span class="hljs-built_in">INT</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-number">0</span>,
    PRIMARY <span class="hljs-keyword">KEY</span>(s_no)
);
</code></pre>
<div class="hn-table">
<table>
<thead>
<tr>
<td>s_no</td><td>name</td><td>registration_number</td><td>gender</td><td>department</td><td>no_of_compartment</td></tr>
</thead>
<tbody>
<tr>
<td></td><td></td><td></td><td></td><td></td></tr>
</tbody>
</table>
</div><p><strong>Primary Key (PK):</strong></p>
<ul>
<li><p>A primary key is a column or a set of columns that uniquely identifies each record in a table.</p>
</li>
<li><p>It must have a unique value for each record and cannot contain NULL values.</p>
</li>
</ul>
<h3 id="heading-view-description-of-table">View Description of table</h3>
<p>This query shows the datatypes, constraints and default values of every attribute of a table.</p>
<pre><code class="lang-sql">DESC students;
</code></pre>
<h3 id="heading-altering-a-table">Altering a Table</h3>
<ul>
<li><p>Adding a new attribute - add a column to the existing table</p>
<p>  ALTER TABLE tableName ADD columnName columnDefinition;</p>
<pre><code class="lang-sql">  <span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> students <span class="hljs-keyword">ADD</span> semester <span class="hljs-built_in">varchar</span>(<span class="hljs-number">255</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-number">1</span>;
</code></pre>
</li>
<li><p>Deleting an existing attribute - drop a column from the existing table</p>
<p>  ALTER TABLE tableName DROP columnName;</p>
<pre><code class="lang-sql">  <span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> students <span class="hljs-keyword">DROP</span> semester;
</code></pre>
</li>
<li><p>Modifying an existing attribute - changing the constraints and datatypes of a pre-existing column</p>
<pre><code class="lang-sql">  <span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> students <span class="hljs-keyword">MODIFY</span> no_of_compartment <span class="hljs-built_in">INT</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-number">1</span>;
</code></pre>
</li>
<li><p>Changing the name of the attribute - rename a column</p>
<p>  ALTER TABLE table_name CHANGE old_attribute_name new_name constraints;</p>
<pre><code class="lang-sql">  <span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> students <span class="hljs-keyword">CHANGE</span> no_of_compartment compartment <span class="hljs-built_in">INT</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-number">1</span>;
</code></pre>
</li>
<li><p>Renaming the table</p>
<pre><code class="lang-sql">  <span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> students <span class="hljs-keyword">RENAME</span> <span class="hljs-keyword">TO</span> students_college;
</code></pre>
</li>
</ul>
<h3 id="heading-linking-table">Linking table</h3>
<p><strong>Foreign Key (FK):</strong></p>
<ul>
<li><p>A foreign key is a column or a set of columns in a table that refers to the primary key of another table.</p>
</li>
<li><p>It establishes a link between two tables, creating a relationship.</p>
</li>
<li><p>Helps maintain referential integrity between tables.</p>
</li>
<li><p>Defined using the <code>FOREIGN KEY</code> constraint.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1703243926379/7dcee244-dc61-4b3f-b6b3-ccf797b074d8.png" alt class="image--center mx-auto" /></p>
<p>Here while creating companies table, <code>FOREIGN KEY(company_id) REFERENCES companies(id)</code> is the query for linking company_id attribute of students table to primary key of companies table, i.e. id.</p>
<p>A Foreign Key is declared to break down complex tables into multiple smaller tables because complexity leads to a greater scope for mistakes.</p>
<h2 id="heading-operations-on-records"><strong>Operations on Records</strong></h2>
<h3 id="heading-inserting-data">Inserting data</h3>
<p>INSERT INTO table_name (attributes...) VALUES (values_corresponding_to_attribute..);</p>
<pre><code class="lang-sql"><span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> students (<span class="hljs-keyword">name</span>, registration_number, gender) <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">"ARUN"</span>, <span class="hljs-number">312422106016</span>, <span class="hljs-string">"Male"</span>);
</code></pre>
<p>INSERT INTO table_name VALUES (values_in_perfect_order_of_table);</p>
<pre><code class="lang-sql"><span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> students <span class="hljs-keyword">VALUES</span> (<span class="hljs-number">2</span>, <span class="hljs-string">"KEN"</span>, <span class="hljs-number">312422106000</span>, <span class="hljs-string">"MALE"</span>, <span class="hljs-string">"ECE"</span>, <span class="hljs-number">2</span>);
</code></pre>
<h3 id="heading-fetching-data">Fetching data</h3>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> students; <span class="hljs-comment">--It displays entire table</span>
<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">name</span>, gender <span class="hljs-keyword">FROM</span> students; <span class="hljs-comment">--It displays only specified attributes</span>
<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> students <span class="hljs-keyword">WHERE</span> compartment&gt;<span class="hljs-number">0</span>; <span class="hljs-comment">-- It display the records which satisfies the conditional only</span>
<span class="hljs-comment">-- WHERE clause can be combbined by AND, OR, =, !=, &gt;, &lt;, &gt;=,&lt;= operators</span>
<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> students <span class="hljs-keyword">order</span> <span class="hljs-keyword">by</span> <span class="hljs-keyword">name</span> <span class="hljs-keyword">ASC</span>; <span class="hljs-comment">--It displays data in ordered way asc or desc</span>
</code></pre>
<h3 id="heading-updating-data">Updating data</h3>
<p>UPDATE table_name SET attribute_name=value WHERE primary_key=value;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">UPDATE</span> students <span class="hljs-keyword">SET</span> 
registration_number = <span class="hljs-number">312422106001</span>,
compartment = <span class="hljs-number">0</span>
<span class="hljs-keyword">WHERE</span> s_no = <span class="hljs-number">2</span>;
</code></pre>
<h3 id="heading-deleting-data">Deleting data</h3>
<p>DELETE FROM table_name WHERE primary_key=value;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">DELETE</span> <span class="hljs-keyword">FROM</span> students <span class="hljs-keyword">WHERE</span> s_no=<span class="hljs-number">2</span>; <span class="hljs-comment">--Absence of where clause will delete entire records</span>
</code></pre>
<h2 id="heading-database-relationships"><strong>Database Relationships</strong></h2>
<p>It means association between two tables. It is of three types,</p>
<ul>
<li><p>One to many</p>
<p>  These types of relationships can be resolved using a foreign key. Foreign keys must be able to uniquely identify a row from the other table. Hence, we have a foreign key on that table that can have multiple records referring to a single record of the other table, which needs to be uniquely identified.</p>
</li>
<li><p>One to One</p>
<p>  In these cases, the tables can be merged into one.</p>
</li>
<li><p>Many to many</p>
<p>  Resolving these relationships require formation of an intermediate new table.</p>
</li>
</ul>
<h2 id="heading-join-queries"><strong>JOIN Queries</strong></h2>
<p>It is used to merge multiple SQL queries, it works by combining two tables into a single virtual table.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1703245648667/e46ef680-b0ac-4d4e-82ce-d968c39cd6c5.png" alt class="image--center mx-auto" /></p>
<p>In MySQL there are three types of join queries,</p>
<h3 id="heading-inner-join">INNER JOIN</h3>
<ul>
<li><p>Inner join query shows the records only if associated values are present on both tables</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1703246514324/e4f8a403-d44e-4a8f-abb9-42cc638b5ca3.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-sql">  <span class="hljs-keyword">SELECT</span>
      *
  <span class="hljs-keyword">FROM</span>
      students
  <span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span>
      companies
  <span class="hljs-keyword">ON</span>
      students.company_id=companies.id;
  <span class="hljs-comment">/* It displays records associated with values in both tables */</span>
</code></pre>
</li>
</ul>
<h3 id="heading-left-join">LEFT JOIN</h3>
<ul>
<li><p>It displays all the data from left table irrespective of its association with the right table. But it displays data in right table only if has one association with left table.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1703247212766/e24a6e41-50e1-41a7-b2d8-55031b0db833.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-sql">  <span class="hljs-keyword">SELECT</span>
      *
  <span class="hljs-keyword">FROM</span>
      students
  <span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span>
      companies
  <span class="hljs-keyword">ON</span>
      students.company_id=companies.id; 
  <span class="hljs-comment">/* It displays all records in left table, but right table require association with left table in order to be displayed*/</span>
</code></pre>
</li>
</ul>
<h3 id="heading-right-join">RIGHT JOIN</h3>
<ul>
<li><p>It displays all the data from right table irrespective of its association with the left table. But it displays data in left table only if has one association with right table.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1703247134219/f6159196-ef1d-4563-b67c-4f4d7ddeb352.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-sql">  <span class="hljs-keyword">SELECT</span>
      *
  <span class="hljs-keyword">FROM</span>
      students
  <span class="hljs-keyword">RIGHT</span> <span class="hljs-keyword">JOIN</span>
      companies
  <span class="hljs-keyword">ON</span>
      students.company_id=companies.id;
  <span class="hljs-comment">/* It displays all records in right table, but left table require association with right table in order to be displayed */</span>
</code></pre>
</li>
</ul>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>This tutorial covered the fundamentals of Database Management Systems using MySQL and SQL. We explored creating databases, tables, and performing basic to advanced data manipulation operations. Understanding these concepts is crucial for anyone working with databases, and MySQL, with its robust features, serves as an excellent platform for database management.</p>
<p>Remember, this is just the beginning. The world of databases and SQL is vast, and continuous learning is key to mastering these essential skills in the realm of software development and data management.</p>
]]></content:encoded></item><item><title><![CDATA[Day 6: Binary Search Algorithm]]></title><description><![CDATA[Binary Search Overview

Binary search is a fast search algorithm that works on sorted arrays. It repeatedly divides the search interval in half, reducing the search space by half with each iteration.

It has a time complexity of O(log n) where "n" is...]]></description><link>https://arunkumar0203.hashnode.dev/day-6-binary-search-algorithm</link><guid isPermaLink="true">https://arunkumar0203.hashnode.dev/day-6-binary-search-algorithm</guid><category><![CDATA[Binary Search Algorithm]]></category><category><![CDATA[Searching Algorithms]]></category><category><![CDATA[array]]></category><dc:creator><![CDATA[Arun Kumar]]></dc:creator><pubDate>Tue, 26 Sep 2023 14:29:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/GnY_mW1Q6Xc/upload/fd673c4c08e01066b6b9401609feeadf.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<hr />
<h2 id="heading-binary-search-overview">Binary Search Overview</h2>
<ul>
<li><p><strong>Binary</strong> search is a fast search algorithm that works on sorted arrays. It repeatedly divides the search interval in half, reducing the search space by half with each iteration.</p>
</li>
<li><p>It has a time complexity of O(log n) where "n" is the number of elements in the array. This makes it much more efficient than linear search for large data sets.</p>
</li>
</ul>
<h2 id="heading-java-code-for-binary-search">Java Code for Binary Search</h2>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">BinarySearch</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> <span class="hljs-title">binarySearch</span><span class="hljs-params">(<span class="hljs-keyword">int</span>[] arr, <span class="hljs-keyword">int</span> target)</span> </span>{
        <span class="hljs-keyword">int</span> start = <span class="hljs-number">0</span>;
        <span class="hljs-keyword">int</span> end = arr.length - <span class="hljs-number">1</span>;

        <span class="hljs-keyword">while</span> (start &lt;= end) {
            <span class="hljs-keyword">int</span> mid = start + (end - start) / <span class="hljs-number">2</span>;

            <span class="hljs-keyword">if</span> (arr[mid] == target) {
                <span class="hljs-keyword">return</span> mid; <span class="hljs-comment">// Return the index where the target is found</span>
            } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (arr[mid] &lt; target) {
                start = mid + <span class="hljs-number">1</span>;
            } <span class="hljs-keyword">else</span> {
                end = mid - <span class="hljs-number">1</span>;
            }
        }

        <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>; <span class="hljs-comment">// Return -1 if the target is not found</span>
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        <span class="hljs-keyword">int</span>[] arr = { <span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">6</span>, <span class="hljs-number">8</span>, <span class="hljs-number">10</span>, <span class="hljs-number">12</span>, <span class="hljs-number">14</span> };
        <span class="hljs-keyword">int</span> target = <span class="hljs-number">8</span>;
        <span class="hljs-keyword">int</span> result = binarySearch(arr, target);
        <span class="hljs-keyword">if</span> (result != -<span class="hljs-number">1</span>) {
            System.out.println(<span class="hljs-string">"Element found at index "</span> + result);
        } <span class="hljs-keyword">else</span> {
            System.out.println(<span class="hljs-string">"Element not found in the array."</span>);
        }
    }
}
</code></pre>
<h2 id="heading-binary-search-algorithm"><strong>Binary Search Algorithm</strong></h2>
<p>Binary search works by repeatedly dividing the search range in half until the desired element is found or the search range becomes empty.</p>
<ol>
<li><p><strong>Start with a sorted array</strong>: Binary search requires that the input array is sorted in ascending order.</p>
</li>
<li><p><strong>Initialize variables</strong>:</p>
<ul>
<li><p><code>left</code> - The index of the leftmost element in the search range (initially 0).</p>
</li>
<li><p><code>right</code> - The index of the rightmost element in the search range (initially the length of the array minus 1).</p>
</li>
</ul>
</li>
<li><p><strong>Repeat until the search range is empty</strong>: a. Calculate the middle index as <code>mid = (left + right) / 2</code>. b. Compare the element at the middle index with the target element. c. If the middle element is equal to the target, return its index (search successful). d. If the middle element is less than the target, update <code>left</code> to <code>mid + 1</code>. e. If the middle element is greater than the target, update <code>right</code> to <code>mid - 1</code>.</p>
</li>
<li><p>If the loop exits without finding the target, return -1 to indicate that the element is not in the array.</p>
</li>
</ol>
<h2 id="heading-finding-mid-term">Finding Mid-term</h2>
<ul>
<li><p>The below-mentioned two expressions are used to calculate the middle index of a range, typically for binary search or similar algorithms. However, the first expression:</p>
<pre><code class="lang-java">  <span class="hljs-keyword">int</span> mid = left + (right - left) / <span class="hljs-number">2</span>;
</code></pre>
</li>
<li><p>is preferred over the second expression:</p>
</li>
<li><pre><code class="lang-java">  <span class="hljs-keyword">int</span> mid = (left + right) / <span class="hljs-number">2</span>;
</code></pre>
</li>
<li><p>The reason for this preference is to avoid potential integer overflow issues. The first expression ensures that the subtraction <code>right - left</code> is performed before dividing by 2. This is important because if <code>left</code> and <code>right</code> are very large integers, directly adding them together could result in an integer overflow, which may lead to incorrect results or undefined behavior.</p>
</li>
<li><p>By subtracting <code>left</code> from <code>right</code> first and then dividing by 2, you avoid this potential overflow problem and ensure the correct middle index is calculated, even for large values of <code>left</code> and <code>right</code>. Therefore, the first expression is a safer and more robust way to calculate the middle index in practice.</p>
</li>
</ul>
<h2 id="heading-order-agnostic-binary-search">Order-Agnostic Binary-Search</h2>
<ul>
<li><p>The above code is good if we know that the array is sorted in ascending order, but what if we don't know whether it is sorted in ascending or descending order?</p>
</li>
<li><p>That's where Order-agnostic binary search comes into play.</p>
</li>
</ul>
<h2 id="heading-java-code-for-order-agnostic-binary-search">Java Code for Order-Agnostic Binary Search</h2>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Main</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> <span class="hljs-title">orderAgnosticBS</span><span class="hljs-params">(<span class="hljs-keyword">int</span>[] arr, <span class="hljs-keyword">int</span> target)</span> </span>{
        <span class="hljs-keyword">int</span> start = <span class="hljs-number">0</span>;
        <span class="hljs-keyword">int</span> end = arr.length - <span class="hljs-number">1</span>;

        <span class="hljs-comment">// Determine the order of the array (ascending or descending)</span>
        <span class="hljs-keyword">boolean</span> isAscending = arr[start] &lt; arr[end];

        <span class="hljs-keyword">while</span> (start &lt;= end) {
            <span class="hljs-keyword">int</span> mid = start + (end - start) / <span class="hljs-number">2</span>;

            <span class="hljs-keyword">if</span> (arr[mid] == target) {
                <span class="hljs-keyword">return</span> mid; <span class="hljs-comment">// Return the index where the target is found</span>
            }

            <span class="hljs-keyword">if</span> (isAscending) {
                <span class="hljs-keyword">if</span> (arr[mid] &lt; target) {
                    start = mid + <span class="hljs-number">1</span>;
                } <span class="hljs-keyword">else</span> {
                    end = mid - <span class="hljs-number">1</span>;
                }
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">if</span> (arr[mid] &gt; target) {
                    start = mid + <span class="hljs-number">1</span>;
                } <span class="hljs-keyword">else</span> {
                    end = mid - <span class="hljs-number">1</span>;
                }
            }
        }

        <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>; <span class="hljs-comment">// Return -1 if the target is not found</span>
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        <span class="hljs-keyword">int</span>[] ascendingArr = { <span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">6</span>, <span class="hljs-number">8</span>, <span class="hljs-number">10</span>, <span class="hljs-number">12</span>, <span class="hljs-number">14</span> };
        <span class="hljs-keyword">int</span>[] descendingArr = { <span class="hljs-number">14</span>, <span class="hljs-number">12</span>, <span class="hljs-number">10</span>, <span class="hljs-number">8</span>, <span class="hljs-number">6</span>, <span class="hljs-number">4</span>, <span class="hljs-number">2</span> };

        <span class="hljs-keyword">int</span> target = <span class="hljs-number">8</span>;
        <span class="hljs-keyword">int</span> ascendingResult = orderAgnosticBS(ascendingArr, target);
        <span class="hljs-keyword">int</span> descendingResult = orderAgnosticBS(descendingArr, target);

        <span class="hljs-keyword">if</span> (ascendingResult != -<span class="hljs-number">1</span>) {
            System.out.println(<span class="hljs-string">"Element found at index "</span> + ascendingResult + <span class="hljs-string">" in the ascending array."</span>);
        } <span class="hljs-keyword">else</span> {
            System.out.println(<span class="hljs-string">"Element not found in the ascending array."</span>);
        }

        <span class="hljs-keyword">if</span> (descendingResult != -<span class="hljs-number">1</span>) {
            System.out.println(<span class="hljs-string">"Element found at index "</span> + descendingResult + <span class="hljs-string">" in the descending array."</span>);
        } <span class="hljs-keyword">else</span> {
            System.out.println(<span class="hljs-string">"Element not found in the descending array."</span>);
        }
    }
}
</code></pre>
<h2 id="heading-use-cases">Use Cases</h2>
<ul>
<li><p>Binary search is highly efficient and suitable for large sorted data sets.</p>
</li>
<li><p>It is commonly used in situations where you need to quickly find an element in a sorted list, such as searching in a sorted array or a dictionary.</p>
</li>
</ul>
<h2 id="heading-performance">Performance</h2>
<ul>
<li><p>Binary search has a time complexity of O(log n), making it very efficient for large data sets.</p>
</li>
<li><p>It divides the search space in half with each iteration, leading to fast search times.</p>
</li>
<li><p>For you to understand how efficient it is, let's take an example array of 1 million elements. In the worst-case scenario in a linear search algorithm, 1 million comparisons are made. However, in binary search algorithms, only 20 comparisons are made. I hope now you can understand the difference.</p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<ul>
<li><p>Binary search is a powerful and efficient algorithm for searching in sorted data sets.</p>
</li>
<li><p>It outperforms linear search for large data sets but requires that the data be sorted beforehand.</p>
</li>
<li><p>When you need to find elements in a sorted list, binary search is a top choice.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Day 5: Linear Search Algorithm + LeetCode]]></title><description><![CDATA[Certainly! Here are some notes on implementing a linear search algorithm in Java:
Linear Search Overview

Linear search is a basic searching algorithm that sequentially checks each element in a list or array until a match is found.

It's straightforw...]]></description><link>https://arunkumar0203.hashnode.dev/day-5-linear-search-algorithm-leetcode</link><guid isPermaLink="true">https://arunkumar0203.hashnode.dev/day-5-linear-search-algorithm-leetcode</guid><category><![CDATA[Java]]></category><category><![CDATA[array]]></category><category><![CDATA[linearsearch]]></category><category><![CDATA[Searching Algorithms]]></category><dc:creator><![CDATA[Arun Kumar]]></dc:creator><pubDate>Mon, 25 Sep 2023 16:53:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/afW1hht0NSs/upload/66e44098857dab04fd72c4831c5ff8d2.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<hr />
<p>Certainly! Here are some notes on implementing a linear search algorithm in Java:</p>
<h3 id="heading-linear-search-overview"><strong>Linear Search Overview</strong></h3>
<ul>
<li><p>Linear search is a basic searching algorithm that sequentially checks each element in a list or array until a match is found.</p>
</li>
<li><p>It's straightforward but not the most efficient for large data sets. It has a time complexity of O(n) where "n" is the number of elements in the list.</p>
</li>
</ul>
<h3 id="heading-java-code-for-linear-search-in-1d-array"><strong>Java Code for Linear Search in 1D Array</strong></h3>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">LinearSearch</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> <span class="hljs-title">linearSearch</span><span class="hljs-params">(<span class="hljs-keyword">int</span>[] arr, <span class="hljs-keyword">int</span> target)</span> </span>{
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; arr.length; i++) {
            <span class="hljs-keyword">if</span> (arr[i] == target) {
                <span class="hljs-keyword">return</span> i; <span class="hljs-comment">// Return the index where the target is found</span>
            }
        }
        <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>; <span class="hljs-comment">// Return -1 if the target is not found</span>
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        <span class="hljs-keyword">int</span>[] arr = { <span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">6</span>, <span class="hljs-number">8</span>, <span class="hljs-number">10</span>, <span class="hljs-number">12</span>, <span class="hljs-number">14</span> };
        <span class="hljs-keyword">int</span> target = <span class="hljs-number">8</span>;
        <span class="hljs-keyword">int</span> result = linearSearch(arr, target);
        <span class="hljs-keyword">if</span> (result != -<span class="hljs-number">1</span>) {
            System.out.println(<span class="hljs-string">"Element found at index "</span> + result);
        } <span class="hljs-keyword">else</span> {
            System.out.println(<span class="hljs-string">"Element not found in the array."</span>);
        }
    }
}
</code></pre>
<h3 id="heading-java-code-for-linear-search-in-2d-array"><strong>Java Code for Linear Search in 2D Array</strong></h3>
<pre><code class="lang-java"><span class="hljs-keyword">import</span> java.util.*;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">LinearSearch2D</span> </span>{
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span>[] linearSearch2D(<span class="hljs-keyword">int</span>[][] arr, <span class="hljs-keyword">int</span> target) {
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> row = <span class="hljs-number">0</span>; row &lt; arr.length; row++) {
            <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> col=<span class="hljs-number">0</span>; col&lt;arr[row].length; col++){
                <span class="hljs-keyword">if</span> (arr[row][col] == target) {
                    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-keyword">int</span>[]{row,col}; <span class="hljs-comment">// Return the index array where the target is found</span>
                }
            }
        }
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-keyword">int</span>[]{-<span class="hljs-number">1</span>}; <span class="hljs-comment">// Return -1 if the target is not found</span>
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        <span class="hljs-keyword">int</span>[][] arr = { 
            {<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>},
            {<span class="hljs-number">4</span>,<span class="hljs-number">5</span>},
            {<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>}
        };
        <span class="hljs-keyword">int</span> target = <span class="hljs-number">8</span>;
        <span class="hljs-keyword">int</span>[] result = linearSearch2D(arr, target);
        <span class="hljs-keyword">if</span> (result[<span class="hljs-number">0</span>] != -<span class="hljs-number">1</span>) {
            System.out.println(<span class="hljs-string">"Element found at index "</span> + Arrays.toString(result));
        } <span class="hljs-keyword">else</span> {
            System.out.println(<span class="hljs-string">"Element not found in the array."</span>);
        }
    }
}
</code></pre>
<h3 id="heading-leetcode-time-1295-find-numbers-with-even-number-of-digitshttpsleetcodecomproblemsfind-numbers-with-even-number-of-digitsdescription"><strong>LeetCode time (</strong><a target="_blank" href="https://leetcode.com/problems/find-numbers-with-even-number-of-digits/description/"><strong>1295. Find Numbers with Even Number of Digits</strong></a><strong>)</strong></h3>
<ul>
<li><p>Given an array <code>nums</code> of integers, return how many of them contain an <strong>even number</strong> of digits.</p>
</li>
<li><p><strong>Example 1:</strong></p>
<pre><code class="lang-java">  Input: nums = [<span class="hljs-number">12</span>,<span class="hljs-number">345</span>,<span class="hljs-number">2</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7896</span>]
  Output: <span class="hljs-number">2</span>
  Explanation: 
  <span class="hljs-number">12</span> contains <span class="hljs-number">2</span> digits (even number of digits). 
  <span class="hljs-number">345</span> contains <span class="hljs-number">3</span> digits (odd number of digits). 
  <span class="hljs-number">2</span> contains <span class="hljs-number">1</span> digit (odd number of digits). 
  <span class="hljs-number">6</span> contains <span class="hljs-number">1</span> digit (odd number of digits). 
  <span class="hljs-number">7896</span> contains <span class="hljs-number">4</span> digits (even number of digits). 
  Therefore only <span class="hljs-number">12</span> and <span class="hljs-number">7896</span> contain an even number of digits.
</code></pre>
<p>  <strong>Example 2:</strong></p>
<pre><code class="lang-java">  Input: nums = [<span class="hljs-number">555</span>,<span class="hljs-number">901</span>,<span class="hljs-number">482</span>,<span class="hljs-number">1771</span>]
  Output: <span class="hljs-number">1</span> 
  Explanation: 
  Only <span class="hljs-number">1771</span> contains an even number of digits.
</code></pre>
</li>
<li><p>I have attached my solution code below, ...</p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Solution</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">findNumbers</span><span class="hljs-params">(<span class="hljs-keyword">int</span>[] nums)</span> </span>{
       <span class="hljs-keyword">int</span> ev = <span class="hljs-number">0</span>;
       <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> num: nums){
           <span class="hljs-keyword">if</span> (evdigi(num)%<span class="hljs-number">2</span>==<span class="hljs-number">0</span>){
               ev++;
           }
       }
       <span class="hljs-keyword">return</span> ev; 
    }
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">evdigi</span><span class="hljs-params">(<span class="hljs-keyword">int</span> n)</span> </span>{
        <span class="hljs-keyword">int</span> digi = <span class="hljs-number">0</span>;
        <span class="hljs-keyword">while</span>(n&gt;<span class="hljs-number">0</span>) {
            digi++;
            n/=<span class="hljs-number">10</span>;
        }
        <span class="hljs-keyword">return</span> digi;
    }
}
</code></pre>
<h3 id="heading-leetcode-time-1672-richest-customer-wealthhttpsleetcodecomproblemsrichest-customer-wealth"><strong>LeetCode time (</strong><a target="_blank" href="https://leetcode.com/problems/richest-customer-wealth/"><strong>1672. Richest Customer Wealth</strong></a><strong>)</strong></h3>
<ul>
<li><p>You are given an <code>m x n</code> integer grid <code>accounts</code> where <code>accounts[i][j]</code> is the amount of money the <code>i​​​​​&lt;sup&gt;​​​​​​th&lt;/sup&gt;​​​​</code> customer has in the <code>j​​​​​&lt;sup&gt;​​​​​​th&lt;/sup&gt;</code>​​​​ bank. Return <em>the</em> <strong><em>wealth</em></strong> <em>that the richest customer has.</em></p>
</li>
<li><p>A customer's <strong>wealth</strong> is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum <strong>wealth</strong>.</p>
</li>
<li><p><strong>Example 1:</strong></p>
<pre><code class="lang-java">  Input: accounts = [[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>],[<span class="hljs-number">3</span>,<span class="hljs-number">2</span>,<span class="hljs-number">1</span>]]
  Output: <span class="hljs-number">6</span>
  Explanation:
  <span class="hljs-number">1</span>st customer has wealth = <span class="hljs-number">1</span> + <span class="hljs-number">2</span> + <span class="hljs-number">3</span> = <span class="hljs-number">6</span>
  <span class="hljs-number">2</span>nd customer has wealth = <span class="hljs-number">3</span> + <span class="hljs-number">2</span> + <span class="hljs-number">1</span> = <span class="hljs-number">6</span>
  Both customers are considered the richest with a wealth of <span class="hljs-number">6</span> each, so <span class="hljs-keyword">return</span> <span class="hljs-number">6.</span>
</code></pre>
<p>  <strong>Example 2:</strong></p>
<pre><code class="lang-java">  Input: accounts = [[<span class="hljs-number">1</span>,<span class="hljs-number">5</span>],[<span class="hljs-number">7</span>,<span class="hljs-number">3</span>],[<span class="hljs-number">3</span>,<span class="hljs-number">5</span>]]
  Output: <span class="hljs-number">10</span>
  Explanation: 
  <span class="hljs-number">1</span>st customer has wealth = <span class="hljs-number">6</span>
  <span class="hljs-number">2</span>nd customer has wealth = <span class="hljs-number">10</span> 
  <span class="hljs-number">3</span>rd customer has wealth = <span class="hljs-number">8</span>
  The <span class="hljs-number">2</span>nd customer is the richest with a wealth of <span class="hljs-number">10.</span>
  Example <span class="hljs-number">3</span>:
</code></pre>
</li>
<li><p>I have attached my solution code below, ...</p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Solution</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">maximumWealth</span><span class="hljs-params">(<span class="hljs-keyword">int</span>[][] accounts)</span> </span>{
        <span class="hljs-keyword">int</span> sum = <span class="hljs-number">0</span>;
        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">0</span>; i&lt;accounts.length; i++){
            <span class="hljs-keyword">int</span> x = <span class="hljs-number">0</span>;
            <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> j=<span class="hljs-number">0</span>; j&lt;accounts[i].length; j++){
                x+=accounts[i][j];
            }
            <span class="hljs-keyword">if</span>(i==<span class="hljs-number">0</span>){
                sum = x;
            }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (x&gt;sum){
                sum = x;
            }
        }
        <span class="hljs-keyword">return</span> sum;
    }
}
</code></pre>
<h3 id="heading-key-points"><strong>Key Points</strong></h3>
<ul>
<li><p>The <code>linearSearch</code> function takes an array (<code>arr</code>) and a target value to search for.</p>
</li>
<li><p>It iterates through the array using a <code>for</code> loop and compares each element with the target value.</p>
</li>
<li><p>If a match is found, it returns the index of the element; otherwise, it returns -1 to indicate that the target is not in the array.</p>
</li>
<li><p>In the <code>main</code> method, we demonstrate how to use the <code>linearSearch</code> function.</p>
</li>
</ul>
<h3 id="heading-use-cases"><strong>Use Cases</strong></h3>
<ul>
<li><p>Linear search is suitable for small data sets or when the data is not sorted.</p>
</li>
<li><p>It's a simple and intuitive algorithm that works well when there's no specific order to the data.</p>
</li>
</ul>
<h3 id="heading-performance"><strong>Performance</strong></h3>
<ul>
<li><p>Linear search has a time complexity of O(n), meaning its execution time increases linearly with the size of the input array. For larger data sets, more efficient algorithms like binary search may be preferred.</p>
</li>
<li><p>Best case -&gt; element found at 0th position of array itself -&gt; O(1)</p>
</li>
<li><p>Worst case -&gt; element not found in array -&gt; O(n)</p>
</li>
</ul>
<h3 id="heading-conclusion"><strong>Conclusion</strong></h3>
<p>Remember that linear search is not the most efficient search algorithm for large data sets, but it can be a good choice for smaller arrays or when simplicity is more important than speed.</p>
]]></content:encoded></item><item><title><![CDATA[Day 4: Exploring  Arrays and ArrayList]]></title><description><![CDATA[Why do we need Array?
Arrays are essential data structures in programming because they allow us to store and manage collections of elements efficiently. They provide a way to group related data under a single variable name, simplifying code organizat...]]></description><link>https://arunkumar0203.hashnode.dev/day-4-exploring-arrays-and-arraylist</link><guid isPermaLink="true">https://arunkumar0203.hashnode.dev/day-4-exploring-arrays-and-arraylist</guid><category><![CDATA[array]]></category><category><![CDATA[arrays]]></category><category><![CDATA[ArrayList]]></category><dc:creator><![CDATA[Arun Kumar]]></dc:creator><pubDate>Sun, 24 Sep 2023 16:55:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/CIfgsywk-_4/upload/84852de52da8df199d2b41067950287c.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-why-do-we-need-array">Why do we need Array?</h3>
<p>Arrays are essential data structures in programming because they allow us to store and manage collections of elements efficiently. They provide a way to group related data under a single variable name, simplifying code organization. Arrays facilitate easy access to individual elements through indexing, making it convenient for tasks like data retrieval and manipulation. They also enable repetitive operations and iterative processes, enhancing code readability and reducing redundancy.</p>
<p>Certainly! Here are some key notes about arrays in Java along with code examples:</p>
<h3 id="heading-declaration-and-initialization"><strong>Declaration and Initialization</strong></h3>
<ul>
<li><p>Declare an array using square brackets after the data type.</p>
</li>
<li><p>Initialize an array using the <code>new</code> keyword or by specifying values enclosed in curly braces <code>{}</code>.</p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-comment">// Declaration and initialization of an integer array</span>
<span class="hljs-keyword">int</span>[] numbers = <span class="hljs-keyword">new</span> <span class="hljs-keyword">int</span>[<span class="hljs-number">5</span>]; <span class="hljs-comment">// Creates an array of size 5</span>
<span class="hljs-comment">// Here new keyword is used to create an object of size 5 in memory</span>
<span class="hljs-keyword">int</span>[] primeNumbers = {<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">7</span>, <span class="hljs-number">11</span>}; <span class="hljs-comment">// Initializes an array with values</span>
</code></pre>
<h3 id="heading-accessing-elements"><strong>Accessing Elements</strong></h3>
<ul>
<li><p>Array elements are accessed using zero-based indexing.</p>
</li>
<li><p>Use square brackets <code>[]</code> to access elements.</p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-keyword">int</span> firstNumber = numbers[<span class="hljs-number">0</span>]; <span class="hljs-comment">// Accesses the first element (index 0)</span>
<span class="hljs-keyword">int</span> thirdPrime = primeNumbers[<span class="hljs-number">2</span>]; <span class="hljs-comment">// Accesses the third element (index 2)</span>
</code></pre>
<h3 id="heading-array-length"><strong>Array Length</strong></h3>
<ul>
<li>You can find the length of an array using the <code>length</code> property.</li>
</ul>
<pre><code class="lang-java"><span class="hljs-keyword">int</span> length = numbers.length; <span class="hljs-comment">// Gets the length of the 'numbers' array</span>
</code></pre>
<h3 id="heading-iterating-through-arrays"><strong>Iterating Through Arrays</strong></h3>
<ul>
<li>Use loops like <code>for</code> or <code>foreach</code> to iterate through array elements.</li>
</ul>
<pre><code class="lang-java"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; numbers.length; i++) {
    System.out.println(numbers[i]);
}

<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> prime : primeNumbers) {
    System.out.println(prime);
}
</code></pre>
<h3 id="heading-arraystostring-method"><strong>Arrays.toString( ) Method</strong></h3>
<ul>
<li><p>Returns a string representation of the contents of the specified array.</p>
</li>
<li><p>The string representation consists of a list of the array's elements, enclosed in square brackets (<code>"[]"</code>). Adjacent elements are separated by the characters <code>", "</code> (a comma followed by a space).</p>
</li>
<li><p>Elements are converted to strings as by <code>String.valueOf(int)</code>. Returns <code>"null"</code> if <code>arr</code> is <code>null</code>.</p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-comment">// Create an array of integers</span>
<span class="hljs-keyword">int</span>[] numbers = {<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>};
<span class="hljs-comment">// Use Arrays.toString to get a string representation of the array</span>
String arrayString = Arrays.toString(numbers);
<span class="hljs-comment">// Print the string representation</span>
System.out.println(<span class="hljs-string">"Array as a string: "</span> + arrayString);
<span class="hljs-comment">//Output : Array as a string: [1, 2, 3, 4, 5]</span>
</code></pre>
<h3 id="heading-multi-dimensional-arrays"><strong>Multi-Dimensional Arrays</strong></h3>
<ul>
<li><p>Java supports multi-dimensional arrays, such as 2D arrays for representing tables or matrices.</p>
</li>
<li><p>While declaring a 2D array in Java, it is not compulsory to add no of columns though, because they can change with each elements</p>
</li>
<li><p><code>int arr[][] = { {1, 2, 3}, {4, 5}, {6, 7, 8, 9, 10} };</code></p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-keyword">int</span>[][] matrix = {{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>}, {<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>}, {<span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>}};
<span class="hljs-keyword">int</span> element = matrix[<span class="hljs-number">1</span>][<span class="hljs-number">2</span>]; <span class="hljs-comment">// Accesses the element at row 1, column 2 (value 6)</span>
</code></pre>
<h3 id="heading-array-manipulation"><strong>Array Manipulation</strong></h3>
<ul>
<li>Arrays can be sorted, searched, and modified using various methods and algorithms provided by Java.</li>
</ul>
<pre><code class="lang-java">Arrays.sort(numbers); <span class="hljs-comment">// Sorts the 'numbers' array in ascending order</span>
<span class="hljs-keyword">int</span> index = Arrays.binarySearch(primeNumbers, <span class="hljs-number">7</span>); <span class="hljs-comment">// Searches for the value 7 in 'primeNumbers'</span>
</code></pre>
<h3 id="heading-array-bounds-and-exceptions"><strong>Array Bounds and Exceptions</strong></h3>
<ul>
<li>Be cautious to avoid accessing elements outside the array bounds, which can lead to <code>ArrayIndexOutOfBoundsException</code>.</li>
</ul>
<pre><code class="lang-java"><span class="hljs-keyword">int</span> outOfBounds = numbers[<span class="hljs-number">10</span>]; <span class="hljs-comment">// This will throw an exception if the array size is less than 11</span>
</code></pre>
<h3 id="heading-dynamic-arrays"><strong>Dynamic Arrays</strong></h3>
<ul>
<li>Java arrays have a fixed size. If you need a dynamic-sized array, consider using <code>ArrayList</code> from the <code>java.util</code> package.</li>
</ul>
<pre><code class="lang-java"><span class="hljs-keyword">import</span> java.util.ArrayList;
<span class="hljs-comment">//Syntax:</span>
<span class="hljs-comment">//ArrayList&lt;RapperClass_datatype&gt; nameOfArrayList = new ArrayList&lt;&gt;();</span>
<span class="hljs-comment">//</span>
ArrayList&lt;Integer&gt; dynamicArray = <span class="hljs-keyword">new</span> ArrayList&lt;&gt;();
dynamicArray.add(<span class="hljs-number">42</span>); <span class="hljs-comment">// Adds an element to the dynamic array</span>
</code></pre>
<p>Arrays are a fundamental part of Java and are widely used for data storage and manipulation in various applications. They provide a structured way to work with collections of data, making them a crucial concept for Java developers.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>In conclusion, arrays are the backbone of data storage and manipulation in Java. They offer an efficient means of organizing and managing collections of elements, streamlining code organization and enhancing readability. With the ability to access individual elements via indexing, arrays enable various data retrieval and manipulation tasks while reducing redundancy.</p>
<p>We've explored the essential aspects of arrays in Java, from their declaration and initialization to accessing elements and determining array length. Iteration through arrays, utilizing the <code>Arrays.toString()</code> method for representation, and even handling multi-dimensional arrays have been discussed.</p>
<p>Stay tuned for our next exploration into problems on Array, which provide dynamic array functionality and opens up new possibilities in Java programming. Arrays and ArrayLists are fundamental tools in a Java developer's toolkit, and mastering them will expand your capabilities as a programmer.</p>
]]></content:encoded></item><item><title><![CDATA[Day 3: Getting to Know the Basics]]></title><description><![CDATA[Introduction
Conditionals and loops are fundamental programming constructs in Java, as well as in many other programming languages. They allow you to control the flow of your program and perform repetitive tasks. In Java, you can use the if statement...]]></description><link>https://arunkumar0203.hashnode.dev/day-3-getting-to-know-the-basics</link><guid isPermaLink="true">https://arunkumar0203.hashnode.dev/day-3-getting-to-know-the-basics</guid><category><![CDATA[Conditional statement]]></category><category><![CDATA[Loops]]></category><category><![CDATA[functions]]></category><category><![CDATA[Methods]]></category><category><![CDATA[Java]]></category><dc:creator><![CDATA[Arun Kumar]]></dc:creator><pubDate>Sat, 23 Sep 2023 16:29:37 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/pxoZSTdAzeU/upload/a03becdfe20b77d6ff32f7292a301904.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<hr />
<h2 id="heading-introduction">Introduction</h2>
<p>Conditionals and loops are fundamental programming constructs in Java, as well as in many other programming languages. They allow you to control the flow of your program and perform repetitive tasks. In Java, you can use the <code>if</code> statement for conditionals and various loop constructs such as <code>for</code>, <code>while</code>, and <code>do-while</code> for looping. Let's explore how to use them:</p>
<h2 id="heading-conditional-statements-if-else-if-else">Conditional Statements (if, else if, else)</h2>
<p>Conditional statements allow you to execute different blocks of code based on certain conditions.</p>
<p>1. <code>if</code> <strong>statement:</strong></p>
<pre><code class="lang-java"><span class="hljs-keyword">int</span> age = <span class="hljs-number">18</span>;
<span class="hljs-keyword">if</span> (age &gt;= <span class="hljs-number">18</span>) {
    System.out.println(<span class="hljs-string">"You are an adult."</span>);
}
</code></pre>
<p>2. <code>else if</code> <strong>statement:</strong></p>
<pre><code class="lang-java"><span class="hljs-keyword">int</span> age = <span class="hljs-number">15</span>;
<span class="hljs-keyword">if</span> (age &gt;= <span class="hljs-number">18</span>) {
    System.out.println(<span class="hljs-string">"You are an adult."</span>);
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (age &gt;= <span class="hljs-number">13</span>) {
    System.out.println(<span class="hljs-string">"You are a teenager."</span>);
} <span class="hljs-keyword">else</span> {
    System.out.println(<span class="hljs-string">"You are a child."</span>);
}
</code></pre>
<h2 id="heading-loops">Loops</h2>
<p>Loops allow you to repeatedly execute a block of code as long as a certain condition is met.</p>
<p>1. <code>for</code> <strong>loop:</strong></p>
<pre><code class="lang-java"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">5</span>; i++) {
    System.out.println(<span class="hljs-string">"Iteration "</span> + i);
}
</code></pre>
<p>2. <code>while</code> <strong>loop:</strong></p>
<pre><code class="lang-java"><span class="hljs-keyword">int</span> count = <span class="hljs-number">0</span>;
<span class="hljs-keyword">while</span> (count &lt; <span class="hljs-number">5</span>) {
    System.out.println(<span class="hljs-string">"Count: "</span> + count);
    count++;
}
</code></pre>
<p>3. <code>do-while</code> <strong>loop:</strong></p>
<pre><code class="lang-java"><span class="hljs-keyword">int</span> number = <span class="hljs-number">1</span>;
<span class="hljs-keyword">do</span> {
    System.out.println(<span class="hljs-string">"Number: "</span> + number);
    number++;
} <span class="hljs-keyword">while</span> (number &lt;= <span class="hljs-number">5</span>);
</code></pre>
<p>In a <code>for</code> loop, you specify the initialization, condition, and update of the loop variable all in one place. In a <code>while</code> loop, you specify the condition before entering the loop, and in a <code>do-while</code> loop, the condition is checked after executing the loop at least once.</p>
<h2 id="heading-logical-operators">Logical Operators</h2>
<p>Certainly! Logical operators are often used in conjunction with conditional statements to create more complex conditions. In Java, there are three main logical operators: <code>&amp;&amp;</code> (logical AND), <code>||</code> (logical OR), and <code>!</code> (logical NOT).</p>
<p>1. <strong>Logical AND (</strong><code>&amp;&amp;</code><strong>):</strong></p>
<p>The logical AND operator returns true if both of its operands are true.</p>
<pre><code class="lang-java"><span class="hljs-keyword">boolean</span> isAdult = <span class="hljs-keyword">true</span>;
<span class="hljs-keyword">boolean</span> hasID = <span class="hljs-keyword">true</span>;

<span class="hljs-keyword">if</span> (isAdult &amp;&amp; hasID) {
    System.out.println(<span class="hljs-string">"You can enter the club."</span>);
} <span class="hljs-keyword">else</span> {
    System.out.println(<span class="hljs-string">"You cannot enter the club."</span>);
}
</code></pre>
<p>2. <strong>Logical OR (</strong><code>||</code><strong>):</strong></p>
<p>The logical OR operator returns true if at least one of its operands is true.</p>
<pre><code class="lang-java"><span class="hljs-keyword">boolean</span> isStudent = <span class="hljs-keyword">true</span>;
<span class="hljs-keyword">boolean</span> isEmployee = <span class="hljs-keyword">false</span>;

<span class="hljs-keyword">if</span> (isStudent || isEmployee) {
    System.out.println(<span class="hljs-string">"You are part of the institution."</span>);
} <span class="hljs-keyword">else</span> {
    System.out.println(<span class="hljs-string">"You are not affiliated."</span>);
}
</code></pre>
<p>3. <strong>Logical NOT (</strong><code>!</code><strong>):</strong></p>
<p>The logical NOT operator negates the value of its operand. If the operand is true, it returns false, and if the operand is false, it returns true.</p>
<pre><code class="lang-java"><span class="hljs-keyword">boolean</span> isLoggedIn = <span class="hljs-keyword">false</span>;

<span class="hljs-keyword">if</span> (!isLoggedIn) {
    System.out.println(<span class="hljs-string">"Please log in to continue."</span>);
}
</code></pre>
<h2 id="heading-control-flow-statements">Control Flow Statements</h2>
<p>You can use control flow statements within loops and conditionals to control the flow of your program further. Examples include <code>break</code> and <code>continue</code> statements.</p>
<p><code>break</code> <strong>statement:</strong></p>
<pre><code class="lang-java"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">10</span>; i++) {
    <span class="hljs-keyword">if</span> (i == <span class="hljs-number">5</span>) {
        <span class="hljs-keyword">break</span>; <span class="hljs-comment">// Exit the loop when i reaches 5.</span>
    }
    System.out.println(<span class="hljs-string">"i: "</span> + i);
}
</code></pre>
<p><code>continue</code> <strong>statement:</strong></p>
<pre><code class="lang-java"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">10</span>; i++) {
    <span class="hljs-keyword">if</span> (i % <span class="hljs-number">2</span> == <span class="hljs-number">0</span>) {
        <span class="hljs-keyword">continue</span>; <span class="hljs-comment">// Skip even numbers.</span>
    }
    System.out.println(<span class="hljs-string">"Odd number: "</span> + i);
}
</code></pre>
<p>These are the basic constructs for conditionals and loops in Java. You can combine them to create more complex control structures for your programs.</p>
<h2 id="heading-switch-statements">Switch Statements</h2>
<ul>
<li><p><strong>Switch</strong> statements allow you to perform different actions based on different values of a variable.</p>
</li>
<li><p>The variable in a switch statement is compared against different case values.</p>
</li>
<li><p>Use <strong>break</strong> to exit the switch block after executing a case.</p>
</li>
<li><p>You can include a <strong>default</strong> case for when no other cases match.</p>
</li>
<li><p>Switch statements are often used when you have multiple choices to handle.</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="lang-java"><span class="hljs-keyword">int</span> day = <span class="hljs-number">3</span>;
<span class="hljs-keyword">switch</span> (day) {
    <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>:
        System.out.println(<span class="hljs-string">"Monday"</span>);
        <span class="hljs-keyword">break</span>;
    <span class="hljs-keyword">case</span> <span class="hljs-number">2</span>:
        System.out.println(<span class="hljs-string">"Tuesday"</span>);
        <span class="hljs-keyword">break</span>;
    <span class="hljs-keyword">case</span> <span class="hljs-number">3</span>:
        System.out.println(<span class="hljs-string">"Wednesday"</span>);
        <span class="hljs-keyword">break</span>;
    <span class="hljs-keyword">default</span>:
        System.out.println(<span class="hljs-string">"Other day"</span>);
}
</code></pre>
<p>In this example, "Wednesday" will be printed because <code>day</code> is set to 3. If <code>day</code> were 5, "Other day" would be printed due to the default case.</p>
<h2 id="heading-functions-methods-in-java">Functions/ Methods in Java</h2>
<p>Functions (also known as methods in Java) are blocks of code that perform a specific task or a set of tasks. They allow you to break down your code into smaller, reusable pieces. In Java, methods are defined inside classes. Here's an overview of how to work with methods in Java:</p>
<ol>
<li><p><strong>Method Declaration:</strong></p>
<p> You declare a method using the following syntax:</p>
<pre><code class="lang-java"> <span class="hljs-function">return_type <span class="hljs-title">method_name</span><span class="hljs-params">(parameter_list)</span> </span>{
     <span class="hljs-comment">// method body</span>
 }
</code></pre>
<ul>
<li><p><code>return_type</code>: The data type of the value that the method returns. Use <code>void</code> if the method doesn't return a value.</p>
</li>
<li><p><code>method_name</code>: The name of the method.</p>
</li>
<li><p><code>parameter_list</code>: A list of parameters (inputs) the method accepts, separated by commas. You can have zero or more parameters.</p>
</li>
</ul>
</li>
<li><p><strong>Method Parameters:</strong></p>
<p> Parameters are variables that you define in the method's parameter list, and they act as placeholders for the values you want to pass into the method when you call it. For example:</p>
<pre><code class="lang-java"> <span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">add</span><span class="hljs-params">(<span class="hljs-keyword">int</span> a, <span class="hljs-keyword">int</span> b)</span> </span>{
     <span class="hljs-keyword">return</span> a + b;
 }
</code></pre>
</li>
<li><p><strong>Using Varargs (Variable-Length Arguments):</strong></p>
<p> Java provides varargs (variable-length arguments) to pass a variable number of arguments of the same type to a method. Varargs are represented using an ellipsis <code>...</code> after the parameter type.</p>
<pre><code class="lang-java"> <span class="hljs-function">javaCopy codepublic <span class="hljs-keyword">void</span> <span class="hljs-title">printItems</span><span class="hljs-params">(String... items)</span> </span>{
     <span class="hljs-keyword">for</span> (String item : items) {
         System.out.print(item + <span class="hljs-string">" "</span>);
     }
     System.out.println();
 }

 <span class="hljs-comment">// Calling the method with varargs</span>
 printItems(<span class="hljs-string">"Apple"</span>, <span class="hljs-string">"Banana"</span>, <span class="hljs-string">"Cherry"</span>); <span class="hljs-comment">// Outputs: Apple Banana Cherry</span>
</code></pre>
<p> The method can be called with any number of arguments (including none) of the specified type.</p>
</li>
<li><p><strong>Method Body:</strong></p>
<p> The method body contains the code that gets executed when the method is called. For example:</p>
<pre><code class="lang-java"> <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">greet</span><span class="hljs-params">(String name)</span> </span>{
     System.out.println(<span class="hljs-string">"Hello, "</span> + name + <span class="hljs-string">"!"</span>);
 }
</code></pre>
</li>
<li><p><strong>Calling a Method:</strong></p>
<p> To use a method, you call it by its name, passing the required arguments if any, like this:</p>
<pre><code class="lang-java"> <span class="hljs-keyword">int</span> result = add(<span class="hljs-number">5</span>, <span class="hljs-number">3</span>);
 greet(<span class="hljs-string">"Alice"</span>);
</code></pre>
<ul>
<li><p><code>add(5, 3)</code> calls the <code>add</code> method with arguments 5 and 3 and stores the result in the <code>result</code> variable.</p>
</li>
<li><p><code>greet("Alice")</code> calls the <code>greet</code> method with the argument "Alice."</p>
</li>
</ul>
</li>
<li><p><strong>Return Statement:</strong></p>
<p> If the method has a return type other than <code>void</code>, it must include a <code>return</code> statement to return a value of the specified type. For example:</p>
<pre><code class="lang-java"> <span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">add</span><span class="hljs-params">(<span class="hljs-keyword">int</span> a, <span class="hljs-keyword">int</span> b)</span> </span>{
     <span class="hljs-keyword">return</span> a + b;
 }
</code></pre>
</li>
<li><p><strong>Void Methods:</strong></p>
<p> Methods with a return type of <code>void</code> do not return any value. They are used for performing actions without returning a result. For example:</p>
<pre><code class="lang-java"> <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">printMessage</span><span class="hljs-params">()</span> </span>{
     System.out.println(<span class="hljs-string">"This is a void method."</span>);
 }
</code></pre>
</li>
<li><p><strong>Method Overloading:</strong></p>
<p> Java allows you to define multiple methods with the same name in the same class as long as they have different parameter lists. This is called method overloading. Java will determine which method to call based on the arguments you provide when calling it.</p>
<pre><code class="lang-java"> <span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">add</span><span class="hljs-params">(<span class="hljs-keyword">int</span> a, <span class="hljs-keyword">int</span> b)</span> </span>{
     <span class="hljs-keyword">return</span> a + b;
 }

 <span class="hljs-function"><span class="hljs-keyword">double</span> <span class="hljs-title">add</span><span class="hljs-params">(<span class="hljs-keyword">double</span> a, <span class="hljs-keyword">double</span> b)</span> </span>{
     <span class="hljs-keyword">return</span> a + b;
 }
</code></pre>
</li>
<li><p><strong>Static Methods:</strong></p>
<p> Static methods belong to the class rather than an instance of the class. You can call static methods using the class name, without creating an object of the class.</p>
<pre><code class="lang-java"> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">staticMethod</span><span class="hljs-params">()</span> </span>{
     System.out.println(<span class="hljs-string">"This is a static method."</span>);
 }
</code></pre>
</li>
</ol>
<p>Now you have a basic understanding of how to define and use methods in Java. Methods are essential for structuring your code, making it more organized, and promoting reusability.</p>
<h2 id="heading-scope-in-java">Scope in Java</h2>
<p>In Java, scope refers to the region of your code where a particular variable can be accessed or used. Understanding the scope of variables is essential for writing error-free and maintainable code. Java has several types of variable scope:</p>
<p><strong>Local Scope:</strong></p>
<ul>
<li><p>Variables declared within a method, constructor, or block of code have local scope.</p>
</li>
<li><p>They can only be accessed within that method, constructor, or block.</p>
</li>
<li><p>Local variables are not visible outside of their enclosing block, and they are destroyed when the block exits.</p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">myMethod</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">int</span> localVar = <span class="hljs-number">42</span>; <span class="hljs-comment">// localVar is only accessible inside myMethod()</span>
    System.out.println(localVar); <span class="hljs-comment">// This is valid</span>
}
</code></pre>
<p><strong>Method or Parameter Scope:</strong></p>
<ul>
<li><p>Method parameters have scope within the method they are declared in.</p>
</li>
<li><p>They can shadow (hide) class-level fields with the same name.</p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-keyword">int</span> myVar = <span class="hljs-number">10</span>; <span class="hljs-comment">// Class-level variable</span>

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">myMethod</span><span class="hljs-params">(<span class="hljs-keyword">int</span> myVar)</span> </span>{
    System.out.println(myVar); <span class="hljs-comment">// This will print the parameter myVar, not the class-level one</span>
}
</code></pre>
<p><strong>Class Scope (Instance Variables):</strong></p>
<ul>
<li><p>Instance variables (also called fields) are declared within a class but outside of any method, constructor, or block.</p>
</li>
<li><p>They have class scope and can be accessed by any method within the same class, as well as by objects of that class.</p>
</li>
<li><p>Each instance (object) of the class has its own copy of instance variables.</p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span> </span>{
    <span class="hljs-keyword">int</span> instanceVar = <span class="hljs-number">42</span>; <span class="hljs-comment">// Instance variable</span>
}
</code></pre>
<p><strong>Static Scope (Class Variables):</strong></p>
<ul>
<li><p>Static variables are declared using the <code>static</code> keyword within a class but outside of any method, constructor, or block.</p>
</li>
<li><p>They have class scope, just like instance variables.</p>
</li>
<li><p>However, there is only one copy of a static variable shared among all instances of the class.</p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span> </span>{
    <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> staticVar = <span class="hljs-number">42</span>; <span class="hljs-comment">// Static variable</span>
}
</code></pre>
<p><strong>Block Scope (Local Blocks):</strong></p>
<ul>
<li><p>Java allows you to create local blocks within methods, constructors, or other blocks.</p>
</li>
<li><p>Variables declared within these local blocks have scope limited to the block itself.</p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">myMethod</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">int</span> localVar = <span class="hljs-number">42</span>;

    {
        <span class="hljs-keyword">int</span> blockVar = <span class="hljs-number">10</span>;
        System.out.println(localVar); <span class="hljs-comment">// Accessible</span>
        System.out.println(blockVar); <span class="hljs-comment">// Accessible</span>
    }

    System.out.println(localVar); <span class="hljs-comment">// Accessible</span>
    <span class="hljs-comment">// System.out.println(blockVar); // Error: blockVar is not accessible here</span>
}
</code></pre>
<p>Remember that the principle of variable scope is vital for preventing naming conflicts, understanding where variables are accessible, and managing memory efficiently in your Java programs.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this blog post, we've embarked on a journey into the core concepts of Java programming. We've explored conditional statements, loops, methods, logical operators, and variable scope, all of which are foundational elements of Java development. Understanding these fundamentals is crucial as they provide the building blocks for writing organized, efficient, and maintainable Java code.</p>
<p>As you continue your Java programming journey, these concepts will serve as a solid foundation upon which you can build more complex applications. Whether you're a beginner taking your first steps into the world of Java or an experienced developer looking to refresh your knowledge, mastering these fundamentals is a vital step towards becoming a proficient Java programmer.</p>
<p>Keep practicing, exploring, and expanding your Java skills, and remember that each day brings us closer to becoming accomplished Java developers. Join me again tomorrow as we dive into the fascinating world of arrays, another essential component of Java programming. Until then, happy coding!</p>
]]></content:encoded></item><item><title><![CDATA[Day 2: First Java Program]]></title><description><![CDATA[Types of Programming Language

Procedural
  Contains a systematic order of statements, functions and commands to complete a task

Functional
  Used in situations where we have to perform lots of different operations on the same set of data, like ML.
...]]></description><link>https://arunkumar0203.hashnode.dev/day-2-first-java-program</link><guid isPermaLink="true">https://arunkumar0203.hashnode.dev/day-2-first-java-program</guid><category><![CDATA[Java]]></category><category><![CDATA[coding]]></category><category><![CDATA[DSA]]></category><category><![CDATA[#DSAwithKunal]]></category><dc:creator><![CDATA[Arun Kumar]]></dc:creator><pubDate>Fri, 22 Sep 2023 17:00:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/npxXWgQ33ZQ/upload/81c313309b010d1e65b84a497d133e65.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<hr />
<h2 id="heading-types-of-programming-language">Types of Programming Language</h2>
<ul>
<li><p><strong>Procedural</strong></p>
<p>  Contains a systematic order of statements, functions and commands to complete a task</p>
</li>
<li><p><strong>Functional</strong></p>
<p>  Used in situations where we have to perform lots of different operations on the same set of data, like ML.</p>
</li>
<li><p><strong>Object Oriented</strong></p>
<p>  Object-oriented programming centers around objects, which are instances of classes that encapsulate both data (attributes) and behaviors (methods).</p>
</li>
</ul>
<h2 id="heading-static-vs-dynamic">Static vs Dynamic</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Aspect</strong></td><td><strong>Static Languages</strong></td><td><strong>Dynamic Languages</strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>Early Error Detection</strong></td><td>Offer early error detection</td><td>This may lead to runtime errors related to type mismatches</td></tr>
<tr>
<td><strong>Performance</strong></td><td>Better performance</td><td>Provide flexibility</td></tr>
<tr>
<td><strong>Type Definitions</strong></td><td>Require stricter type definitions</td><td>Offer flexibility</td></tr>
<tr>
<td><strong>Common Languages</strong></td><td>Java, C++, Swift</td><td>Python, JavaScript, Ruby</td></tr>
<tr>
<td><strong>Selection Criteria</strong></td><td>Project's requirements and developer preferences</td><td>Project's requirements and developer preferences</td></tr>
</tbody>
</table>
</div><h2 id="heading-why-java">Why Java?</h2>
<p>Java is an excellent choice for learning Data Structures and Algorithms (DSA) because it offers strong support for object-oriented programming, which aligns well with DSA concepts, and its robust standard libraries provide a wide range of data structures and algorithms for practice and implementation. Additionally, Java's platform independence allows learners to focus on DSA principles without worrying about low-level system details.</p>
<h2 id="heading-running-your-first-java-programm-hello-world">Running Your First Java Programm - Hello, World!</h2>
<p>To compile and run a Java file using the command prompt (cmd) on Windows, follow these steps:</p>
<ol>
<li><p><strong>Install Java (if not already installed):</strong></p>
<ul>
<li>Make sure you have Java Development Kit (JDK) installed on your computer. You can download it from the official Oracle website.</li>
</ul>
</li>
<li><p><strong>Write Your Java Code:</strong></p>
<ul>
<li><p>Use a text editor (e.g., Notepad) to write your Java code. Save the file with a ".java" extension. For example, you can create a file named "HelloWorld.java" with the following content:</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1695389905230/7b11dcba-2b29-4b93-a0cb-b24380c0b3a7.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
</ol>
<pre><code class="lang-java">    <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HelloWorld</span> </span>{
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
            <span class="hljs-comment">//Display Hello, World!</span>
            System.out.println(<span class="hljs-string">"Hello, World!"</span>);
        }
    }
</code></pre>
<ol>
<li><p><strong>Open Command Prompt (cmd):</strong></p>
<ul>
<li>Press <code>Win + R</code>, type "cmd," and press Enter to open the command prompt.</li>
</ul>
</li>
<li><p><strong>Navigate to the Directory Containing Your Java File:</strong></p>
<ul>
<li>Use the <code>cd</code> (change directory) command to navigate to the directory where your Java file is located. For example:</li>
</ul>
</li>
</ol>
<pre><code class="lang-bash">    <span class="hljs-built_in">cd</span> path\to\your\java\file\directory
</code></pre>
<ol>
<li><p><strong>Compile the Java Program:</strong></p>
<ul>
<li>Use the <code>javac</code> command to compile your Java source file (replace "HelloWorld.java" with your file's name if different):</li>
</ul>
</li>
</ol>
<pre><code class="lang-bash">    javac HelloWorld.java
</code></pre>
<p>    If there are no syntax errors in your code, this will generate a bytecode file named "HelloWorld.class" in the same directory.</p>
<ol>
<li><p><strong>Run the Compiled Java Program:</strong></p>
<ul>
<li>To execute your Java program, use the <code>java</code> command followed by the name of the class containing the <code>main</code> method (without the ".class" extension):</li>
</ul>
</li>
</ol>
<pre><code class="lang-bash">    java HelloWorld
</code></pre>
<p>    If everything is set up correctly, you should see the output of your program, which is "Hello, World!" in this case.</p>
<p>That's it! You've compiled and run a Java program using the command prompt. You can now create more complex Java applications and follow the same process to compile and execute them.</p>
<h3 id="heading-inputs-in-java">Inputs in Java</h3>
<p>The <code>Scanner</code> class in Java is a useful utility for reading input from various sources, such as the keyboard (standard input), files, or strings. It is part of the <code>java.util</code> package and provides methods for parsing and tokenizing input. Here's an overview of how to use the <code>Scanner</code> class for input in Java:</p>
<ol>
<li><p><strong>Import the Scanner class:</strong></p>
<p> To use the <code>Scanner</code> class, you need to import it at the beginning of your Java program:</p>
<pre><code class="lang-java"> <span class="hljs-keyword">import</span> java.util.Scanner;
</code></pre>
</li>
<li><p><strong>Creating a Scanner object:</strong></p>
<p> You create a <code>Scanner</code> object to read input from a specific source. The most common source is the keyboard (standard input):</p>
<pre><code class="lang-java"> Scanner input = <span class="hljs-keyword">new</span> Scanner(System.in);
</code></pre>
<p> This creates a <code>Scanner</code> object named <code>input</code> that reads input from the keyboard (<code>System.in</code>).</p>
</li>
<li><p><strong>Reading Input:</strong></p>
<p> You can use various <code>Scanner</code> methods to read input based on the data type you expect. Here are some common methods:</p>
<ul>
<li><p><code>nextLine()</code>: Reads a line of text (including spaces) as a <code>String</code>.</p>
</li>
<li><p><code>nextInt()</code>: Reads the next integer.</p>
</li>
<li><p><code>nextDouble()</code>: Reads the next double-precision floating-point number.</p>
</li>
<li><p><code>nextBoolean()</code>: Reads the next boolean value (true or false).</p>
</li>
<li><p><code>next().charAt(0)</code>: Reads the next char value.</p>
</li>
<li><p><code>next()</code>: Reads individual words.</p>
<p>  Example:</p>
<pre><code class="lang-java">  System.out.print(<span class="hljs-string">"Enter your name: "</span>);
  String name = input.nextLine();

  System.out.print(<span class="hljs-string">"Enter your age: "</span>);
  <span class="hljs-keyword">int</span> age = input.nextInt();
</code></pre>
</li>
</ul>
</li>
<li><p><strong>Closing the Scanner:</strong></p>
<p> It's a good practice to close the <code>Scanner</code> when you're done with it to release any system resources it might be holding:</p>
<pre><code class="lang-java"> input.close();
</code></pre>
<p> However, in most simple console applications, it's not strictly necessary since <code>System.in</code> will still be open. But it's essential when dealing with other input sources like files.</p>
</li>
</ol>
<h2 id="heading-data-types-in-java"><strong>Data Types in Java</strong></h2>
<ol>
<li><p><strong>Primitive Data Types (8):</strong></p>
<ul>
<li><p><code>byte</code>: 1 byte, -128 to 127</p>
</li>
<li><p><code>short</code>: 2 bytes, -32,768 to 32,767</p>
</li>
<li><p><code>int</code>: 4 bytes, -2^31 to 2^31-1</p>
</li>
<li><p><code>long</code>: 8 bytes, -2^63 to 2^63-1</p>
</li>
<li><p><code>float</code>: 4 bytes, 7 decimal digits</p>
</li>
<li><p><code>double</code>: 8 bytes, 15 decimal digits</p>
</li>
<li><p><code>char</code>: 2 bytes, Unicode character</p>
</li>
<li><p><code>boolean</code>: true or false</p>
</li>
</ul>
</li>
<li><p><strong>Reference Data Types:</strong></p>
<ul>
<li><p>Objects and references to objects.</p>
</li>
<li><p>String, Arrays, Custom Classes.</p>
</li>
</ul>
</li>
<li><p><strong>Wrapper Classes:</strong></p>
<ul>
<li><p>Convert primitives to objects.</p>
</li>
<li><p>E.g., <code>Integer</code>, <code>Double</code>, <code>Boolean</code>.</p>
</li>
</ul>
</li>
<li><p><strong>Casting:</strong></p>
<ul>
<li><p>Implicit (e.g., <code>int</code> to <code>double</code>).</p>
</li>
<li><p>Explicit (e.g., <code>(int) 3.14</code>).</p>
</li>
</ul>
</li>
<li><p><strong>Literals:</strong></p>
<ul>
<li><p>Constants: <code>1</code>, <code>3.14</code>, <code>'A'</code>, <code>true</code>.</p>
</li>
<li><p>Scientific Notation: <code>1.23e-4</code>.</p>
</li>
</ul>
</li>
<li><p><strong>Type Conversion:</strong></p>
<ul>
<li><p>Widening (Implicit): Smaller to larger data type.</p>
</li>
<li><p>Narrowing (Explicit): Larger to smaller data type (may lose data).</p>
</li>
</ul>
</li>
<li><p><strong>String Data Type:</strong></p>
<ul>
<li><p>Sequence of characters.</p>
</li>
<li><p><code>"Hello, World!"</code>.</p>
</li>
<li><p>Concatenation with <code>+</code>.</p>
</li>
</ul>
</li>
<li><p><strong>Arrays:</strong></p>
<ul>
<li><p>Ordered collection of elements.</p>
</li>
<li><p>E.g., <code>int[] numbers = {1, 2, 3};</code>.</p>
</li>
</ul>
</li>
<li><p><strong>Enum Types:</strong></p>
<ul>
<li><p>User-defined data types with a fixed set of constants.</p>
</li>
<li><p>E.g., <code>enum Days {MON, TUE, WED}</code>.</p>
</li>
</ul>
</li>
<li><p><strong>Constants:</strong></p>
<ul>
<li><p><code>final</code> keyword to create constants.</p>
</li>
<li><p>E.g., <code>final double PI = 3.14</code>.</p>
</li>
</ul>
</li>
<li><p><strong>Default Values:</strong></p>
<ul>
<li><p>Primitives: 0 (or false for <code>boolean</code>).</p>
</li>
<li><p>References: <code>null</code>.</p>
</li>
</ul>
</li>
<li><p><strong>Type Inference (Java 10+):</strong></p>
<ul>
<li><p><code>var</code> keyword for local variables.</p>
</li>
<li><p>E.g., <code>var num = 42;</code>.</p>
</li>
</ul>
</li>
</ol>
<p>Remember that choosing the right data type is crucial for efficient memory usage and accurate data representation in your Java programs.</p>
<h2 id="heading-type-casting">Type Casting</h2>
<p>In Java, there are two main types of type casting: implicit casting (widening) and explicit casting (narrowing).</p>
<p><strong>Implicit Casting (Widening):</strong></p>
<ul>
<li><p>Implicit casting occurs automatically when you assign a value of a smaller data type to a variable of a larger data type.</p>
</li>
<li><p>It's safe because there is no risk of data loss or loss of precision.</p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-keyword">int</span> intValue = <span class="hljs-number">42</span>;
<span class="hljs-keyword">double</span> doubleValue = intValue; <span class="hljs-comment">// Implicit casting from int to double</span>
</code></pre>
<p><strong>Explicit Casting (Narrowing):</strong></p>
<ul>
<li><p>Explicit casting is required when you want to convert a value of a larger data type to a smaller data type.</p>
</li>
<li><p>It may result in data loss or loss of precision, so you need to use a cast operator.</p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-keyword">double</span> doubleValue = <span class="hljs-number">3.14</span>;
<span class="hljs-keyword">int</span> intValue = (<span class="hljs-keyword">int</span>) doubleValue; <span class="hljs-comment">// Explicit casting from double to int</span>
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this insightful journey through the foundational concepts of Java programming, we've explored the various facets that make Java one of the most popular and versatile programming languages. From understanding the different types of programming languages to running our very first Java program, delving into input handling with the Scanner class, and comprehending the nuances of data types and type casting, we've laid a strong foundation for our coding endeavors.</p>
<p>Java, known for its robust support for object-oriented programming, is an ideal choice for learning Data Structures and Algorithms (DSA). It provides a seamless alignment between DSA concepts and object-oriented principles, allowing us to dive deeper into these critical areas of computer science.</p>
<p>As we continue this learning journey, we'll explore more intricate topics, build sophisticated applications, and embark on exciting coding challenges.</p>
<p>Stay tuned for the next chapter in our learning adventure, where we'll delve deeper into Java, tackle more advanced programming concepts, and work towards becoming proficient developers. Until then, happy coding!</p>
]]></content:encoded></item><item><title><![CDATA[Day 1: Mastering Git and GitHub]]></title><description><![CDATA[Introduction
Welcome to the world of version control and collaborative development! Git and GitHub have revolutionized the way we manage code, collaborate with teams, and track changes in software projects. In this comprehensive guide, I will take yo...]]></description><link>https://arunkumar0203.hashnode.dev/day-1-mastering-git-and-github</link><guid isPermaLink="true">https://arunkumar0203.hashnode.dev/day-1-mastering-git-and-github</guid><category><![CDATA[Git]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[Gitcommands]]></category><category><![CDATA[version control]]></category><category><![CDATA[documentation]]></category><dc:creator><![CDATA[Arun Kumar]]></dc:creator><pubDate>Thu, 21 Sep 2023 19:13:20 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/wX2L8L-fGeA/upload/e2bfbc850a5bc5de6aa004964625fd5f.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<hr />
<h3 id="heading-introduction"><strong>Introduction</strong></h3>
<p>Welcome to the world of version control and collaborative development! Git and GitHub have revolutionized the way we manage code, collaborate with teams, and track changes in software projects. In this comprehensive guide, I will take you on an in-depth journey through the fundamental concepts of Git and GitHub, starting from basic command-line operations to more advanced topics like branching, forking, and pull requests. Whether you're a beginner or looking to deepen your Git knowledge, this guide has you covered.</p>
<h3 id="heading-developer-journey"><strong>Developer Journey</strong></h3>
<blockquote>
<p><mark>Learn to Code --- Attend Events --- Participate in Hackathon --- Volunteer --- Freelance --- Apply for developer Job</mark></p>
<p><strong><mark>Learn to Code --- Post your Own Projects --- Contribute to Open Source --- Internship --- Apply for developer Job</mark></strong></p>
</blockquote>
<h3 id="heading-section-1-basic-cmd-commands"><strong>Section 1: Basic CMD Commands</strong></h3>
<p>Let's begin with the fundamentals of command-line operations on a Windows system. These commands are essential for navigating your file system and managing files and folders effectively.</p>
<pre><code class="lang-bash">notepad file-name       <span class="hljs-comment"># Creates and opens a file in Notepad</span>
code .                  <span class="hljs-comment"># Opens VS code                                            </span>
cls                     <span class="hljs-comment"># Clears the screen</span>
<span class="hljs-built_in">cd</span>                      <span class="hljs-comment"># Change directory</span>
<span class="hljs-built_in">cd</span> ..                   <span class="hljs-comment"># Move up one level</span>
mkdir                   <span class="hljs-comment"># Create a new folder</span>
dir                     <span class="hljs-comment"># List all files in the folder</span>
dir /a                  <span class="hljs-comment"># Show hidden files</span>
rmdir /s                <span class="hljs-comment"># Delete a folder with all contents</span>
rmdir                   <span class="hljs-comment"># Delete an empty folder</span>
<span class="hljs-built_in">echo</span> &gt; filename.ext     <span class="hljs-comment"># Create new files in the folder</span>
del <span class="hljs-string">"filename"</span>          <span class="hljs-comment"># Delete files</span>
del /f                  <span class="hljs-comment"># Force delete files</span>
del *.*                 <span class="hljs-comment"># Delete all files in the current folder</span>
del <span class="hljs-string">"word*"</span>             <span class="hljs-comment"># Delete files whose names start with "word"</span>
del <span class="hljs-string">"*word"</span>             <span class="hljs-comment"># Delete files that end with your specified word</span>
</code></pre>
<h3 id="heading-section-2-git-commands-local-repositories"><strong>Section 2: Git Commands (Local Repositories)</strong></h3>
<p>Now, let's dive into the essential Git commands for managing your local codebase effectively.</p>
<pre><code class="lang-bash">git init                <span class="hljs-comment"># Initialize a Git repository</span>
git add                 <span class="hljs-comment"># Move a file to the staging area</span>
git commit -m <span class="hljs-string">"message"</span> <span class="hljs-comment"># Commit changes to the local repository</span>
git status              <span class="hljs-comment"># Show the current status of updates</span>
git <span class="hljs-built_in">log</span>                 <span class="hljs-comment"># Display commitment messages</span>
git diff <span class="hljs-string">"file"</span>         <span class="hljs-comment"># Display differences (changes) made to a specific file</span>
git checkout <span class="hljs-string">"file"</span>     <span class="hljs-comment"># Revert any local changes made to that file</span>
</code></pre>
<h3 id="heading-section-3-pushing-to-github"><strong>Section 3: Pushing to GitHub</strong></h3>
<blockquote>
<p><mark>Working Directory ---&gt; Staging Area ---&gt; Local Repository ---&gt; Remote Repository</mark></p>
</blockquote>
<p>Learn how to push your local repository to GitHub, making your code accessible to others.</p>
<pre><code class="lang-bash">git remote add origin https://github.com/Username/RepositoryName.git
git branch -M main
git push -u origin main
</code></pre>
<h3 id="heading-section-4-creating-a-new-repository-on-github"><strong>Section 4: Creating a New Repository on GitHub</strong></h3>
<p>Explore how to create a new GitHub repository from the command line. It involves setting up a central location to store, manage, and collaborate on software development or other digital content. Users can define repository details, configure access controls, and initialize the repository with their project files, enabling efficient version control and collaboration with teammates or the open-source community.</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">"# Test"</span> &gt;&gt; README.mEd
git init
git add README.md
git commit -m <span class="hljs-string">"first commit"</span>
git remote add origin https://github.com/Username/RepositoryName.git
git push -u origin main
</code></pre>
<h3 id="heading-section-5-gitignore"><strong>Section 5: .gitignore</strong></h3>
<p>Use a <code>.gitignore</code> file to specify files and directories to exclude from Git commits, keeping your repository clean and secure.</p>
<pre><code class="lang-bash"><span class="hljs-comment"># .gitignore content</span>
*.<span class="hljs-built_in">log</span>
secret.txt
<span class="hljs-comment"># and more...</span>
</code></pre>
<h3 id="heading-section-6-cloning-a-repository"><strong>Section 6: Cloning a Repository</strong></h3>
<p>Discover how to clone a remote repository to your local machine for development.</p>
<pre><code class="lang-bash">git <span class="hljs-built_in">clone</span> url
</code></pre>
<h3 id="heading-section-7-branching-and-merging"><strong>Section 7: Branching and Merging</strong></h3>
<p>Understand the essential concepts of branching and merging in Git.</p>
<p><strong>What is a Branch?</strong> In Git, a branch is a separate line of development within a repository. It allows you to work on features, bug fixes, or experiments without affecting the main codebase (usually referred to as the "master" or "main" branch).</p>
<p><strong>What is Merging?</strong> Merging is the process of combining changes from one branch into another. You typically merge a feature branch back into the main branch (e.g., "master" or "main") to incorporate your changes into the main codebase.</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Creating a new branch</span>
git branch feature-branch

<span class="hljs-comment"># Switching to a branch</span>
git checkout feature-branch

<span class="hljs-comment"># Creating and switching to a new branch</span>
git checkout -b feature-branch

<span class="hljs-comment"># Merging branches</span>
git checkout main
git merge feature-branch

<span class="hljs-comment"># Deleting a branch</span>
git branch -d feature-branch
</code></pre>
<h3 id="heading-section-8-forking-and-pull-requests"><strong>Section 8: Forking and Pull Requests</strong></h3>
<p><strong>What is a Fork?</strong> Forking is the process of creating a copy of a repository (usually a public one) from one user's account or organization to another user's account or organization. The new copy is entirely separate from the original but starts with the same codebase.</p>
<p><strong>What are Pull Requests?</strong> In collaborative workflows, such as those used on platforms like GitHub or GitLab, developers often create pull requests or merge requests to propose and discuss changes before merging them into the main branch. This allows for code review and collaboration.</p>
<p>Collaborate effectively on open-source projects using forks and pull requests.</p>
<ul>
<li><p>Fork a Repository</p>
</li>
<li><p>Make Changes and Create a Pull Request</p>
</li>
<li><p>Collaborate and Review</p>
</li>
<li><p>Merge the Pull Request</p>
</li>
</ul>
<h3 id="heading-section-9-git-pull"><strong>Section 9: git pull</strong></h3>
<p>Combine fetching and merging in a single step to keep your local repository up to date.</p>
<pre><code class="lang-bash">git pull
</code></pre>
<h3 id="heading-section-10-git-reset"><strong>Section 10: git reset</strong></h3>
<p>Learn how to undo commits and reset your repository when necessary.</p>
<pre><code class="lang-bash">git reset &lt;hashid&gt; <span class="hljs-comment">#Visible on git log command</span>
</code></pre>
<h3 id="heading-section-11-expressing-gratitude"><strong>Section 11: Expressing Gratitude</strong></h3>
<p>As I embark on this thrilling journey of learning, I would like to extend my heartfelt gratitude to two individuals and their exceptional courses that have been guiding lights in my quest for knowledge.</p>
<p><strong>Kunal Kushwaha:</strong></p>
<p>I have been fortunate to follow the enlightening "Java + DSA + Interview Preparation Course" by Kunal Kushwaha, a comprehensive and free playlist available on YouTube. His dedication to making complex concepts accessible and his commitment to the community are truly admirable. <a target="_blank" href="https://youtu.be/apGV9Kg7ics?si=_1jPzmPvaG-MPp8o">Complete Git and GitHub Tutorial.</a></p>
<p><strong>Dr. Angela Yu:</strong></p>
<p>Another invaluable resource that has been pivotal in my journey is the, "The Complete 2023 Web Development Bootcamp" by Dr. Angela Yu on Udemy. With this course, I have been diving deep into the world of web development, exploring HTML, CSS, JavaScript, Node.js, React, MongoDB, Web3, and DApps. Dr. Angela Yu's course has provided me with not only the knowledge but also the practical skills necessary to become a full-stack web developer. <a target="_blank" href="https://www.udemy.com/share/1013gG3@y6eNzDYl_NUycNP6JRIBgnY01UHrron5BSN733b2zN1ZkvfMBReTfDByhwKxjev8AA==/"><strong>The Complete 2023 Web Development Bootcamp</strong></a></p>
<p>Thank you once again to Kunal Kushwaha and Dr. Angela Yu for their incredible contributions to the learning community.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>In this guide, we've delved into the essential aspects of Git and GitHub, from mastering basic command-line operations to creating repositories, managing branches, and collaborating effectively. Git and GitHub are powerful tools that can enhance your coding experience and teamwork. As you progress, remember the significance of continuous learning and practice.</p>
<p>As you continue your journey in technology and software development, stay curious, share your knowledge, and keep pushing boundaries. Together, we can make remarkable strides in this ever-evolving field. Thank you for being part of this learning adventure, and I look forward to our continued exploration and innovation.</p>
<p>Until then, happy coding!</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Day 0: Embarking on My Data Structures and Full Stack Learning Journey]]></title><description><![CDATA[Introduction
Hello, dear readers! Welcome to "DSA and Dev Days: Arun's Learning Blog." I'm thrilled to have you here with me as I embark on this exciting journey of learning data structures and full-stack development from scratch. This blog will serv...]]></description><link>https://arunkumar0203.hashnode.dev/day-0</link><guid isPermaLink="true">https://arunkumar0203.hashnode.dev/day-0</guid><category><![CDATA[DSA]]></category><category><![CDATA[full stack]]></category><category><![CDATA[Beginner Developers]]></category><dc:creator><![CDATA[Arun Kumar]]></dc:creator><pubDate>Wed, 20 Sep 2023 12:17:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/TamMbr4okv4/upload/cfb5902725df8ffb1815aea7b51a3378.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<hr />
<h3 id="heading-introduction"><strong>Introduction</strong></h3>
<p>Hello, dear readers! Welcome to "DSA and Dev Days: Arun's Learning Blog." I'm thrilled to have you here with me as I embark on this exciting journey of learning data structures and full-stack development from scratch. This blog will serve as a chronicle of my daily adventures, triumphs, and challenges as I dive headfirst into the world of programming and technology.</p>
<h3 id="heading-a-little-about-myself"><strong>A Little About Myself</strong></h3>
<p>Before we dive into the details of my learning journey, let me introduce myself. I'm Arun Kumar, a 2nd-year student at St. Joseph's Institute of Technology, pursuing a Bachelor's degree in Electronics and Communication Engineering (ECE). Despite my non-computer science background, I am deeply passionate about technology and programming.</p>
<h3 id="heading-why-im-starting-this-blog"><strong>Why I'm Starting This Blog</strong></h3>
<p>You might wonder, why start a blog about my learning journey? Well, the answer is simple: I believe in the power of documentation. Keeping a record of my experiences, progress, and the lessons I learn along the way not only helps me track my growth but also provides valuable insights to others who might be on a similar path.</p>
<h3 id="heading-the-beginning"><strong>The Beginning</strong></h3>
<p>Today marks Day Zero of my journey. I've set my sights on mastering data structures and full-stack development, and I'm starting from the crack of dawn. As the saying goes, "The journey of a thousand miles begins with a single step," and this blog is that very first step.</p>
<h3 id="heading-my-approach"><strong>My Approach</strong></h3>
<p>I plan to blog daily, sharing my thoughts, challenges, and small victories. Each day will bring new challenges, but I'm determined to embrace them as opportunities for growth.</p>
<h3 id="heading-connect-with-me"><strong>Connect with Me</strong></h3>
<p>If you'd like to connect with me and follow my journey on a more personal level, you can find me on LinkedIn <a target="_blank" href="https://www.linkedin.com/in/m-arun-kumar-0203-gmail/">here</a>. I'd love to connect with fellow learners, mentors, or anyone passionate about technology.</p>
<h3 id="heading-conclusion"><strong>Conclusion</strong></h3>
<p>I'm excited about what lies ahead, and I hope you are too! Whether you're a seasoned developer, a fellow learner, or someone simply curious about the world of programming, I invite you to join me on this exciting journey. Together, we'll explore the fascinating realms of data structures and full-stack development, one day at a time.</p>
<p>Stay tuned for Day One, where I'll share my first experiences and insights gained from day one. Also most importantly I will be sharing the resources which I will be using throughout my Journey. Until then, happy coding!</p>
<hr />
]]></content:encoded></item></channel></rss>