<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by BuddhiK on Medium]]></title>
        <description><![CDATA[Stories by BuddhiK on Medium]]></description>
        <link>https://medium.com/@lkprabha?source=rss-145e3e4b00b9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*AopAoyxquDKG2hfn</url>
            <title>Stories by BuddhiK on Medium</title>
            <link>https://medium.com/@lkprabha?source=rss-145e3e4b00b9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 03:23:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lkprabha/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Basic Linux Commands]]></title>
            <link>https://lkprabha.medium.com/basic-linux-commands-2f1c7ee07c0d?source=rss-145e3e4b00b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f1c7ee07c0d</guid>
            <category><![CDATA[terminal-commands]]></category>
            <category><![CDATA[linux-tutorial]]></category>
            <category><![CDATA[basic-linux-commands]]></category>
            <category><![CDATA[command-line-interface]]></category>
            <category><![CDATA[linux-commands]]></category>
            <dc:creator><![CDATA[BuddhiK]]></dc:creator>
            <pubDate>Tue, 14 Jan 2025 11:56:55 GMT</pubDate>
            <atom:updated>2025-01-16T04:18:48.861Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i9J1rU4rU2zQ-weuQKcfsw.png" /></figure><h3>What is Linux ?</h3><p>Linux is an <strong>open-source operating system</strong> that serves as the backbone for many different devices, from personal computers and servers to smartphones and embedded systems. It functions similarly to other operating systems like Windows and macOS, providing the essential interface between hardware and software so that applications can run efficiently.</p><h3>Linux Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*no2DHR7nnmCMi4qrEgXs1g.png" /><figcaption>image 01</figcaption></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — -<br>| User Applications |<br> — — — — — — — — — — — — — — — — — — — — — — — — -<br>| System Libraries |<br> — — — — — — — — — — — — — — — — — — — — — — — — -<br>| Shell |<br> — — — — — — — — — — — — — — — — — — — — — — — — -<br>| Linux Kernel |<br>| — Process Management — File Systems |<br>| — Memory Management — Networking |<br>| — Device Drivers — System Calls |<br> — — — — — — — — — — — — — — — — — — — — — — — — -<br>| Hardware |<br> — — — — — — — — — — — — — — — — — — — — — — — — -</p><h4>Hardware Layer</h4><p>This is the physical layer, which includes:</p><ul><li><strong>CPU (Central Processing Unit)</strong></li><li><strong>Memory (RAM)</strong></li><li><strong>Storage devices</strong></li><li><strong>Peripherals (keyboards, monitors, printers, etc.)</strong></li></ul><p>The Linux operating system interacts with these hardware components via the <strong>kernel</strong>.</p><h4>Kernel Layer</h4><p>The <strong>kernel</strong> is the core of the Linux operating system. It acts as a bridge between hardware and software. The kernel has several responsibilities:</p><ul><li><strong>Hardware Management</strong>: Communicates with and controls hardware devices.</li><li><strong>Process Management</strong>: Manages processes by allocating CPU time and memory.</li><li><strong>Memory Management</strong>: Controls the use of RAM and manages virtual memory.</li><li><strong>Device Drivers</strong>: Allows the kernel to interact with specific hardware components.</li><li><strong>File System Management</strong>: Manages how data is stored and retrieved.</li><li><strong>Networking</strong>: Handles data exchange between devices and networks.</li></ul><p>The kernel operates in <strong>kernel space</strong>, which is isolated from the user and application processes for security and stability.</p><h4>Shell Layer</h4><p>The <strong>shell</strong> is an interface between the user and the kernel. It allows users to execute commands and interact with the operating system. There are two types of shells:</p><ul><li><strong>Command-Line Shells</strong>: Examples include Bash, Zsh, and Fish, where users input text-based commands.</li><li><strong>Graphical Shells</strong>: Used in desktop environments like GNOME or KDE, offering a graphical user interface (GUI).</li></ul><h4>User Space</h4><p>This is where applications and user processes run. It is divided into two main categories:</p><h4>1. System Libraries</h4><ul><li>Provide reusable functions and tools that applications can use to perform specific tasks (e.g., accessing files, communicating with the network).</li><li>The most common library in Linux is the <strong>GNU C Library (glibc)</strong>.</li></ul><h4>2. User Applications</h4><ul><li>Programs or software that users interact with, such as web browsers, text editors, and media players.</li></ul><p>Applications communicate with the kernel indirectly via <strong>system calls</strong> provided by system libraries.</p><h3>General Knowlege Before We starts</h3><h4>What is the Command Line here ?</h4><p>When we talk about the command line, we are actually referring to the <strong>Shell</strong>. The shell is a program that receives commands typed on the keyboard and passes them to the operating system (OS) for execution. One popular shell program is <strong>Bash</strong>, which stands for “Bourne Again Shell.” It is an enhanced version of the original Unix Shell program, which was written by Steve Bourne.</p><h4>What Terminal Emulators ?</h4><p>In Linux, terminal emulators are software applications that provide a command-line interface (CLI) for interacting with the operating system. They emulate the functionalities of traditional hardware terminals and allow users to execute shell commands, run scripts, and manage the system. Terminal emulators are essential for system administration, development, and various technical tasks in Linux.</p><p>Common terminal emulators in Linux : GNOME, Konsole, xterm,xterm</p><h4>First Steps</h4><p>Launch the terminal emulator ! Once you open it up you will see some thing like this.</p><p>[user1@linuxbox ~ ]$</p><p>This is what we call a shell prompt. Now the terminal imulator is ready for take input.</p><p>If it is prompt with # sign rather than $ that means you have higher “supper user” privilages.</p><p>[user1@linuxbox~ ]#</p><p>In here</p><h4>User1</h4><ul><li>Represents the <strong>username</strong> of the person logged into the system.</li><li>In this case, User1 is the current user.</li></ul><h4>@</h4><ul><li>Separates the username (User1) from the hostname (linuxbox).</li><li>It indicates the format: username@hostname.</li></ul><h4>linuxbox</h4><ul><li>Refers to the <strong>hostname</strong> or name of the computer.</li><li>In this case, linuxbox is the name given to the system by the user or administrator.</li></ul><h4>~</h4><ul><li>Represents the <strong>current working directory</strong>.</li><li>The ~ symbol is shorthand for the user&#39;s <strong>home directory</strong> (e.g., /home/me).</li><li>If the user navigates to a different directory, this part of the prompt will display the full path (e.g., /usr/bin).</li></ul><h4>$</h4><ul><li>Indicates the type of user currently operating in the shell:</li><li>A <strong>dollar sign (</strong><strong>$)</strong> means the user is a <strong>regular user</strong> with limited permissions.</li><li>If the user were a <strong>root user</strong> (administrator), the prompt would display a <strong>hash symbol (</strong><strong>#)</strong> instead.</li></ul><h3>Navigation</h3><h4>Understand the filesystem tree</h4><p>The Linux filesystem is organized as a <strong>hierarchical tree structure</strong>, with the root directory (/) at the base. All files and directories stem from this root directory.</p><p>The first directory in the filesystem is called the root directory.The root directory contains files and subdirectories and so on.</p><p>note : Unlike the windows ,which has a seperate filesystem tree for each storage device ,Unix systems like Linux always have a single filesystem tree,regarrdless of how many drives or storage divices are attached to the computer.</p><p>File Hyrachy in windows</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*4n5QfDuMOcFFMLngwoI7EQ.png" /><figcaption>image 02</figcaption></figure><p>File Sytem in Linux</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*n8zmJ8bycjOqt9RD5kF1xA.png" /><figcaption>image 03</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UMwWyqDwAY1AsX9xVNRGrg.png" /><figcaption>image 04</figcaption></figure><h4>Current working directory — pwd</h4><p>pwd refers to the directory in the file system where the user is currently operating. It is the location where commands will be executed, files will be searched, or new files and directories will be created by default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*GCcJhVx5Pr7uYYJyHaYaYQ.png" /><figcaption>image 05</figcaption></figure><h4>Listing the contents in the directory -ls</h4><p>ls is used to list the contents of a directory. When you use the ls command without any options, it displays a list of files and directories present in the current working directory.Using cd helps you move around the file system quickly and efficiently, making it easier to find and manage files and directories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*eqSl-huDVCUvyxlT1ZlAPQ.png" /><figcaption>image 06</figcaption></figure><h4>Change the current working directory — cd</h4><p>cd is used to navigate through the file system by changing the current working directory to a specified path.</p><ul><li><strong>Absoulute path : </strong>A file or directory from the root directory (/). It starts from the root directory and includes all the directories in between.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*Puy9BJqhRuxJKdUNosE-yQ.png" /><figcaption>image 07</figcaption></figure><ul><li><strong>Relative path : </strong>A file or directory location relative to the current working directory. It does not start from the root but uses the current directory as the reference point.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*jyVds23_PL4XHXcWMOuvRw.png" /><figcaption>image 08</figcaption></figure><h4>What are those dots really doing ? ..</h4><p>cd .. is used to <strong>move up one level</strong> in the directory hierarchy, taking you to the parent directory of the current working directory.</p><p>In here</p><ul><li>cd — stands for <strong>Change Directory</strong>.</li><li>.. refers to the <strong>parent directory</strong>, which is one level above the current directory.</li></ul><p>Example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*xqmfyotDiji4ThL-_fSz1g.jpeg" /><figcaption>image 09</figcaption></figure><h3>Most commonly used commands you should know</h3><h3>1. Create folder — mkdir</h3><p>mkdir &lt;space&gt; &lt;Folder Name&gt;</p><p>Checking available files and folders in current location</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*euQH58RbPaO-7YrdNRM31A.jpeg" /><figcaption>image 10</figcaption></figure><p>Creating the folder named “Prabha” and then checking the location just to verify whether the folder has been created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*8_ml1inR7pgbN2PjocRxAQ.jpeg" /><figcaption>image 11</figcaption></figure><h3>2. Create text file</h3><h4><strong>2.1 touch command :</strong></h4><p>Will create empty text file.The touch command is used only to create an empty file; it doesn&#39;t open the file for editing. After running the touch filename.txt command, you don&#39;t need to exit because it does not leave you in an interactive editing mode. The command finishes immediately after execution.</p><p>touch &lt;textfilename.txt&gt;</p><ul><li>To edit the textfile you have created you can use cat, nano or vim commands to edit the content of the text file and you can save and exit via givving relevant commands accordingly.</li></ul><p>example: edit the created text file using touch command I have used nano&lt;textfilename.txt&gt;. Then I have edit my text file.So to save I pressed Ctrl+O to save and Ctrl+X to close and exit the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*boizneKk2pBJy3Fl-l53Pw.png" /><figcaption>image 12</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*zFKzzSn4ZtO6VCEWCZLxwg.png" /><figcaption>image 13</figcaption></figure><h4><strong>2.2 echo command</strong></h4><p>The echo command in Linux is used to display a line of text or a string in the terminal.</p><ul><li><strong>2.2.1 Display a Message or Text — echo “text you want to display”</strong></li><li>Display Messge or a Text</li></ul><p>echo “&lt;Text you needed to display in the terminal&gt;”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*O-u2Q_DI37ecyq5yMxca7w.png" /><figcaption>image 14</figcaption></figure><h4><strong>2.2.2 Write Text to a File — echo “</strong>text you want to save to a text file” &gt; textfilename.txt</h4><ul><li>Write Text to a File — echo “This is line 1” &gt; echofile.txt</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*_RD1z3u6z_D5HCVdgVLakQ.jpeg" /><figcaption>image 15</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*wOeFqU-AlAdQP9AsWJcuEw.png" /><figcaption>image 16</figcaption></figure><h4>2.2.3 Append to a file — echo “text you want to append to a text file” &gt;&gt; textfilename.txt</h4><ul><li>Append to a File — echo “This is line 2” &gt;&gt; echofile.txt</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*wSKy1e3lTzQV7ib0ZA7IiA.png" /><figcaption>image 17</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*hZxCtrUfTh7Dhpfqj9Zy3A.png" /><figcaption>image 18</figcaption></figure><p>Echo command is far more than that and will explain the usage in upcoming topic.</p><h4>2.3. cat command</h4><p>Following cat command will allow you to write text to the givven text file.</p><p>cat &gt; filename.txt</p><p>Then you can start writing text in to the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*u2OEjRcmxp5Vpt6y1lEEnw.png" /><figcaption>image 19</figcaption></figure><p>After you finished you can simply press Ctrl + D to exit.</p><p>View and ammend the text file as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*9l96M2f8w5DNGV0OynKAPQ.png" /><figcaption>image 20</figcaption></figure><h3>3. Copy files or directories</h3><p><strong>3.1 Copy a file to another directory</strong>:</p><p>cp &lt;copeing file name&gt; &lt;path where you need to locate the file copy&gt;</p><p>cp document.txt /home/user/documents/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*DIvcbu-ec2h0hgdfrqXWfg.png" /><figcaption>image 21</figcaption></figure><p><strong>3.2 Copy a directory and its contents</strong>:</p><p>cp <strong>-r</strong> &lt;From Directory&gt; &lt;to Directory&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*0wb7NUGKzTPeePW1eY1E9g.png" /><figcaption>image 22</figcaption></figure><p><strong>3.3 Copy and rename a file</strong>:</p><p>cp &lt;file name&gt; &lt;path/&lt;new name for rename&gt;</p><p>Extra:</p><p>Important Options</p><ol><li>-i: Interactive mode; prompts before overwriting.</li><li>-r: Recursive copy for directories.</li><li>-a: Archive mode; preserves file attributes and directory structure.</li><li>-u: Copy only when the source file is newer than the destination file or if the file doesn’t exist at the destination.</li><li>-v: Verbose mode; shows detailed output during the copy process.</li></ol><h3>4. Move or rename files or directories</h3><h4>4.1 <strong>Move a File to Another Directory</strong>:</h4><p>mv &lt;file1.txt&gt;&lt; path to destination&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*0Q4U1KfNsF2KhSxBxBd33A.png" /><figcaption>image 23</figcaption></figure><h4>4.2 Move Multiple Files :</h4><p>mv &lt;file1.txt&gt;&lt;file2.txt&gt; &lt;path to destination&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*t-kIEQLvBqLFCQL9Nyv_7A.png" /><figcaption>image 24</figcaption></figure><h4>4.3: Options for moving</h4><p><strong>Prompt Before Overwriting</strong>: Use the -i (interactive) flag to prompt before overwriting:</p><p>mv -i file1.txt /path/to/destination/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*WkXp-tOqakyO58mC_jQXoQ.png" /><figcaption>image 25</figcaption></figure><p><strong>Force Overwrite Without Prompt</strong>: Use the -f (force) flag to overwrite without prompting:</p><p>mv -f file1.txt /path/to/destination/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*xxS4G3FSHkGymBKedY-6SQ.png" /><figcaption>image 26</figcaption></figure><p><strong>Verbose Output</strong>: Use the -v (verbose) flag to display detailed output:</p><p>mv -v file1.txt /path/to/destination/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*d1XLMzZlUvQKd62HgAaVWw.png" /><figcaption>image 27</figcaption></figure><h3>5. Remove files or directories</h3><p>rm &lt;filename&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*TDFgIGxrg09qXGW1_SdCxg.jpeg" /><figcaption>image 28</figcaption></figure><p>Before you remove a file or directory just good to know below options.</p><ul><li><strong>Forceful deletion</strong>: Be cautious when using rm -f or rm -rf as it bypasses prompts and can delete important files or directories.</li><li><strong>Recursive deletion</strong>: The -r flag is required to remove directories and their contents.</li><li><strong>Safety tip</strong>: Always double-check the command before pressing Enter, especially when using wildcards like *.</li></ul><p>Examples:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*Eh8lJ-dIR3TxL_Mxja19Fg.png" /><figcaption>image 29</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*tDxt4ZT_edqTHUwvGUVzAg.png" /><figcaption>image 30</figcaption></figure><h3>6. Change file permissions</h3><h4>Understanding the file permssion</h4><p>rwxr-xr —</p><p>Permissions are represented as:</p><ul><li><strong>r</strong>: Read</li><li><strong>w</strong>: Write</li><li><strong>x</strong>: Execute</li><li><strong>- </strong>: No permission</li><li><strong>First character</strong>: File type (- for files, d for directories).</li><li><strong>Next three characters</strong>: Permissions for the <strong>owner</strong> (user).</li><li><strong>Next three characters</strong>: Permissions for the <strong>group</strong>.</li><li><strong>Last three characters</strong>: Permissions for <strong>others</strong> (everyone else).</li></ul><h4>6.1 View permision</h4><p>ls -l &lt;file name&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*xkDgMh5Ga11Ms_nCi8Dp4A.png" /><figcaption>image 31</figcaption></figure><h4>6.2 Add Permission — chmod u+x &lt;filename&gt;</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*-xvnErD52vK5MwOxar3J2g.png" /><figcaption>image 32</figcaption></figure><h4>6.3 Add Excactlly Permission — chmod o=r &lt;filename&gt;</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*PjmWrMwTfaseETgsxuiJEA.png" /><figcaption>image 33</figcaption></figure><h4>6.4 Remove Permission -chmod g-w &lt;filename&gt;</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*GkQ70O0oRvJhSLQoDbt6Hg.png" /><figcaption>image 34</figcaption></figure><h4>6.5 <strong>Give All Permissions to Everyone</strong>: chmod a+rwx &lt;filename&gt;</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*Ei1TzdRNM8YsCu9dhlg_VA.png" /><figcaption>image 35</figcaption></figure><h4>6.6 Changing Permissions Recursively</h4><p>chmod -R 755 &lt;path to directory&gt;</p><h4>6.7 Using Numeric Mode</h4><p>In numeric mode, permissions are represented as a three-digit number (octal):</p><ul><li><strong>Read</strong> = 4</li><li><strong>Write</strong> = 2</li><li><strong>Execute</strong> = 1</li></ul><p>Add these values to calculate permissions:</p><ul><li>rwx = 4 + 2 + 1 = 7</li><li>rw- = 4 + 2 + 0 = 6</li><li>r-- = 4 + 0 + 0 = 4</li></ul><p>Format: chmod [owner][group][others] &lt;filename&gt;</p><p>example :</p><p>a) Set permission to everyone -chmod 777 &lt;filename&gt;</p><p>b) Set Owner to Read/Write, Group to Read, Others to No Access —</p><p>chmod 640 &lt;filename&gt;</p><h3>7. Change file ownership — chown</h3><h4>7.1 Verfying ownership</h4><p>ls -l &lt;filename&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*ViEf6GJJnR0R2Z9b-58DEg.png" /><figcaption>image 36</figcaption></figure><h4>7.2 Change the Owner of a File</h4><p>chown newuser file.txt</p><h4><strong>7.3 Change Both Owner and Group</strong>:</h4><p>chown newuser:newgroup file.txt</p><h4><strong>7.4 Change Only the Group</strong>:</h4><p>Use a colon without specifying a user:</p><p>To change only group ownership without using chown, you can use the chgrp command:chgrp newgroup file.txt</p><p>chown :newgroup file.txt</p><h4>7.5 Options for chown</h4><ul><li><strong>Change Ownership Verbosely</strong>: Use the -v option to display changes:</li></ul><p>chown -v alice file.txt</p><ul><li><strong>Preserve Permissions While Changing Ownership</strong>: The -c option reports changes without verbose output for every file:</li></ul><p>chown -c alice:developers file.txt</p><ul><li><strong>Suppress Errors</strong>: Use the --silent or -f option to suppress error messages:</li></ul><p>chown -f alice file.txt</p><h4>7.6 Permissions Required</h4><ul><li>You must have <strong>root privileges</strong> or be the <strong>file owner</strong> to use chown. Use sudo if necessary</li></ul><p>sudo chown alice file.txt</p><h4>Practical examples</h4><p>Example 01: Set Owner to bob and Group to staff -</p><p>chown bob:staff report.txt</p><p>Example 02: Set Owner for All Files in a Directory —</p><p>chown -R bob /home/bob/documents</p><p>Example 03:Set Group for a File</p><p>chown :engineers script.sh</p><h3>8. Add new Users and Remove Users</h3><p><strong>sudo</strong> <strong>adduser</strong> &lt;newuser&gt;</p><p><strong>sudo</strong> <strong>deluser</strong> &lt;username&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*XYR69bwZ4z-4uqBMCIAUsg.png" /><figcaption>image 37</figcaption></figure><h3>8. Display disk space usage</h3><p>df [options] [file_or_directory]</p><p><strong>8.1 Display Disk Usage for All Filesystems -df</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*X9jQqiEIEy1Kq9V_NJwrQA.png" /><figcaption>image 38</figcaption></figure><p>8.2 <strong>Display in Human-Readable Format</strong>: Use the -h option to show sizes in human-readable units (KB, MB, GB):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*5K6VFy8WgGRk5G7sFzaPxQ.png" /><figcaption>image 39</figcaption></figure><p><strong>8.3 Check Disk Usage for a Specific Directory</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*b9wV0pjJFebJQqXA0UO-yQ.png" /><figcaption>image 40</figcaption></figure><p><strong>8.4 Display Information in Inodes</strong>: Use the -i option to show inode usage instead of disk space:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*6N4ncwGDG7qAB2duNKbEVg.png" /><figcaption>image 41</figcaption></figure><p><strong>8.5 Include Filesystems of Specific Types</strong>: Use the -t option to filter by filesystem type (e.g., ext4):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*vz5knjw7ufW4V4kSb7ULqw.png" /><figcaption>image 42</figcaption></figure><p><strong>8.6 Exclude Filesystems of Specific Types</strong>: Use the -x option to exclude certain filesystem types (e.g., tmpfs):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*Bak5IaF1tI9WZoQC0JjJkA.png" /><figcaption>image 43</figcaption></figure><p><strong>8.7 Show Filesystem Type</strong>: df -T</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*ij3VQILlhWQjk0da4cxdMA.png" /><figcaption>image 44</figcaption></figure><h4>8.8 Command for Specific File/Folder Usage -du</h4><p><strong>8.8.1 Basic disk usage</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*NOmonLsUAC1siGqSP1ckTw.png" /><figcaption>image 45</figcaption></figure><p><strong>8.8.2 Basic disk usage in Human readable format</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*dl0jmKGiGc90nUyf9PZejw.png" /><figcaption>image 46</figcaption></figure><p><strong>8.8.3 Summerise total disk usage</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*c2YVpFRGI1-PGgG7VI8O_g.png" /><figcaption>image 47</figcaption></figure><h3>9. Display information about active processes</h3><h4>9.1 ps Command</h4><p><strong>9.1.1 List all processes — ps -e</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*4xmBt_CWzpRIH8QBVx50IA.png" /><figcaption>image 48</figcaption></figure><p><strong>9.1.2 Detailed process information — ps -ef</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*c8UN9d4TMCR5dIoYGyvpZg.png" /><figcaption>image 49</figcaption></figure><h4>9.2 top Command</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*U8wwL4Wfpk9lxxhi6f1NNg.png" /><figcaption>image 50</figcaption></figure><p>9.3 htop Command</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*N-1n-H5KfzfVpmmuymalyQ.png" /><figcaption>image 51</figcaption></figure><h3>10. Terminate a process</h3><h4>10.1 Using kill Command</h4><p>steps :</p><ol><li><strong>Find the PID of the Process</strong>: Use ps, top, or pgrep to identify the process ID (PID)</li><li>send the kill command</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*wRyXsoyqAmm-h1fVG9cl9w.png" /><figcaption>image 52</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*JWUgWsWeuIVTZ5VgfiQIDw.jpeg" /><figcaption>image 53</figcaption></figure><p>10.1.1 Kill by User</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*xrhji_8EWmCW5hUFY1pLDQ.png" /><figcaption>image 54</figcaption></figure><p>10.1.2 Kill by Port</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*dURq_PO4NYJfM6vafveCwg.png" /><figcaption>image 55</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*XgXJ9xeUing1EIxieHc5nw.png" /><figcaption>image 56</figcaption></figure><h4>10.2 Using pkill Command</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*xYDa0o6HVhvnvXYnJGgYSQ.png" /><figcaption>image 57</figcaption></figure><h4>10.3 Using killall Command</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*8QKnuHBgsUTyoE3CcusmCw.png" /><figcaption>image 58</figcaption></figure><p>Example 01 : <strong>Kill a process by name- </strong>pkill -9 apache2</p><p>Example 02 : Force kill a process using its PID — kill -9 9876</p><p>Example 03 : Kill all instances of a program- killall firefox</p><p>Example 04 :Kill processes owned by a specific user — pkill -u john</p><h3>11. Display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*fp4FPfj5k-wNZ0ecsuISUA.jpeg" /><figcaption>image 59</figcaption></figure><h4>11.1 The netstat command provides comprehensive network-related information.net stat command</h4><p>Step 01: Install netstat if not available with sudo install netstat</p><p>Step 02: netstat command</p><ul><li>Display Active Network Connections — netstat</li><li>Show Routing Tables- netstat -r</li><li>Display Interface Statistics- netstat -i</li><li>Show Masquerade Connections- netstat -M</li><li>Display Multicast Group Memberships — netstat -g</li></ul><h4>11.2 Using ss Command</h4><ul><li>Display Active Network Connections — ss</li><li>Show Listening Ports -ss -l</li><li>View All Sockets (TCP and UDP)- ss -tua</li><li>Display Process Information- ss -p</li></ul><h4>11.3 Using ip Command</h4><ul><li><strong>Display Network Interfaces — </strong>ip link show</li><li>Show IP Addresses- ip addr show</li><li>Display Routing Table- ip route show</li><li>View Multicast Addresses- ip maddr show</li></ul><h4>11.4 Using the ifconfig Command</h4><ul><li>provides information about network interfaces.</li><li>If ifconfig is unavailable, install net-tools as shown above.</li></ul><h4>11.5 nmcli Command</h4><ol><li><strong>Display Network Status — </strong>nmcli general status</li><li>Show Active Connections- nmcli connection show</li></ol><h3>12. Test network connectivity</h3><ul><li><strong>ping — </strong>ping &lt;hostname_or_IP&gt;</li><li><strong>traceroute — </strong>traceroute &lt;hostname_or_IP&gt;</li><li><strong>curl-</strong> curl &lt;URL&gt;</li><li><strong>wget- </strong>wget &lt;URL&gt;</li><li><strong>telnet- </strong>telnet &lt;hostname_or_IP&gt; &lt;port&gt;</li><li><strong>naslookup- </strong>nslookup &lt;hostname&gt;</li><li><strong>ss- </strong>ss -tua</li></ul><h3>13. Securely connect to another machine over the network</h3><p>First you have to ensure whether ssh installed in both local and remote machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qHuOD6ZsngnDC9UWtDKcAw.jpeg" /><figcaption>image 60</figcaption></figure><h3>Real-World Examples:</h3><ol><li><strong>Access a remote server</strong>: ssh admin@server.example.com to log into the server securely.</li><li><strong>Copy files to a remote machine</strong>: scp report.pdf</li></ol><p>http://user@192.168.1.5/home/user/docs/</p><ol><li><strong>Create an SSH key for password-less login</strong>: Use ssh-keygen to generate a key, then ssh-copy-id to add it to the remote server.</li><li><strong>Transfer large directories</strong>: Use rsync for efficient and secure directory synchronization.</li></ol><h3>14. Manage system services</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*1q5hdwYqmO7IndjV6MzGKA.jpeg" /><figcaption>image 61</figcaption></figure><h3>15. View system logs</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*-wkmpmHLQvY1QFAa2-sWSA.jpeg" /><figcaption>image 62</figcaption></figure><h3>16. Monitor system processes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fleiiuU8lWUNA7uOUsoq4w.jpeg" /><figcaption>image 63</figcaption></figure><p>Resources : “The Linux Command Line” by Williams E.Shotts Jr, ChatGPT</p><p><em>Special thanks to my VU lecturer, Jimmy Mathew, for providing insightful resources and guidence, and to HelloMonday career coach, Katie Peterson, for her encouragement throughout the Digital Jobs Program.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f1c7ee07c0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Oracle Certified Java Foundation Associate — 1Z0–811 — Exam Topic Discussion]]></title>
            <link>https://lkprabha.medium.com/oracle-certified-java-foundation-associate-1z0-811-exam-topic-discussion-a7f07e8077c9?source=rss-145e3e4b00b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7f07e8077c9</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[oracle-certification]]></category>
            <category><![CDATA[oracle-certified-training]]></category>
            <category><![CDATA[1z0-811-exam-dumps]]></category>
            <dc:creator><![CDATA[BuddhiK]]></dc:creator>
            <pubDate>Sun, 24 Mar 2024 22:49:13 GMT</pubDate>
            <atom:updated>2024-09-15T23:52:31.869Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jx_GxD_lW7Rgmdpe40LZcA.png" /></figure><h3>Oracle Certified Java Foundation Associate — 1Z0–811 — Exam Topic Discussion</h3><h3>1. What Is Java?</h3><h4>1.1. Describe the features of Java</h4><p>Java is a versatile and widely-used programming language that has evolved over the years.</p><ol><li><strong>Simple and Easy to Learn:</strong></li></ol><p>Java was designed to be beginner-friendly and has a syntax that is similar to other C-based languages like C++ and C#. It avoids complex features, such as explicit pointers and operator overloading, making it easier for developers to learn and use.</p><p><strong>2. Object-Oriented Programming (OOP):</strong></p><p>Java is a fully object-oriented programming language, supporting principles such as encapsulation, inheritance, and polymorphism. This allows for the creation of modular and reusable code.</p><p><strong>3. Platform Independence (Write Once, Run Anywhere — WORA):</strong></p><p>Java programs are compiled into an intermediate form called bytecode, which can be executed on any device with a Java Virtual Machine (JVM). This platform independence is a key feature, enabling Java applications to run on various platforms without modification.</p><p><strong>4. Automatic Memory Management (Garbage Collection):</strong></p><p>Java incorporates automatic memory management through a garbage collector. This helps developers avoid manual memory management and reduces the risk of memory leaks.</p><p><strong>5. Multithreading:</strong></p><p>Java provides built-in support for multithreading, allowing concurrent execution of multiple threads within the same program. This feature is particularly useful for developing scalable and responsive applications.</p><p><strong>6. Rich Standard Library:</strong></p><p>Java comes with a comprehensive standard library (Java API) that provides a wide range of pre-built classes and methods for various tasks, from data structures and networking to file handling and graphical user interface (GUI) development.</p><p><strong>7. Security:</strong></p><p>Java has built-in security features to protect against potential threats, such as viruses and malware. The Java Runtime Environment (JRE) includes a security manager and supports features like sandboxing for applets.</p><p><strong>8. Distributed Computing (RMI, Networking):</strong></p><p>Java supports distributed computing through features like Remote Method Invocation (RMI) and networking libraries, making it suitable for building scalable and distributed systems.</p><p><strong>9. Dynamic and Extensible:</strong></p><p>Java supports dynamic loading of classes and extensibility through interfaces and abstract classes. This allows for flexible and modular code design.</p><p><strong>10. Community Support:</strong></p><p>Java has a large and active developer community, contributing to numerous open-source projects, frameworks, and libraries. This support enhances the ecosystem and facilitates collaboration among developers.</p><p><strong>11.Robust Exception Handling:</strong></p><p>Java has a robust exception-handling mechanism that helps manage runtime errors and allows developers to write more reliable and fault-tolerant code.</p><p><strong>12. Annotations (Metadata):</strong></p><p>Java supports annotations, which allow developers to embed metadata within the source code. Annotations are widely used in frameworks like Spring for configuration and customization.</p><p>These features contribute to Java’s popularity and widespread use in a variety of domains, including web development, enterprise applications, mobile app development (Android), and more.</p><h4>1.2 Describe the real-world applications of Java</h4><ol><li><strong>Web Development:</strong></li></ol><ul><li>Enterprise-level Web Applications: Java, particularly through frameworks like Spring and Java EE (Enterprise Edition), is widely used for developing large-scale, enterprise-level web applications.</li><li>Servlets and JSP: Java Servlets and JavaServer Pages (JSP) are used to build dynamic web pages and handle server-side processing.</li></ul><p><strong>2. Mobile Applications (Android Development):</strong></p><ul><li>Android Apps: Java is the primary language for Android app development. Android Studio, the official IDE for Android development, supports Java alongside Kotlin.</li></ul><p><strong>3. Enterprise Applications:</strong></p><ul><li>Enterprise Resource Planning (ERP) Systems: Java is often used to build robust and scalable ERP systems that handle various business processes.</li><li>Customer Relationship Management (CRM) Systems: Java is utilized in building CRM applications that manage interactions with customers.</li></ul><p><strong>4. Desktop Applications:</strong></p><ul><li>Swing and JavaFX: Java provides GUI libraries like Swing and JavaFX for developing cross-platform desktop applications with rich user interfaces.</li></ul><p><strong>5. Scientific and Research Applications:</strong></p><ul><li>Scientific Computing: Java is used in scientific research applications due to its portability and ability to handle complex computations.</li><li>Data Analysis and Visualization: Java is employed in applications for data analysis and visualization, especially in fields like bioinformatics and geospatial analysis.</li></ul><p><strong>6. Middleware Products:</strong></p><ul><li>Message-Oriented Middleware (MOM): Java is used in developing middleware products like Apache Kafka, RabbitMQ, and ActiveMQ, which facilitate communication between distributed systems.</li></ul><p><strong>7. Cloud Computing:</strong></p><ul><li>Cloud Infrastructure and Services: Java is used in various cloud platforms and services. Many cloud-based applications, especially those deployed on platforms like Amazon Web Services (AWS) or Google Cloud Platform (GCP), are written in Java.</li></ul><p><strong>8. Big Data Technologies:</strong></p><ul><li>Apache Hadoop and Apache Spark: Java is used in big data processing frameworks like Apache Hadoop and Apache Spark, enabling the efficient processing of large datasets.</li></ul><p><strong>9. Financial Services:</strong></p><ul><li>Banking Systems: Java is widely used in developing banking systems, including online banking and financial transaction processing systems.</li><li>Risk Management Systems: Java is employed in developing risk analysis and management applications in the financial sector.</li></ul><p><strong>10. Internet of Things (IoT):</strong></p><ul><li>Embedded Systems: Java is used in developing applications for IoT devices, providing a platform-independent language for embedded systems.</li></ul><p><strong>11. Game Development:</strong></p><ul><li>Mobile and Web Games: Java is used in game development, particularly for mobile and web-based games. Libraries like LibGDX support cross-platform game development.</li></ul><p><strong>12. Educational Applications:</strong></p><ul><li>Learning Platforms: Java is used in educational software and learning management systems due to its ease of use and platform independence.</li></ul><p>Java’s versatility, performance, and robustness make it suitable for a wide range of applications, contributing to its enduring popularity in the software development landscape.</p><h3>2. Java Basics</h3><p>2.1. Describe the Java Development Kit (JDK) and the Java Runtime Environment (JRE)</p><p><a href="https://lkprabha.medium.com/jvm-jre-jdk-surface-knowledge-b05a64eea71c">JVM, JRE, JDK Surface Knowledge</a></p><p>2.2. Describe the components of object-oriented programming</p><p><a href="https://lkprabha.medium.com/oop-concepts-java-e95148fefeab">OOP Concepts -(Java)</a></p><p>2.3. Describe the components of a basic Java program</p><p>A basic Java program consists of several components that work together to perform a specific task. Here are the key components of a basic Java program:</p><p><strong>Package Declaration:</strong></p><ul><li>A package is a way to organize related classes into a single namespace. The package statement is optional but if used, it must be the first statement in a Java file.</li></ul><p><strong>Import Statements:</strong></p><ul><li>The import statement is used to bring in classes from other packages so that they can be used in the current program</li></ul><p><strong>Class Declaration:</strong></p><ul><li>The class keyword is used to declare a class. A Java program must have at least one class, and the name of the class must match the name of the file.</li></ul><p><strong>Main Method:</strong></p><ul><li>The main method is the entry point of a Java program. It is where the program starts executing. The public static void main(String[] args) method signature is the standard format.</li></ul><p><strong>Statements and Expressions:</strong></p><ul><li>Inside the main method, you write statements and expressions that define the logic of your program. Statements can include variable declarations, method calls, loops, conditionals, and other control flow structures.</li></ul><p><strong>Comments:</strong></p><ul><li>Comments are used to provide additional information about the code. They are ignored by the compiler.</li></ul><p><strong>Variables:</strong></p><ul><li>Variables are used to store and manipulate data in a program. They must be declared with a specific type before use.</li></ul><p><strong>Data Types:</strong></p><ul><li>Java has various data types, such as int, double, boolean, and more, that define the type of data a variable can hold.</li></ul><p><strong>Methods:</strong></p><ul><li>Methods are blocks of code that perform a specific task. They can be called from the main method or other methods.</li></ul><p><strong>Console Output:</strong></p><ul><li>The System.out.println statement is commonly used to print output to the console.</li></ul><p><strong>Input Handling (Optional):</strong></p><ul><li>Java provides classes like Scanner for reading input from the console or other sources.</li></ul><p>Full example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s1Wccfq4uHg5hrkPYn72aw.png" /></figure><h4>2.4. Compile and execute a Java program</h4><h4>Compile</h4><ol><li>Write Your Java Code:</li></ol><ul><li>Use a text editor or an Integrated Development Environment (IDE) to write your Java code. Save the file with a .java extension.</li></ul><p>2. Open a Terminal or Command Prompt and navigate to the Directory Containing Your Java File.</p><p>ex : cd path/to/your/java/file</p><p>3. Compile the Java Code.</p><p>ex : <strong>javac</strong> HelloWorld.java</p><h4>Execute :</h4><p>Run the Compiled Program.</p><p>ex : <strong>java </strong>HelloWorld</p><h3>3. Basic Java Elements</h3><h4>3.1. Identify the conventions to be followed in a Java program</h4><p>In Java programming, there are several conventions and best practices that developers typically follow to write clean, readable, and maintainable code. Adhering to these conventions makes the code more consistent and helps improve collaboration among developers. Here are some key conventions to be followed in a Java program:</p><ol><li>Package Names: Use lowercase letters for package names to maintain consistency and improve readability. For example: com.example.myproject.</li></ol><p>2. Class Names: Use CamelCase for class names. Start each word with an uppercase letter. For example: MyClass, PersonDetails, etc.</p><p>3. Method Names: Use camelCase for method names. Start with a lowercase letter and capitalize the first letter of each subsequent concatenated word. For example: calculateArea(), getUserInfo(), etc.</p><p>4. Variable Names: Use camelCase for variable names. Start with a lowercase letter and capitalize the first letter of each subsequent concatenated word. For example: totalAmount, userName, etc.</p><p>5. Constants: Use uppercase letters with underscores to separate words for constants. For example: MAX_VALUE, PI_VALUE, etc.</p><p>6. Indentation: Use consistent indentation to make the code structure visually clear. The standard is often four spaces per indentation level.</p><p>7. Braces (Curly Braces): Place opening braces { on the same line as the statement and closing braces } on a new line.</p><p>8. Line Length: Keep lines of code reasonably short (commonly 80–120 characters) to enhance readability.</p><p>9. Comments: Use comments to explain complex parts of the code, especially if the logic might not be immediately apparent. Follow a consistent commenting style.</p><p>10. Javadoc: Use Javadoc comments for documenting classes and methods. This helps generate documentation automatically and improves code understanding.</p><p>11. Naming Conventions for Boolean Variables: Use names that suggest a boolean meaning, such as isDone, hasValue, etc.</p><p>12. Whitespace: Use whitespace judiciously to enhance readability. Add spaces around operators and after commas.</p><p>13. Enum Types: Use uppercase letters for enum type names and constants within the enum.</p><p>14. Class File Organization: Organize your class files in a clear and logical manner. Group related classes together.</p><p>15. Exception Handling: Follow consistent exception handling practices. Use meaningful exception names and provide helpful error messages.</p><p>16. Avoid Magic Numbers: Avoid using magic numbers (hardcoded numerical constants) in your code. Use named constants or variables with meaningful names.</p><p>17. Avoid Unnecessary Code: Remove unnecessary code and imports. Keep your codebase clean and focused.</p><p>Adhering to these conventions helps create code that is more readable, maintainable, and consistent, making it easier for both the original developer and other team members to understand and work with the codebase. It also aligns with Java’s coding standards and community practices.</p><h4>3.2. Use Java reserved words</h4><p>In Java, reserved words, also known as keywords, are words that have predefined meanings and cannot be used as identifiers (e.g., variable names, class names, method names) within the program. These reserved words are part of the Java language specification and serve specific purposes in the language syntax, structure, and functionality. Here are some important Java reserved words:</p><ol><li>Primitive Data Types:</li></ol><ul><li>boolean: Represents a boolean value (true or false).</li><li>byte: Represents an 8-bit signed integer.</li><li>short: Represents a 16-bit signed integer.</li><li>int: Represents a 32-bit signed integer.</li><li>long: Represents a 64-bit signed integer.</li><li>float: Represents a 32-bit floating-point number.</li><li>double: Represents a 64-bit floating-point number.</li><li>char: Represents a 16-bit Unicode character.</li></ul><p>2. Control Flow Statements:</p><ul><li>if: Introduces a conditional statement.</li><li>else: Part of the conditional statement for the &quot;false&quot; branch.</li><li>switch: Introduces a switch statement for multiple branches based on a value.</li><li>case: Defines a branch in a switch statement.</li><li>default: Defines the default branch in a switch statement.</li><li>while: Introduces a while loop.</li><li>do: Introduces a do-while loop.</li><li>for: Introduces a for loop.</li><li>break: Exits a loop or switch statement.</li><li>continue: Skips the rest of the current iteration and continues with the next one.</li><li>return: Exits a method and optionally returns a value.</li><li>throw: Throws an exception.</li><li>try: Introduces a try block for exception handling.</li><li>catch: Defines a catch block for handling exceptions.</li><li>finally: Defines a block of code to be executed after a try/catch block, regardless of whether an exception is thrown.</li></ul><p>3. Modifiers:</p><ul><li>public: Specifies that a class, method, or field can be accessed from anywhere.</li><li>private: Specifies that a class, method, or field can only be accessed within its own class.</li><li>protected: Specifies that a method or field can only be accessed within its own package or by subclasses.</li><li>static: Specifies that a method or field belongs to the class rather than an instance of the class.</li><li>final: Specifies that a variable, method, or class cannot be further modified or extended.</li><li>abstract: Specifies that a class or method is abstract and cannot be instantiated or must be implemented by subclasses.</li><li>native: Specifies that a method is implemented in native code (not in Java) using JNI (Java Native Interface).</li><li>synchronized: Specifies that a method can be accessed by only one thread at a time.</li><li>transient: Specifies that a variable should not be serialized during object serialization.</li><li>volatile: Specifies that a variable may be modified by multiple threads.</li></ul><p>4. Class and Object Declarations:</p><ul><li>class: Declares a class.</li><li>interface: Declares an interface.</li><li>extends: Specifies the superclass or interface that a class or interface extends.</li><li>implements: Specifies the interfaces that a class implements.</li><li>this: Refers to the current instance of an object.</li><li>super: Refers to the superclass of a class.</li></ul><p>5. Packages:</p><ul><li>package: Declares a package.</li><li>import: Imports classes, interfaces, or packages.</li></ul><p>6. Miscellaneous:</p><ul><li>new: Creates a new instance of a class.</li><li>instanceof: Tests whether an object is an instance of a specific class or interface.</li></ul><p>These reserved words play a crucial role in defining the structure and behavior of Java programs. They are an integral part of the Java language syntax, and using them correctly is essential for writing valid and functional Java code.</p><h4>3.3. Use single-line and multi-line comments in Java programs</h4><p>In Java, comments are used to provide explanatory notes within the code. Comments are ignored by the Java compiler and do not affect the execution of the program. They serve as a form of documentation and help improve the readability and understanding of the code. Java supports both single-line and multi-line comments.</p><p><strong>Single-Line Comments:</strong></p><p>Single-line comments are used to annotate a single line of code. Anything following // on a line is treated as a comment and is ignored by the compiler.</p><p>example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UVvDlE3rXlH_gN2ogx0WSg.png" /></figure><p>In the example above, both comments after the // are single-line comments. They provide additional information about the code on the same line.</p><p><strong>Multi-Line Comments:</strong></p><p>Multi-line comments are used to annotate multiple lines of code. Anything between /* and */ is treated as a comment block, and all content within the block is ignored by the compiler.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ga3lxyTn8Z0dcfUYzmOKg.png" /></figure><p>In the example above, the content between /* and */ is a multi-line comment. This comment block provides more extensive explanations about the code within the block.</p><p><strong>Best Practices for Comments:</strong></p><ol><li>Be Clear and Concise: Comments should be clear and concise, providing just enough information to aid understanding without being overly verbose.</li></ol><p>2. Update Comments: Keep comments up-to-date. If the code changes, update the associated comments to reflect the current state of the code.</p><p>3. Avoid Redundant Comments: Avoid comments that merely restate the obvious. Focus on providing insights that are not immediately apparent from the code itself.</p><p>4. Use Javadoc for Documentation: For documenting classes, methods, and fields, consider using Javadoc comments. Javadoc comments start with /** and support additional documentation tags.</p><h4>3.4. Import other Java packages to make them accessible in your code</h4><p>In Java, the import statement is used to make classes or entire packages from other Java packages accessible in your code. This is especially useful when you want to use classes or functionalities from external libraries or packages. The import statement informs the compiler about the location of the classes you want to use.</p><p><strong>Importing a Specific Class:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*76uMpQENWLGwpqpGpBP4zw.png" /></figure><p>In this example, packageName is the name of the package containing the ClassName you want to use. By importing packageName.ClassName, you can refer to ClassName directly in your code without specifying the full package path each time.</p><p><strong>Importing All Classes from a Package:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R6iVUJ_83jDM-CR2esPrNA.png" /></figure><p>Here, the * wildcard is used to import all classes from the specified package (packageName). This allows you to use any class from that package without explicitly importing each class.</p><p><strong>Importing Static Members:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*izTZyfFi5YFad8wj-u_KPQ.png" /></figure><p>If a class has static methods or fields that you want to use without qualifying them with the class name, you can use the import static statement.</p><p><strong>Common Java Packages:</strong></p><ul><li>java.lang: Imported by default. It contains fundamental classes like String, Object, etc.</li><li>java.util: Provides utility classes and data structures like ArrayList, HashMap, etc.</li><li>java.io: Contains classes for input and output operations.</li><li>java.net: Provides classes for networking operations.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*erVZAjEKyXEkalOt-dYcYA.png" /></figure><p>In this example, ArrayList and HashMap are used from the java.util package.</p><p>When importing classes, it’s essential to know the correct package names and class names. Documentation and the official Java API are valuable resources for finding the necessary information about classes and their packages.</p><h4>3.5. Describe the java.lang package</h4><p>The java.lang package is a fundamental package in the Java Standard Library. Unlike other packages, the classes in <strong>java.lang are automatically imported into every Java program by default.</strong> This package contains fundamental classes and data types that are used in most Java programs.</p><ol><li>Object Class:</li></ol><p>The Object class is the root class for all Java classes. Every class in Java is a subclass of Object, either directly or indirectly. It provides essential methods such as toString(), equals(), and hashCode().</p><p>2. Primitive Data Types:</p><ul><li>The java.lang package includes classes representing primitive data types, such as Integer, Double, Boolean, etc. These classes provide utility methods for converting between primitive types and objects.</li></ul><p>3. String Class:</p><ul><li>The String class in java.lang represents a sequence of characters. It is widely used for manipulating and working with textual data.</li></ul><p>4. Math Class:</p><ul><li>The Math class provides a set of static methods for mathematical operations. It includes methods for basic arithmetic, exponentiation, logarithms, trigonometry, and more.</li></ul><p>5. System Class:</p><ul><li>The System class provides access to the system resources, including standard input, standard output, and error output. It also has methods for managing the garbage collector and obtaining information about the Java Virtual Machine (JVM).</li></ul><p>6. Thread Class:</p><ul><li>The Thread class is part of the core Java concurrency model. It provides methods for creating and managing threads, as well as coordinating their execution.</li></ul><p>7. Exception Classes:</p><ul><li>The java.lang package includes fundamental exception classes, such as RuntimeException and Exception, which serve as the base classes for all exceptions. It also includes the Error class for representing serious errors.</li></ul><p>8. ClassLoader Class:</p><p>The ClassLoader class is responsible for loading classes into the Java Virtual Machine (JVM). It is an integral part of the Java class-loading mechanism.</p><p>9. Runtime Class:</p><p>The Runtime class provides information about the runtime environment and allows the application to interface with the Java Virtual Machine.</p><h3>4. Working with Java Data Types</h3><h4>4.1.Declare and initialize variables including a variable using final</h4><p>In Java, you declare and initialize variables using a specific syntax. Variables are containers for storing data, and their type determines the kind of data they can hold. Additionally, you can use the final keyword to create constants or make a variable immutable once it has been assigned a value.</p><p><strong>Declare and Initialize Variables:</strong></p><p>To declare and initialize a variable, you specify the data type followed by the variable name and, optionally, an initial value. Here are some examples:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UK6lfJDlw2cDmck10FKmrA.png" /></figure><h4>Declare and Initialize Variables Without Initialization:</h4><p>You can declare a variable without providing an initial value, but you must assign a value before attempting to use the variable. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9z6E1PoMs0RFk1hJweES_Q.png" /></figure><h4>Declare and Initialize final Variables:</h4><p>The final keyword in Java is used to declare a constant or to indicate that a variable&#39;s value cannot be changed once it has been assigned. You can initialize a final variable at the time of declaration or in a constructor if it&#39;s an instance variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t9ZKobFgwaJC2Y2p0yU1QQ.png" /></figure><p>In these examples, PI_VALUE is a final variable that cannot be modified after its initial assignment. Similarly, MAX_VALUE is a final variable in a class, making it a constant that can be accessed using the class name (Constants.MAX_VALUE).</p><h4>4.2. Cast a value from one data type to another including automatic and manual promotion</h4><p>In Java, casting refers to the process of converting a value from one data type to another. Casting can be divided into two categories: automatic (implicit) casting and manual (explicit) casting. These mechanisms are used to handle data type conversions in a program.</p><p><strong>Automatic (Implicit) Casting/ Widening Casting:</strong></p><p>Automatic casting occurs when the conversion from one data type to another is performed by the compiler itself, and it’s considered safe because it is performed implicitly without any explicit instruction.</p><ul><li>byte -&gt; short -&gt; char -&gt; int -&gt; long -&gt; float -&gt; double</li></ul><p>For example, consider converting a smaller data type to a larger data type:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RACIBhBkPKO7405i1P0A0Q.png" /></figure><p>In this example, the int value intValue is automatically cast to a double when assigned to the doubleValue variable. This is safe because there is no loss of precision.</p><p><strong>Manual (Explicit) Casting:</strong></p><p>Manual casting is performed explicitly by the programmer when converting from a larger data type to a smaller data type, which may result in a loss of precision. To manually cast, you use parentheses along with the target data type.</p><ul><li>double -&gt; float -&gt; long -&gt; int -&gt; char -&gt; short -&gt; byte</li></ul><p>For example, consider converting a larger data type (double) to a smaller data type (int):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P7ut8Iqnr4yJv-gapEqHrg.png" /></figure><p>n this example, the double value doubleValue is manually cast to an int using (int). Keep in mind that manual casting may result in loss of fractional parts, and the result is truncated.</p><p><strong>Automatic and Manual Promotion:</strong></p><p>Automatic and manual promotion are terms used when working with mixed data types, particularly in arithmetic operations. Automatic promotion occurs when the operands of an operation have different data types, and the compiler automatically promotes the smaller data type to the larger data type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBaMdZ1b3QVod37M5MvMgQ.png" /></figure><p>In this example, the intValue is automatically promoted to a double before the addition operation.</p><p>On the other hand, manual promotion involves explicitly casting one or more operands to a common data type before performing an operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2y6XAeiyXUnQDVsHa4JLog.png" /></figure><h4>4.3. Declare and initialize a String variable</h4><p>In Java, a String is a class that represents a sequence of characters. To declare and initialize a String variable, you can use the following syntax:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FtAh1OeFEbJFZNbGa_LSsg.png" /></figure><p>In this course, will discuss the string futher in upcoming topics.</p><h3>5. Operator precedence and use of parenthesis</h3><p>Operator precedence in Java determines the order in which different operators are evaluated in an expression. The precedence rules ensure that expressions are evaluated correctly. Operators with higher precedence are evaluated before those with lower precedence. Parentheses can be used to override the default precedence and explicitly control the order of evaluation.</p><p>Operator precedence in Java determines the order in which different operators are evaluated in an expression. The precedence rules ensure that expressions are evaluated correctly. Operators with higher precedence are evaluated before those with lower precedence. Parentheses can be used to override the default precedence and explicitly control the order of evaluation.</p><p>Here’s a brief overview of operator precedence in Java:</p><ol><li>Postfix operators (e.g., expr++, expr--): Highest precedence</li><li>Unary operators (e.g., ++expr, --expr, +expr, -expr, !expr, ~expr):</li><li>Multiplicative operators (e.g., *, /, %):</li><li>Additive operators (e.g., +, -):</li><li>Shift operators (e.g., &lt;&lt;, &gt;&gt;, &gt;&gt;&gt;):</li><li>Relational operators (e.g., &lt;, &gt;, &lt;=, &gt;=, `instanceof):</li><li>Equality operators (e.g., ==, `!=):</li><li>Bitwise AND (&amp;):</li><li>Bitwise XOR (^):</li><li>Bitwise OR (|):</li><li>Logical AND (&amp;&amp;):</li><li>Logical OR (||):</li><li>Conditional (Ternary) operator (? :):</li><li>Assignment operators (e.g., =, +=, -=, *=, /=, %=): Lowest precedence</li></ol><p>ex :</p><p>int result = a + b * c;</p><p>In herehe multiplication (*) has higher precedence than addition (+), so b * c is evaluated first.</p><p>int result = (a + b) * c;</p><p>In this example, (a + b) is evaluated first because it is enclosed in parentheses, and then the result is multiplied by c. The use of parentheses makes the intent clear and avoids relying solely on operator precedence.</p><h4><strong>Postfix operators</strong></h4><ul><li><strong>Increment Operator (</strong><strong>++):</strong></li></ul><p>The increment operator (++) adds 1 to the current value of a variable.</p><p>example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a70eXBG0XMEF418NsVeX7A.png" /></figure><ul><li><strong>Decrement Operator (</strong><strong>--):</strong></li></ul><p>The decrement operator (--) subtracts 1 from the current value of a variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d0XiQVQRPMrG9CNow92B8A.png" /></figure><ul><li><strong>Prefix and Postfix Notation:</strong></li></ul><p><strong>Postfix Notation </strong>(x++ or y--): The current value of the variable is used, and then the variable is incremented or decremented.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*rVVOic5ahyIXg14J0DVGxQ.png" /></figure><p><strong>Prefix Notation</strong> (++x or --y): The variable is incremented or decremented first, and then the updated value is used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*C0DUaeBC5YQ-BhyNQ9zmFw.png" /></figure><h4>tilde (~)</h4><p>In Java, the tilde (~) operator is a bitwise complement operator. When applied to an operand, it performs a bitwise inversion, flipping each bit of the operand from 0 to 1 and from 1 to 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*gBqh3mVopKE8J0C3mZLgSg.png" /></figure><ul><li>The binary representation of 42 is 0000 0000 0000 0000 0000 0000 0010 1010.</li><li>Applying the bitwise complement (~) operation inverts each bit, resulting in 1111 1111 1111 1111 1111 1111 1101 0101.</li><li>The resulting decimal value is -43.</li></ul><h4>Unary Plus (+expr):</h4><ul><li>The unary plus operator (+) is used to indicate the positive value of the operand. It doesn&#39;t actually change the sign of the operand; it&#39;s mainly used for clarity or when dealing with expressions.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*_F5BNLbjLAzxi0g5yz7ttA.png" /></figure><h4>Unary Minus (-expr):</h4><ul><li>The unary minus operator (-) negates the value of the operand. It changes the sign of the operand to its opposite.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*ygtbKz3aR9BsejEior0YUw.png" /></figure><ul><li>Logical NOT (!expr):</li></ul><p>The logical NOT operator (!) is used to perform logical negation. It flips the logical value of a boolean expression. If the expression is true, it becomes false, and if it&#39;s false, it becomes true.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*aPS_HVjVCnrSQE6lcq0UMw.png" /></figure><h4>Shift Operators</h4><p>Shift operators in Java are used to perform bitwise shifting on integer values.</p><p><strong>Left Shift (</strong><strong>&lt;&lt;):</strong></p><p>The left shift operator (&lt;&lt;) shifts the bits of a number to the left by a specified number of positions. It effectively multiplies the number by 2 raised to the power of the specified shift amount.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M2iw2-XkkPz1MjcDR-XbWA.png" /></figure><ul><li>The binary representation of 5 is 0000 0101.</li><li>Left shifting it by 2 positions gives 0001 0100, which is 20 in decimal.</li></ul><p><strong>Right Shift (</strong><strong>&gt;&gt;):</strong></p><p>The right shift operator (&gt;&gt;) shifts the bits of a number to the right by a specified number of positions. It effectively divides the number by 2 raised to the power of the specified shift amount.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wNTZMVxMVSmPkmEowMqpgQ.png" /></figure><ul><li>The binary representation of 16 is 0001 0000.</li><li>Right shifting it by 2 positions gives 0000 0100, which is 4 in decimal.</li></ul><p><strong>Unsigned Right Shift (</strong><strong>&gt;&gt;&gt;):</strong></p><p>The unsigned right shift operator (&gt;&gt;&gt;) is similar to the right shift operator (&gt;&gt;), but it fills the vacant positions with zeros regardless of the sign bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EMg-A9AjqE7WMRNmULMQhQ.png" /></figure><ul><li>The binary representation of -16 is 1111 1111 1111 1111 1111 1111 1111 0000 (using two&#39;s complement).</li><li>Unsigned right shifting it by 2 positions gives 0011 1111 1111 1111 1111 1111 1111 1100, which is 1073741820 in decimal.</li></ul><h4>Bitwise AND operator (&amp;)</h4><p>It compares each bit of the first operand with the corresponding bit of the second operand and produces a new integer where each bit of the result is the logical AND of the corresponding bits in the operands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*R7LH4NLCRzm7MPuoI6pg3w.png" /></figure><ul><li>operand1 in binary is 1100.</li><li>operand2 in binary is 11001.</li><li>The bitwise AND operation is performed on each pair of corresponding bits:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*g7i-fS72--DxArNpWe5ysg.png" /></figure><p>truth table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*9KL6yIH68KXSty6eFuHqmQ.png" /></figure><h4>Bitwise XOR (^)</h4><p>The XOR operation results in a new integer where each bit of the result is the exclusive OR of the corresponding bits in the operands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*X2OFUe2cCQkA_kEU1oLWbw.png" /></figure><ul><li>operand1 in binary is 1100.</li><li>operand2 in binary is 11001.</li><li>The bitwise XOR operation is performed on each pair of corresponding bits:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*pAkkPAH2fRvKMnaEeOM5hQ.png" /></figure><p>Truth table :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*Uk6uQkj-81K1yKMh0fQo1w.png" /></figure><h4>Bitwise OR operator ( | )</h4><p>The bitwise OR operator (|) in Java performs a bitwise OR operation on the corresponding bits of two integer operands. The OR operation results in a new integer where each bit of the result is the logical OR of the corresponding bits in the operands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*0guq8I5HH7O_TsWYg46l6Q.png" /></figure><ul><li>operand1 in binary is 1100.</li><li>operand2 in binary is 11001.</li><li>The bitwise OR operation is performed on each pair of corresponding bits:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/204/1*qDnZMlI9YaRog95Z5QWxrA.png" /></figure><p>Truth table :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*CBWWEASFE5C-tHO2QCR2Dg.png" /></figure><h4>Ternary conditional operator ‘ ? ‘</h4><p>In Java, the ? symbol is part of the ternary conditional operator, also known as the ternary operator or the conditional operator. It provides a concise way to express a conditional statement and is often used as a shorthand for an if-else statement.</p><p>condition ? expression_if_true : expression_if_false;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*abrJ1OJRM9vKXl0C8MTYeg.png" /></figure><h3>6. Working with the String Class</h3><ul><li>Develop code that uses methods from the String class</li><li>Format Strings using escape sequences including %d, %n, and %s</li></ul><h4>Formatting Integers (%d):</h4><p>In this example, %d is a format specifier for integers. The %d will be replaced by the value of the number variable when the string is formatted.</p><h4>Formatting Strings (%s):</h4><p>In this example, %s is a format specifier for strings. The %s will be replaced by the value of the name variable when the string is formatted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QrIkdZgE2XJ-8NEZu1ssHA.png" /></figure><h4>Newline Character (%n):</h4><p>In this example, %n is used to represent a newline character. This can be useful for creating multiline strings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*icHNFiL0ExEXCInswzcp8A.png" /></figure><h4>Combining Multiple Format Specifiers:</h4><p>Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*83CEdQDdg-Ao7nR_pP90cQ.png" /></figure><h3>7. Working with the Random and Math Classes</h3><h4>Math Class</h4><p>‘java.lang.Math’ is a built-in class in Java that provides methods for various mathematical operations.</p><p>example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*ZV7Fq-nh_mMqlNpncoVlKw.jpeg" /></figure><p>Addition — addExact()</p><p>Subtraction — subtractExact()</p><p>Multiplication — multiplyExact()</p><p>Square root — sqrt()</p><p>Power operations — pow()</p><p>cos()</p><p>sin()</p><p>tan()</p><p>etc..</p><h3>Random class</h3><p>java.util.Random class in Java is part of the Java Standard Library and is used to generate pseudorandom numbers. It provides a mechanism to generate random numbers using a seed value. Pseudorandom numbers are not truly random because they are generated by an algorithm, but they can be unpredictable enough for many applications.</p><p><strong>Initialization with a Seed:</strong></p><p>seed is a value used to initialize the internal state of the pseudorandom number generator (PRNG).The internal state is crucial for generating a sequence of pseudorandom numbers.In other words internal state is crucial for generating a sequence of pseudorandom numbers.</p><ol><li>Default Seed: When you create a Random object without explicitly specifying a seed, it uses the current system time in milliseconds as the default seed.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*wbMt6bqxw9cuC5kbN3UWXA.jpeg" /></figure><p>2. Specifying Seed Explicitly: You can also provide a specific seed value when creating a Random object. If you use the same seed in different runs of your program, you&#39;ll get the same sequence of pseudorandom numbers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*ohWFi0RTzMRk4OfuuRCegQ.jpeg" /></figure><p>3. Reproducibility: Setting the seed explicitly is useful when you want to reproduce a specific sequence of random numbers. For example, in testing or debugging scenarios where you need to ensure the same behavior each time the program runs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*eg0Q6MqqLWSDmyZSvkRA-A.jpeg" /></figure><p>example. :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*Lo60fqHdJ1FBsAXgUrhGZg.jpeg" /></figure><p>If you need a more secure source of randomness, especially for cryptographic purposes, consider using java.security.SecureRandom. The SecureRandom class is designed to provide a cryptographically secure random number generation and is not based on a predictable algorithm like the standard Random class.</p><h3>8. Using Decision Statements</h3><h4>8.1. Use the decision making statement (if-then and if-then-else)</h4><p><strong>if-then Statement:</strong></p><p>The if-then statement is used when you want to execute a block of code only if a specified condition is true.</p><p>example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m5rAkN3DrcNEIDkjgZEesA.png" /></figure><p><strong>if-then-else Statement:</strong></p><p>The if-then-else statement is used when you want to execute one block of code if a condition is true and another block if the condition is false.</p><p>example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y0mu_00kJt7qUJTKclwtaw.png" /></figure><h4>8.2. Switch statement</h4><p>In Java, the switch statement is a decision-making construct that provides an alternative way to express multiple conditional branches based on the value of an expression. It is particularly useful when you have a variable or an expression with discrete, distinct values and you want to execute different code blocks for each possible value.</p><p>Example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lh_YX4o7Q-0VxzE9wiObtw.png" /></figure><p>The expression is evaluated once, and its value is compared with the values in each case.</p><ul><li>If a match is found, the corresponding code block is executed.</li><li>The break statement is used to exit the switch statement. If a break statement is not present, the control will fall through to the next case (which can sometimes be intentional).</li><li>The default case is optional and is executed if none of the case values match the expression.</li></ul><h4>8.3. Compare how == differs between primitives and objects</h4><p>In Java, the == operator behaves differently when used with primitives and objects. Let&#39;s discuss the differences:</p><h4>- Primitives</h4><ol><li>Equality Check:</li></ol><ul><li>For primitive data types (such as int, double, char, etc.), == checks for the equality of values.In this example, a == b evaluates to true because both variables have the same value.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*1kPN1Al00x1-KPPoHIsrXg.png" /></figure><p>Comparing Value:</p><ul><li>Primitives store actual values, and == compares these values directly.Here, x == y evaluates to true because both variables have the value &#39;A&#39;.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*yjP0tM8F9JO6f4gaMoAnwA.png" /></figure><h4>- Objects:</h4><ol><li><strong>Reference Check:</strong></li></ol><ul><li>For objects, including instances of classes, == checks for reference equality, not the equality of the contents.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9oyAe-jueAiK3BXOTkDApA.png" /></figure><p>In this example, str1 == str2 evaluates to false because new String(&quot;Hello&quot;) creates two different objects with distinct references.</p><p><strong>2. Comparing Content:</strong></p><ul><li>To check if the content of two objects is equal, you should use the equals() method.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A42nIg-XeDG_YfG-FU9R4A.png" /></figure><p>Here, str3.equals(str4) evaluates to true because the equals() method compares the content of the String objects.</p><h4>8.4. Compare two String objects by using the compareTo and equals methods</h4><p><a href="https://lkprabha.medium.com/understanding-java-string-stringbuilder-and-stringbuffer-0fb2cea37071">Understanding Java String, StringBuilder, and StringBuffer</a></p><h3>9. Using Looping Statements</h3><h4>9.1. Describe looping statements</h4><p>Looping statements in Java allow you to repeatedly execute a block of code as long as a certain condition is true or until a certain condition becomes true. There are three main types of looping statements in Java: for, while, and do-while.</p><h4>9.2. Use a for loop including an enhanced for loop</h4><p><strong>Traditional </strong><strong>for Loop:</strong></p><p>The for loop is commonly used when the number of iterations is known before entering the loop.</p><ul><li>Initialization: Executed only once at the beginning of the loop.</li><li>Condition: Checked before each iteration. If false, the loop exits.</li><li>Update: Executed after each iteration.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VV_Vy8ajv_lh_Ynyyan7OA.png" /></figure><p><strong>Enhanced </strong><strong>for (for-each) Loop:</strong></p><p>The enhanced for loop is particularly useful for iterating over elements of arrays or collections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KV3dxdJngdc-sa9QepFolQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Lum9YFIwxnNhunID06aqA.png" /></figure><p>In this example, the loop iterates over each element in the numbers array, and num takes on the value of each element in each iteration.</p><ul><li>The enhanced for loop works with arrays and Iterable collections. It simplifies the syntax and is often preferred for iterating over elements when the index is not needed.</li><li>For other scenarios or when you need more control over the loop structure, the traditional for loop is more suitable.</li></ul><p>Both types of for loops are essential constructs in Java, and the choice between them depends on the specific requirements of your code.</p><h4>9.3. Use a while loop</h4><p>The while loop is used when the number of iterations is not known beforehand.Checked before each iteration.</p><p><strong>Condition</strong>:If false, the loop exits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IBY_OZ2NOrySxbHeqjf6rQ.png" /></figure><h4>9.4. Use a do- while loop</h4><p>The do-while loop is similar to the while loop, but the condition is checked after each iteration. This guarantees that the loop body is executed at least once.</p><p><strong>Condition</strong>: Checked after each iteration. If false, the loop exits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gQyGH4dmei746osuITweCA.png" /></figure><h4>9.5. Code that uses break and continue statements</h4><ul><li>continue: Skips the rest of the code in the loop and moves to the next iteration.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YOTu7P4XNb7aG4zLbEd91g.png" /></figure><ul><li><strong>break</strong>: Exits the loop prematurely.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yZCt5GQpH886eX7gfEmxpw.png" /></figure><p>Looping statements are fundamental for controlling the flow of a program, and choosing the appropriate type of loop depends on the specific requirements of the task at hand.</p><h4>9.6. Compare and contrast the for, while, and do-while loops</h4><p>When we talk about the <strong>similarities</strong> ;</p><ul><li>All three loops provide a way to repeatedly execute a block of code based on a certain condition.</li><li>Each loop type relies on a condition to determine whether to continue iterating or exit the loop.</li><li>All three loops can be controlled using statements like break and continue to alter the flow of the loop.</li></ul><p><strong>Tips :</strong></p><ul><li>Use for when the number of iterations is known.</li><li>Use while when the number of iterations is not known, and the loop condition is evaluated before entering the loop.</li><li>Use do-while when you want to guarantee the execution of the loop body at least once, and the loop condition is checked after the loop body.</li></ul><h3>10. Debugging and Exception Handling</h3><h4>10.1. Identify syntax and logic errors</h4><p><strong>Syntax Errors:</strong></p><ul><li>Syntax errors occur when the code violates the rules of the Java programming language.</li><li>These errors prevent the program from compiling.</li><li>Syntax errors are typically detected by the compiler during the compilation phase.</li><li>Missing semicolons at the end of statements, Mismatched parentheses or brackets, Incorrect keyword usage, etc..</li></ul><p><strong>Logic Errors:</strong></p><ul><li>Logic errors occur when the code does not behave as intended.</li><li>The program may compile and run, but it produces incorrect results.</li><li>Logic errors are more challenging to detect because the program will compile and run without error messages.</li><li>Debugging and testing are often used to identify logic errors.</li></ul><h4><strong>10.2. Use exception handling</strong></h4><p>Exception handling is a mechanism in Java that allows you to gracefully manage runtime errors and abnormal conditions that may occur during the execution of a program. Exception handling in Java is based on the use of try, catch, throw, and finally blocks.</p><h4>Use try and catch blocks</h4><p><strong>1. try Block:</strong></p><ul><li>The try block contains the code that might generate an exception.</li><li>It is followed by one or more catch blocks or a finally block.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RFa9CQlg20QfrJzT5J7E6w.png" /></figure><p>2. catch Blocks:</p><ul><li>The catch blocks are used to handle specific types of exceptions that might be thrown within the corresponding try block.</li><li>You can have multiple catch blocks to handle different types of exceptions.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jbGADIBk6HPUSkYFVD67LQ.png" /></figure><p>3. finally Block:</p><ul><li>The finally block contains code that is guaranteed to be executed, regardless of whether an exception occurs or not.</li><li>It is often used for cleanup operations, such as closing resources.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o8sD0g_3OfH36uDAUtbm7Q.png" /><figcaption>x</figcaption></figure><p>4. throw Statement:</p><ul><li>The throw statement is used to explicitly throw an exception.</li><li>You can throw either built-in exceptions or create your own custom exceptions.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bDZld9HUbf16jFGarPlK-A.png" /></figure><p>example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JmT0dj2siemiGBoT258cng.png" /></figure><h4><strong>10.3. Handle common exceptions thrown</strong></h4><p>Handling common exceptions in Java involves using try-catch blocks to manage and recover from specific types of exceptions. Here are some common exceptions and how you might handle them:</p><p><strong>1. ArithmeticException:</strong></p><ul><li>Occurs when an arithmetic operation results in an overflow, underflow, or division by zero.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DCT0UoivinTJTXib5_1KcA.png" /></figure><p><strong>2. NullPointerException:</strong></p><ul><li>Occurs when you attempt to access an object or invoke a method on an object that is null.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yMQCMXvMQRNmK8lo6g0FQQ.png" /></figure><p><strong>3. ArrayIndexOutOfBoundsException:</strong></p><p>Occurs when trying to access an array element with an index that is outside the array bounds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LEsY-DjJTBH14agWOCVjiA.png" /></figure><p>4<strong>. </strong><strong>NumberFormatException:</strong></p><p>Occurs when trying to convert a string to a numeric format, but the string does not represent a valid number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AvxeCz7Sd8BwM9aRO9zk_A.png" /></figure><p><strong>5. </strong><strong>IOException:</strong></p><ul><li>Represents a variety of input/output-related exceptions.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rCczunuSAFJRTwf-DA7p3w.png" /></figure><p><strong>6. FileNotFoundException:</strong></p><p>A specific type of IOException that occurs when trying to access a file that does not exist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hq0hxihMkYBMtjcOHcE-1w.png" /></figure><p><strong>7. </strong><strong>NumberFormatException:</strong></p><p>Occurs when trying to convert a string to a numeric format, but the string does not represent a valid number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WIL0lwt23MJcgDz11Oypig.png" /></figure><p><strong>8 . </strong><strong>InterruptedException:</strong></p><ul><li>Occurs when a thread is interrupted while it is in a blocked state.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kd-kI1Kxvc3vdaMUNloFPA.png" /></figure><p><strong>9. </strong><strong>IllegalArgumentException:</strong></p><ul><li>Occurs when an illegal or inappropriate argument is passed to a method.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KMkACKkkD9r0UiZ2sYj_Bg.png" /></figure><p><strong>10. </strong><strong>RuntimeException (Unchecked Exceptions):</strong></p><ul><li>A broad category of exceptions, such as NullPointerException and ArrayIndexOutOfBoundsException, that do not need to be explicitly caught or declared in a method&#39;s throws clause.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hLY9Z1yHJgSstoI2a2Zzxg.png" /></figure><p>When handling exceptions, it’s essential to catch specific exceptions based on the potential errors that might occur in your code. This helps you provide more meaningful error messages and implement appropriate recovery or error-handling mechanisms.</p><h3>11. Arrays and ArrayLists</h3><h4>11.1. Use a one-dimensional array</h4><p>In Java, a one-dimensional array is a collection of elements of the same data type arranged in a linear sequence. Each element in the array can be accessed by its index, starting from 0 for the first element. One-dimensional arrays are useful for storing and manipulating a list of values of the same type.</p><p>One-dimensional arrays are fundamental data structures in Java and are widely used in various applications for organizing and processing data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OeLqH7ENES3Ka3zeEuBPUA.png" /></figure><p>In below code segment will show you how to create an integer array and then print the elements one by one by using a standard for loop and using by extended for loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1wimBCUNy2WgfFQb7nHmqw.png" /></figure><h4>11.2. Create and manipulate an ArrayList and 11.3. Traverse the elements of an ArrayList by using iterators and loops including the enhanced for loop</h4><p>In Java, the ArrayList class is part of the java.util package and provides a dynamic array implementation. Unlike regular arrays, ArrayLists can dynamically grow or shrink in size during runtime.</p><ol><li>To use ArrayList, you need to import it:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mPQGNmKWPCq3xUKelZnBXA.png" /></figure><p>2. create an ArrayList:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NrBOroEKGJiXGzXOw8lbqQ.png" /></figure><p>3. Adding elements by add() method :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y-R2MH4IJyqjZi89cS313A.png" /></figure><p>4. Accessing the elements by their index using the get method:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mjqYD_2y20x3aTaEDKMjDQ.png" /></figure><p>5. Iterate over the elements:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bqZjiOr4Wn-c0nfYoYpt-w.png" /></figure><p>6. Removing elements by index or value:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WQh6JFX8UvCi1Exxq_YlxA.png" /></figure><p>7. Check the size of the ArrayList using the size method:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m-Dt4qHQ-J3uqASf5XpofA.png" /></figure><p>example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nQGdTDHmVdofGprYRUQ_nA.png" /></figure><p>output :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J8ToDVVA7IRO-aqCt83-XA.png" /></figure><h4>11.4. Compare an array and an ArrayList</h4><p>Arrays and ArrayLists are both used to store collections of elements in Java, but they have some key differences.</p><ol><li><strong>size :</strong></li></ol><ul><li>Arrays have a fixed size, which means you need to know the size at the time of declaration.</li><li>Once an array is created, its size cannot be changed.</li><li>ArrayLists can dynamically grow or shrink in size during runtime.</li><li>The size can be changed dynamically with methods like add and remove.</li></ul><p><strong>2. Primitives and Objects:</strong></p><ul><li>Arrays can store both primitive data types and objects.</li><li>ArrayLists can only store objects, not primitive data types. However, Java autoboxing allows you to use primitive types indirectly.</li></ul><p>ex: Array</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qy0T_y6pArQHAlEXvKB5yA.png" /></figure><p>ArrayList</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gDsmogui6ca8wYbHbFws-w.png" /></figure><p><strong>3. Direct Element Access</strong>:</p><ul><li>Elements in an array are accessed using their index.</li></ul><p><strong>4. No Built-in Methods:</strong></p><ul><li>Arrays in Java do not have built-in methods for common operations like resizing or easily removing elements.</li><li>ArrayLists provide built-in methods for common operations like adding, removing, and searching for elements.</li></ul><p>ex:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JXiDszv_rQCa57qcp-fl5A.png" /></figure><p><strong>5. Performance:</strong></p><ul><li>Arrays generally have slightly better performance compared to ArrayLists because they are simpler and more lightweight.</li><li>ArrayLists have a bit more overhead compared to arrays due to the additional functionality they provide.</li></ul><h4>When to Use Each:</h4><p><strong>Arrays:</strong></p><ul><li>When the size is fixed or known at compile time.</li><li>When you need direct and fast access to elements by index.</li><li>When memory efficiency is critical.</li></ul><p><strong>ArrayList:</strong></p><ul><li>When the size may change during runtime.</li><li>When you need built-in methods for common operations.</li><li>When flexibility in adding, removing, or modifying elements is important.</li></ul><p>Both arrays and ArrayLists have their advantages, and the choice between them depends on the specific requirements of your program. ArrayLists are more flexible and convenient in many scenarios, but arrays are still useful in situations where a fixed size is sufficient or when performance is critical.</p><h3>12. Classes and Constructors</h3><h4>12.1. Create a new class including a main method</h4><ol><li>In your IDE, create a new Java class. Typically, you can find an option like “New Class” or “Create Java Class” in the menu. Give your class a meaningful name, and make sure to check the option for creating a main method if it&#39;s available.</li><li>If you are using a simple text editor, create a new file with a .java extension and write the class code manually.</li><li>Save the class file with the same name as your class but with a .java extension.</li><li>If you’re using an IDE, it might automatically compile the code for you. If not, open a terminal or command prompt, navigate to the directory where your Java file is saved, and compile it using the javac command:</li></ol><p>ex : <strong>javac MyClass.java</strong></p><p>5. After compiling, run the Java program using the java command:</p><p>ex : <strong>java MyClass</strong></p><p>This will execute the main method within your MyClass class, and you should see the output.</p><p>example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2jseKE3QYckGbnW2Hcwc2Q.png" /></figure><h4>12.2. Use the private modifier</h4><p>In Java, the private modifier is an access modifier that can be applied to instance variables, methods, and inner classes. It restricts the access to the declared members only within the same class, making them inaccessible from outside the class.</p><ol><li><strong>Private Instance Variables:</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EBGL3rwqNC2pVN-VrC9yZw.png" /></figure><p>In this example, privateVariable is a private instance variable, and the setPrivateVariable and getPrivateVariable methods are used to modify and access the variable, respectively. These methods act as a controlled interface for interacting with the private variable.</p><p><strong>2. Private Methods:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RCKBt0Fyi8bB7OK3fJ7buw.png" /></figure><p>Here, privateMethod is a private method that can only be called from within the same class. It&#39;s used internally by the publicMethod.</p><p><strong>3. Private Inner Classes:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*FP5NayQcL5OBVUKJauHCZA.png" /></figure><p>Inner classes can also be marked as private, restricting their visibility to only the outer class.</p><h3>Benefits of Using private:</h3><ol><li><strong>Encapsulation:</strong></li></ol><ul><li>private helps in encapsulating the implementation details of a class by hiding its internal state and implementation.</li></ul><p><strong>2. Controlled Access:</strong></p><ul><li>By making certain members private, you have control over how they are accessed and modified. This prevents external classes from directly manipulating internal state.</li></ul><p><strong>3. Security:</strong></p><ul><li>It improves the security of the code by preventing unauthorized access and modification.</li></ul><p><strong>4. Flexibility:</strong></p><ul><li>It provides flexibility to change the internal implementation of a class without affecting the classes that use it.</li></ul><p><strong>5. Access Outside the class :</strong></p><p>The private members of a class are not accessible outside the class, including subclasses. If you need to allow access to certain members for subclasses, you can use the protected modifier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PliFTJblkWSbiDeiUwBf_w.png" /></figure><p>The private modifier is crucial for encapsulation and maintaining the integrity of a class by controlling access to its members. It is a key principle in object-oriented programming that promotes data hiding and modularity.</p><h4>12.3. Describe the relationship between an object and its members</h4><p>In Java, the relationship between an object and its members refers to how an object encapsulates its state and behavior through the definition of fields (also known as members or attributes) and methods.</p><p><strong>Object</strong></p><ul><li>An object is an instance of a class in Java.</li><li>It is a runtime entity that represents a real-world entity with properties and behaviors.</li><li>Objects are created based on the blueprint provided by the class.</li></ul><p><strong>Members (Attributes/Fields):</strong></p><ul><li>Members are the data fields or attributes of a class that represent the state of an object.</li><li>They define the properties of an object.</li><li>Members are typically private to ensure encapsulation, and their values are accessed and modified through methods (getters and setters).</li></ul><h4>12.4. Describe the difference between a class variable, an instance variable, and a local variable.</h4><p>In Java, like in many object-oriented programming languages, class variables, instance variables, and local variables have distinct characteristics.</p><p><strong>Class Variable:</strong></p><ul><li><strong>Declaration</strong>: A class variable is declared using the static keyword within a class but outside of any method.</li><li><strong>Scope</strong>: It is associated with the class itself rather than with instances of the class.</li><li><strong>Access</strong>: Class variables are accessed using the class name and can be modified using the class name or through an instance of the class.</li><li><strong>Lifetime</strong>: It exists as long as the class is loaded in the memory.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*lp0MhLZenq7vARBo5QM1sQ.png" /></figure><p><strong>Instance Variable:</strong></p><ul><li><strong>Declaration</strong>: An instance variable is declared without the static keyword, typically within a class but outside of any method, and it is associated with instances of the class.</li><li><strong>Scope</strong>: It is specific to each instance (object) of the class.</li><li><strong>Access</strong>: Instance variables are accessed using the instance of the class (object).</li><li><strong>Lifetime</strong>: It exists as long as the instance of the class exists.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*ocLbpWXuvVaATQBqf84vig.png" /></figure><p><strong>Local Variable:</strong></p><ul><li><strong>Declaration</strong>: Local variables are declared within a method, constructor, or block of code.</li><li><strong>Scope</strong>: They are limited to the block where they are declared. They are not accessible outside that block.</li><li><strong>Access</strong>: Limited to the method, constructor, or block in which they are declared.</li><li><strong>Lifetime</strong>: They exist only as long as the method, constructor, or block is executing.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZUmQ_sGVEVCegptYH8ankw.png" /></figure><p>In summery class variables provide a shared state among all instances, instance variables store state specific to each object, and local variables are temporary and local to a specific block of code.</p><h4>12.5. Develop code that creates an object’s default constructor and modifies the object’s fields.</h4><p>In Java, when you create a class, a default constructor is provided by the compiler if you don’t explicitly define one.</p><p>The default constructor initializes the object with default values for its fields. If you want to modify the object’s fields after creating an instance, you can do so by providing setter methods or modifying the fields directly if they are accessible.</p><p>example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yBa1tZomT3G4x_r84l-49w.png" /></figure><p>code explain :</p><ul><li>The MyCars class has two fields: stringValue.</li><li>The default constructor initializes these fields with default values ( &quot;Default&quot; for stringValue).</li><li>The modifyFields method allows you to change the values of the object&#39;s fields.</li><li>The displayState method is used to display the current state of the object.</li><li>In the main method, an object of MyCars is created using the default constructor, and its initial and modified states are displayed.</li></ul><p>You can customize this code according to your specific requirements and add more fields or methods as needed.</p><h4>12.6. Use constructors with and without parameters.</h4><p><strong>Constructors With Parameters (Parameterized Constructors):</strong></p><p>Constructors with parameters allow you to initialize the object with specific values at the time of creation. You define these constructors with parameters in the class, and they are invoked when you create an object with the new keyword.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ek4qSejrq1-tByHabiHEaQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_dVtGuv4PBcKzSjgWf-zrA.png" /></figure><p>In this example, the MyClass class has a parameterized constructor that takes two parameters (intValue and stringValue). When you create an object of MyClass using new MyClass(42, &quot;Hello&quot;), it calls this parameterized constructor, initializing intValue with 42 and stringValue with &quot;Hello&quot;.</p><p><strong>Constructors Without Parameters (Default Constructors):</strong></p><p>A default constructor is automatically provided by the Java compiler if you don’t explicitly define any constructor in your class. This constructor has no parameters and is responsible for initializing the object with default values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nNFrhhC7FbOQTS2xo9Q1kA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m4e5ScuF25nKpFKPHHXsgA.png" /></figure><p>In this example, the MyClass class has a default constructor that initializes intValue with 0 and stringValue with &quot;Default&quot;. When you create an object of MyClass using new MyClass(), it calls this default constructor.</p><h4>12.7. Develop code that overloads constructors</h4><p>In Java, constructor overloading allows you to define multiple constructors in a class, each with a different set of parameters. This enables you to create objects in various ways by providing different input values during object creation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8IIR2NaOBYRv4uCjxQlkJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T5XTdI8HzTPh5EFqMwg8sg.png" /></figure><ul><li>The MyCar class has four constructors: a default constructor, an int parameterized constructor, a string parameterized constructor, and a constructor that takes both int and string parameters.</li><li>Each constructor initializes the object’s fields based on the provided parameters.</li><li>The displayState method is used to display the state of the object.</li></ul><p>In the main method, four objects are created using different constructors, demonstrating how constructor overloading allows you to create objects with different initial states based on the provided parameters.</p><h3>13. Java Methods</h3><h4>13.1. Describe and create a method</h4><p>A method is a block of code within a class that performs a specific task. Methods are used to organize code, improve reusability, and facilitate modular programming. Methods can be classified into two main types: instance methods and static methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1ivYiD7y9Op1nvPFKrZwsg.png" /></figure><ul><li>displayMessage is an instance method that doesn&#39;t take any parameters. It simply prints a message when called.</li><li>addNumbers is a static method that takes two integer parameters (num1 and num2) and returns their sum.</li></ul><p>To create a method:</p><ol><li>Specify the access modifier (e.g., public, private, protected, or default package-private).</li><li>Specify the return type (or use void if the method doesn&#39;t return any value).</li><li>Provide the method name.</li><li>If applicable, specify the parameters within parentheses.</li><li>Write the method body, enclosed in curly braces {}.</li></ol><p>In the main method, an object of the class is created to call the instance method, and the static method is called directly.</p><p>When you run this program, it will display the message from the instance method and the sum of two numbers from the static method.</p><h4>13.2. Create and use accessor and mutator methods</h4><p>Accessor and mutator methods, also known as getter and setter methods, are used to access and modify the private fields (attributes) of a class, respectively. Encapsulation is a fundamental concept in object-oriented programming that involves hiding the internal implementation details of a class and providing controlled access to its data. Accessor and mutator methods are essential components of achieving encapsulation in Java.</p><ol><li><strong>Accessor (Getter) Methods:</strong></li></ol><p>Accessor methods are used to retrieve the values of private fields. They typically have the following characteristics:</p><ul><li>They are public methods.</li><li>They do not modify the state of the object.</li><li>They return the value of a private field.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cfV_t1Gaef2c3QoAa_DzzA.png" /></figure><p>In the example above, getIntValue is an accessor method that returns the value of the private field intValue.</p><p><strong>2. Mutator (Setter) Methods:</strong></p><p>Mutator methods are used to modify the values of private fields. They typically have the following characteristics:</p><ul><li>They are public methods.</li><li>They modify the state of the object by changing the values of private fields.</li><li>They often have parameters representing the new values.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xUTm6j18HSxM1G6DgzxLlQ.png" /></figure><p>When both getter and setter used in code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zo9ecZz8vMxUGFqaOyd95w.png" /></figure><p>In this extended example, the class MyClass has both accessor and mutator methods for two private fields (intValue and stringValue). These methods allow controlled access to the internal state of the class while maintaining encapsulation. Accessor methods enable the retrieval of field values, and mutator methods allow modification of those values.</p><h4>13.3. Create overloaded methods</h4><p>In Java, method overloading allows you to define multiple methods in the same class with the same name but different parameter lists. The compiler determines which method to call based on the number and types of arguments passed. This feature enhances code readability and flexibility.</p><p>Method overloading is based on the following criteria:</p><ol><li><strong>Number of Parameters:</strong> Methods must have a different number of parameters.</li><li><strong>Type of Parameters:</strong> Methods must have parameters of different types.</li><li><strong>Order of Parameters:</strong> The order of parameters must be different.</li></ol><p>The return type alone is not sufficient for method overloading; the parameter list must be unique.</p><p>Example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0LZM4XljW2rQr8Up8gOpkg.png" /></figure><p>In this example:</p><ul><li>add method is overloaded three times: one for adding two integers, one for adding three integers, and one for adding two doubles.</li><li>concatenate method is used to concatenate two strings.</li></ul><p>When you call these methods, the appropriate method is selected based on the number and types of arguments provided.</p><h4>13.4. Describe a static method and demonstrate its use within a program</h4><p>In Java, a static method is a method that belongs to the class rather than an instance of the class. This means you can call a static method on the class itself, without creating an object of that class. <strong>Static methods are often used for utility functions or operations that don’t depend on the state of a particular instance.</strong></p><p><strong>Declaration:</strong></p><ul><li>Static methods are declared using the static keyword.</li><li>They can access other static members of the class directly but cannot access instance variables or instance methods without creating an object.</li></ul><p><strong>Use Cases:</strong></p><ul><li>Utility methods: Methods that perform general-purpose tasks not specific to any instance.</li><li>Helper methods: Methods that assist in some computation without relying on the state of an object.</li><li>Factory methods: Methods that create and return instances of the class.</li></ul><p>Below example create a simple MathUtils class with a static method to calculate the square of a number:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s6D_uG3S2H5tZ4Z82yyi2A.png" /></figure><ul><li>The MathUtils class has a static method named square that takes an integer parameter and returns the square of that number.</li><li>In the main method, we call the square method directly on the class (MathUtils.square(5)) without creating an instance of MathUtils.</li><li>The result is then printed to the console.Square of 5 is: 25</li></ul><p>Here, the square method is defined as static, allowing us to use it without the need to create an object of the MathUtils class. This is a simple demonstration, but static methods become especially useful in larger programs when you have utility functions or operations that don&#39;t require an instance of the class.</p><p>As we draw to a close, I trust that the insights shared herein will serve as a valuable compass on your journey toward examination success.Good luck for the exams!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7f07e8077c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OOP Concepts -(Java)]]></title>
            <link>https://lkprabha.medium.com/oop-concepts-java-e95148fefeab?source=rss-145e3e4b00b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/e95148fefeab</guid>
            <category><![CDATA[java-oops-concept]]></category>
            <category><![CDATA[java-oop]]></category>
            <category><![CDATA[oop-concepts]]></category>
            <dc:creator><![CDATA[BuddhiK]]></dc:creator>
            <pubDate>Tue, 16 Jan 2024 11:33:23 GMT</pubDate>
            <atom:updated>2024-01-16T11:33:23.812Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PWZiYQnvsnwIOuiz041N0A.png" /></figure><h3>Object-Oriented Programming</h3><p>Object-oriented programming is a programming practice or we can call it a programming paradigm. Which is the most popular practice among programmers based on objects and classes. The most commonly used OOP languages are Java, JavaScript, C#, and Python.</p><p>Let us have a brief look at the basics of OOP.</p><h3>The Object</h3><p><strong>The object is any real-world entity.</strong></p><p>Ex: Cat, Car, Software Engineer, Student, Flower</p><p>It has its own states and behaviors.</p><p>ex: Cat</p><p>States :</p><p>The cat has a color.</p><p>The cat has a name.</p><p>The cat has a puffy tail.</p><p>Objects are instances of classes, which serve as blueprints or templates defining the structure and behavior of the objects. Objects encapsulate both data (attributes or properties) and behavior (methods or functions) into a single unit, promoting modularity, reusability, and maintainability in software development.</p><h3><strong>The Class</strong></h3><p><strong>A class is a blueprint or template that defines the structure and behavior of objects. </strong>It specifies the attributes (fields) and methods that the objects of the class will have. Not consume any memory space.</p><p>example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*29OwJNImCYxsd2BwcO8lSw.png" /></figure><p>In this example:</p><ul><li>The Person class defines attributes (name and age), a constructor for instantiation, and a method (introduce) for behavior.</li><li>Two objects (person1 and person2) are created based on the Person class.</li><li>The objects’ attributes are accessed, and their methods are called in the main method.</li></ul><p>Objects in OOP provide a way to model and interact with entities in a software system, facilitating a modular and reusable approach to software design. They enable the creation of systems that closely mirror real-world scenarios.</p><h3>Core concepts of Java</h3><h4><strong>- Inheritance (IS-A) — (R</strong>epresent IS A Relationship<strong>)</strong></h4><p>With the use of inheritance, the information is made manageable in a hierarchical order. <strong>When some object needs to use all the states/properties and behaviors of another object it is called inheritance.</strong> The new object will be the child and the object we inherited from is a parent.</p><p>ex: Software engineer object inherited from employee object.</p><p>This means we can use the same code -reusable. So it provides run time polymorphism.</p><p>ex: Assume that we have several toys as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*UIqradReSE60W2Inej2fUw.png" /></figure><p>As you can see same methods are repeated in all toys. So we can take the common methods into one-up level class as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*TqJV5wZzyyG5D8qFE4Rf7Q.png" /></figure><p>As you can see code repetition reduces. We can use the toys() supper class to inherit the other subclasses. (toycar, doll, musicbook)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a5a9789f6ae3f1c92a5348f1698bd47/href">https://medium.com/media/4a5a9789f6ae3f1c92a5348f1698bd47/href</a></iframe><h3><strong>Polymorphism:</strong></h3><p>poly means multiple. So <strong>If <em>one task can be done in different ways</em>, it is known as polymorphism.</strong> <strong>Polymorphism occurs when we have many classes related to each other by inheritance.</strong></p><p>ex: Animal object .Different animals can make sounds (behavior) .Like dog bark, cat mew, cow -moo .</p><p>In Java, we use method overloading and method overriding to achieve this.</p><pre>class Animal {<br>  public void animalSound() {<br>    System.out.println(&quot;The animal makes a sound&quot;);<br>  }<br>}<br>class Pig extends Animal {<br>  public void animalSound() {<br>    System.out.println(&quot;The pig says: wee wee&quot;);<br>  }<br>}<br>class Dog extends Animal {<br>  public void animalSound() {<br>    System.out.println(&quot;The dog says: bow wow&quot;);<br>  }<br>}<br>class Main {<br>  public static void main(String[] args) {<br>    Animal myAnimal = new Animal();  // Create a Animal object<br>    Animal myPig = new Pig();  // Create a Pig object<br>    Animal myDog = new Dog();  // Create a Dog object<br>    myAnimal.animalSound();<br>    myPig.animalSound();<br>    myDog.animalSound();<br>  }<br>}</pre><h3><strong>Method Overloading :</strong></h3><p><strong>Method overloading allows a class to have multiple methods with the same name but different parameter lists. </strong>This means you can define two or more methods with the same name within the same class, as long as the number or types of parameters are different. The compiler determines which method to call based on the arguments provided during the method invocation.</p><h3>Key Points about Method Overloading:</h3><ol><li>Same Method Name:</li></ol><ul><li>In an overloaded set of methods, all methods must have the same name.</li></ul><p>2. Different Parameter Lists:</p><ul><li>Overloaded methods must have different types or numbers of parameters. This can include differences in the order of parameters.</li></ul><p>3. Return Type:</p><ul><li>The return type alone does not determine method overloading. Two methods with the same name and parameter types but different return types will result in a compilation error.</li></ul><p>4. Inheritance:</p><ul><li>Overloaded methods can exist in the same class or its subclasses. They can also be present in interfaces.</li></ul><p>Example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xioTduITitFFNyK1QvqwgA.png" /></figure><ul><li>In this example, the MathOperations class has two overloaded add methods—one for integers and another for doubles. It also has a concatenate method that takes two strings.</li></ul><h4>Benefits of Method Overloading:</h4><ol><li><strong>Improved Readability:</strong></li></ol><ul><li>Overloading allows you to use the same method name for logically similar operations, making the code more readable and intuitive.</li></ul><p><strong>2. Code Reusability:</strong></p><ul><li>Overloaded methods promote code reuse by providing a single method name for different variations of the same operation.</li></ul><p><strong>3. Flexibility:</strong></p><ul><li>Developers can choose the method that best fits their needs based on the types of arguments they want to pass.</li></ul><p><strong>4. Default Values (Java 8 and later):</strong></p><ul><li>With the introduction of default values for method parameters in Java 8 and later versions, you can achieve a form of method overloading with fewer method signatures.</li></ul><h3><strong>Method Overriding :</strong></h3><p>Method overriding is a concept in object-oriented programming that allows a subclass to provide a specific implementation of a method that is already defined in its superclass. The overridden method in the subclass should have the same method signature (name, return type, and parameters) as the method in the superclass. When an object of the subclass calls the overridden method, the subclass’s version of the method is executed instead of the superclass’s version.</p><p>Consider the above toy example. There are three toys which are can on the lights and play the music. But the toy car plays a piece of siren music and lights will on according to the music intervals.</p><p>Therefore the toy cars onLights() method and playMusic() methods differ from other toys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/201/1*fqxo_ItzZB_VGDI4NZ6Flg.png" /></figure><p>Now here the same inherited methods from the supper class toys onLight() method and playMusic() methods have been overridden with special features that need to be performed within the toy car sub-class.</p><h3>Key Points about Method Overriding:</h3><ol><li>Inheritance Requirement:</li></ol><p>Method overriding is applicable in an inheritance hierarchy, where a subclass inherits from a superclass.</p><p>2. Same Method Signature:</p><p>The overriding method in the subclass must have the same method signature (name, return type, and parameters) as the method in the superclass.</p><p>3. Annotation (Optional):</p><p>While not required, using the @Override annotation before the method in the subclass helps the compiler catch errors if the method is not correctly overridden.</p><p>4. Access Modifiers:</p><p>The access level of the overriding method in the subclass cannot be more restrictive than the overridden method in the superclass. It can be the same or more permissive.</p><p>5. Return Type:</p><p>The return type of the overriding method must be the same as, or a subtype of, the return type of the overridden method. If the return types differ, it will result in a compilation error.</p><p>6. Checked Exceptions:</p><p>The overriding method is allowed to throw fewer, more specific, or no checked exceptions than the overridden method. It cannot throw broader or new checked exceptions.</p><h3><strong>Encapsulation</strong></h3><p>The meaning of <strong>Encapsulation</strong> is to make sure that “sensitive” data is hidden from users. To achieve this, you must:</p><ul><li>declare class variables/attributes as private</li><li>provide public <strong>get</strong> and <strong>set</strong> methods to access and update the value of a private variable</li></ul><p>Getter and Setter</p><p>private variables can only be accessed within the same class (an outside class has no access to it). However, it is possible to access them if we provide public <strong>get</strong> and <strong>set</strong> methods.</p><p>The get method returns the variable value, and the set method sets the value.</p><p>The syntax for both is that they start with either get or set, followed by the name of the variable, with the first letter in upper case:</p><h3>Example</h3><pre>public class Person {<br>  private String name; // private = restricted access</pre><pre>// Getter<br>  public String getName() {<br>    return name;<br>  }</pre><pre>// Setter<br>  public void setName(String newName) {<br>    this.name = newName;<br>  }<br>}</pre><ul><li>Better control of class attributes and methods</li><li>Class attributes can be made <strong>read-only</strong> (if you only use the get method), or <strong>write-only</strong> (if you only use the set method)</li><li>Flexible: the programmer can change one part of the code without affecting other parts</li><li>Increased security of data</li></ul><h3><strong>Data Abstraction</strong></h3><p>Data <strong>abstraction</strong> is the process of hiding certain details and showing only essential information to the user.<br>Abstraction can be achieved with either <strong>abstract classes</strong> or <a href="https://www.w3schools.com/java/java_interface.asp"><strong>interfaces</strong></a></p><p>The abstract keyword is a non-access modifier, used for classes and methods:</p><ul><li><strong>Abstract class:</strong> is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class).</li><li><strong>Abstract method:</strong> can only be used in an abstract class, and it does not have a body. The body is provided by the subclass (inherited from).</li></ul><p>An abstract class can have both abstract and regular methods:</p><p><strong>Interface</strong></p><p>Another way to achieve <a href="https://www.w3schools.com/java/java_abstract.asp">abstraction</a> in Java is with interfaces.</p><p>An interface is a completely &quot;<strong>abstract class</strong>&quot; that is used to group related methods with empty bodies:</p><h3>Example</h3><pre>// interface<br>interface Animal {<br>  public void animalSound(); // interface method (does not have a body)<br>  public void run(); // interface method (does not have a body)<br>}</pre><p>To access the interface methods, the interface must be “implemented” (kinda like inherited) by another class with the implements keyword (instead of extends). The body of the interface method is provided by the &quot;implement&quot; class:</p><h4>Notes on Interfaces:</h4><ul><li>Like <strong>abstract classes</strong>, interfaces <strong>cannot</strong> be used to create objects (in the example above, it is not possible to create an “Animal” object in the MyMainClass)</li><li>Interface methods do not have a body — the body is provided by the “implement” class</li><li>On implementation of an interface, you must override all of its methods</li><li>Interface methods are by default abstract and public</li><li>Interface attributes are by default public, static and final</li><li>An interface cannot contain a constructor (as it cannot be used to create objects)</li></ul><h4>Why And When To Use Interfaces?</h4><p>1) To achieve security — hide certain details and only show the important details of an object (interface).</p><p>2) Java does not support “multiple inheritances” (a class can only inherit from one superclass). However, it can be achieved with interfaces, because the class can <strong>implement</strong> multiple interfaces. <strong>Note:</strong> To implement multiple interfaces, separate them with a comma (see example below).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e95148fefeab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Java String, StringBuilder, and StringBuffer]]></title>
            <link>https://lkprabha.medium.com/understanding-java-string-stringbuilder-and-stringbuffer-0fb2cea37071?source=rss-145e3e4b00b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/0fb2cea37071</guid>
            <category><![CDATA[string-builder]]></category>
            <category><![CDATA[springbuilder]]></category>
            <category><![CDATA[java-strings]]></category>
            <category><![CDATA[stringbuffer]]></category>
            <category><![CDATA[string-vs-stringbuilder]]></category>
            <dc:creator><![CDATA[BuddhiK]]></dc:creator>
            <pubDate>Tue, 02 Jan 2024 06:59:51 GMT</pubDate>
            <atom:updated>2024-01-02T06:59:51.003Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*DeM8dHqfJ7UTzSC2K7YdHQ.jpeg" /></figure><h4>Java String Classes</h4><p>Java has provide three different classes to handle strings.</p><ul><li>String class is — imutable</li><li>StringBuilder and StringBuffer are - mutable</li></ul><p><strong>Which means once immutable objects are objects whose state (data) cannot be modified after the object is created while mutable objects are objects whose state (data) can be modified after the object is created</strong>.</p><p><strong>Immutable objects may have higher memory overhead because each modification creates a new object.</strong></p><h3>Java String object</h3><p>In Java, when you create instances of objects, memory allocation typically involves the String Pool and the heap.In String class uses <strong><em>String constant pool</em></strong>.Let’s break down the memory allocation for the provided code segment:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*AF5eSP75RjQbKuACThBtJg.jpeg" /><figcaption>img 01</figcaption></figure><ol><li>First String Literal (&quot;Hello&quot;):</li></ol><ul><li>When the code encounters the string literal “Hello”, it is stored in the String Pool.</li><li>If the literal already exists in the String Pool, the existing reference is reused. In this case, “Hello” is stored in the String Pool.</li></ul><p>2. Reference Assignment (String str = ...):</p><ul><li>String str = &quot;Hello&quot;;: Declares a String variable named str and assigns it the reference to the string literal &quot;Hello&quot; in the String Pool.</li><li>The variable str now points to the memory location where the string literal &quot;Hello&quot; is stored.</li></ul><p>3. Second String Literal (&quot;Hello&quot;):</p><ul><li>When the code encounters the string literal “Hello” again, it checks the String Pool.</li><li>Since “Hello” is already present in the String Pool, the existing reference is reused. <strong>No new string object is created.</strong></li></ul><p>4. Reference Assignment (String strCopy = ...):</p><ul><li>String strCopy = &quot;Hello&quot;;: Declares another String variable named strCopy and assigns it the reference to the same string literal &quot;Hello&quot; in the String Pool.</li><li>The variable strCopy now also points to the same memory location where the string literal &quot;Hello&quot; is stored.</li></ul><p>5. Print Statements:</p><ul><li>System.out.println(str);: Prints the value of str to the console. The value is &quot;Hello&quot;.</li><li>System.out.println(strCopy);: Prints the value of strCopy to the console. The value is also &quot;Hello&quot;.</li></ul><p>In summary:</p><ul><li><strong>The string literal “Hello” is stored in the String Pool.</strong></li><li><strong>Both </strong><strong>str and </strong><strong>strCopy reference the same string literal &quot;Hello&quot; in the String Pool.</strong></li></ul><p>The use of the String Pool allows Java to optimize memory usage by reusing existing string literals, promoting efficiency when working with string constants.</p><h3>StringBuilder Class</h3><p>In Java, the memory allocation for StringBuilder objects involves the <strong><em>heap</em></strong>. Let&#39;s break down the memory allocation for the provided code segment:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*K_7US65Snd8O-FCLbxuw-w.jpeg" /><figcaption>img 02</figcaption></figure><ol><li>First StringBuilder (new StringBuilder(&quot;Hello&quot;)):</li></ol><ul><li>new StringBuilder(&quot;Hello&quot;): Creates a new StringBuilder object with the initial content &quot;Hello&quot;.</li><li>The new StringBuilder object is allocated memory on the heap.</li></ul><p><strong>2.Reference Assignment </strong>(StringBuilder strBuilder = ...):</p><ul><li>StringBuilder strBuilder = new StringBuilder(&quot;Hello&quot;);: Declares a StringBuilder variable named strBuilder and assigns it the reference to the newly created StringBuilder object.</li><li>The variable strBuilder now points to the memory location where the StringBuilder object with the content &quot;Hello&quot; is stored.</li></ul><p><strong>3. Second </strong><strong>StringBuilder</strong> (new StringBuilder(&quot;Hello&quot;)):</p><ul><li>new StringBuilder(&quot;Hello&quot;): Creates another new StringBuilder object with the same initial content &quot;Hello&quot;.</li><li>This results in a separate StringBuilder object being allocated memory on the heap.</li></ul><p><strong>4. Reference Assignment </strong>(StringBuilder strBuilderCopy = ...):</p><ul><li>StringBuilder strBuilderCopy = new StringBuilder(&quot;Hello&quot;);: Declares another StringBuilder variable named strBuilderCopy and assigns it the reference to the second StringBuilder object.</li><li>The variable strBuilderCopy now points to the memory location where the second StringBuilder object with the content &quot;Hello&quot; is stored.</li></ul><p><strong>5. Print Statements:</strong></p><ul><li>System.out.println(strBuilder);: Prints the value of strBuilder to the console. The value is the string representation of the StringBuilder object.</li><li>System.out.println(strBuilderCopy);: Prints the value of strBuilderCopy to the console. The value is the string representation of the second StringBuilder object.</li></ul><p><strong><em>In summary:</em></strong></p><ul><li><em>Two </em><em>StringBuilder objects are created on the heap, each with the initial content &quot;Hello&quot;.</em></li><li><em>strBuilder and </em><em>strBuilderCopy are reference variables that point to the memory locations of their respective </em><em>StringBuilder objects.</em></li></ul><p>Unlike String objects, StringBuilder objects are mutable, meaning you can modify their contents without creating new objects. The memory allocation for StringBuilder objects is dynamic, and the objects can be resized as needed.</p><h3>StringBuffer Class</h3><p>In Java, when you create instances of StringBuffer objects, memory allocation typically involves the heap. Let’s break down the memory allocation for the provided code segment:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*OgGNWMc4187Mb2YJBpvyOA.jpeg" /><figcaption>img 03</figcaption></figure><ol><li><strong>First </strong>StringBuffer (new StringBuffer(&quot;Hello&quot;)):</li></ol><ul><li>new StringBuffer(&quot;Hello&quot;): Creates a new StringBuffer object with the initial content &quot;Hello&quot;.</li><li>The new StringBuffer object is allocated memory on the heap.</li></ul><p><strong>2. Reference Assignment </strong>(StringBuffer strbuffer = ...):</p><ul><li>StringBuffer strbuffer = new StringBuffer(&quot;Hello&quot;);: Declares a StringBuffer variable named strbuffer and assigns it the reference to the newly created StringBuffer object.</li><li>The variable strbuffer now points to the memory location where the StringBuffer object with the content &quot;Hello&quot; is stored.</li></ul><p><strong>3. Second</strong> StringBuffer (new StringBuffer(&quot;Hello&quot;)):</p><ul><li>new StringBuffer(&quot;Hello&quot;): Creates another new StringBuffer object with the same initial content &quot;Hello&quot;.</li><li>This results in a separate StringBuffer object being allocated memory on the heap.</li></ul><p><strong>4. Reference Assignment </strong>(StringBuffer strbuffercopy = ...):</p><ul><li>StringBuffer strbuffercopy = new StringBuffer(&quot;Hello&quot;);: Declares another StringBuffer variable named strbuffercopy and assigns it the reference to the second StringBuffer object.</li><li>The variable strbuffercopy now points to the memory location where the second StringBuffer object with the content &quot;Hello&quot; is stored.</li></ul><p><strong>5. Print Statements:</strong></p><ul><li>System.out.println(strbuffer);: Prints the value of strbuffer to the console. The value is the string representation of the StringBuffer object.</li><li>System.out.println(strbuffercopy);: Prints the value of strbuffercopy to the console. The value is the string representation of the second StringBuffer object.</li></ul><p><strong>In summary:</strong></p><ul><li>Two StringBuffer objects are created on the heap, each with the initial content &quot;Hello&quot;.</li><li>strbuffer and strbuffercopy are reference variables that point to the memory locations of their respective StringBuffer objects.</li></ul><p>Unlike String objects, StringBuffer objects are mutable, meaning you can modify their contents without creating new objects. The memory allocation for StringBuffer objects is dynamic, and the objects can be resized as needed.</p><h3>Immutability -Perfomance -Thread Safety</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*AjTbzhKh6mFOL6GpVJXciQ.jpeg" /><figcaption>img 04</figcaption></figure><h3>Memory Efficiency:</h3><ul><li>Strings are memory-efficient but create new objects on each modification.</li><li>StringBuilder and StringBuffer provide more efficient memory usage for dynamic modifications.</li></ul><p>In summary, the choice between String, StringBuilder, and StringBuffer depends on the specific requirements of your application, such as immutability, performance, and thread safety. Each class serves different use cases, so choosing the right one is essential for optimal functionality and efficiency.</p><p>Look in to the below code segments and the outputs.</p><p>example for String class object :</p><p>Run below source code and see the results. Both str and strCopy point in to the same memory address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*dw9X11itUI1GpEcbTw0Shg.jpeg" /><figcaption>img 05</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*UrUOFJcixh0IAK2qUNWPRw.jpeg" /><figcaption>img 06</figcaption></figure><p>example for StringBuilder class object :</p><p>Run below source code and see the results. Both strBuilder and strBuilderCopy point in to two different memory addresses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*WnSVyVrrSYLdjWuLNL_YUA.jpeg" /><figcaption>img 07</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*b2qBVeaQXYtM8zIgACSK4g.jpeg" /><figcaption>img 08</figcaption></figure><p>example for StringBuffer class object :</p><p>Run below source code and see the results. Both str and strCopy point in to two different memory addresses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*2lkAcdqX-QihB5fp-dulLw.jpeg" /><figcaption>img 09</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*fLau8FkuDRMFEopOggYy6g.jpeg" /><figcaption>img 10</figcaption></figure><h3>&#39;==’ Operator: The == operator in Java checks for reference equality, i.e., whether the two variables point to the same memory location.</h3><h4>String class</h4><ul><li>The == operator compares the references of two String objects. It <strong>checks whether they refer to the same memory location</strong>.</li><li>Example:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*ZpObsC5nVnB6HctdAl6wXA.jpeg" /><figcaption>img 11</figcaption></figure><h4>StringBuilder</h4><ul><li>The == operator for StringBuilder compares the references of two StringBuilder objects, similar to the String class.</li><li>Example:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*6si2kVvQ4V6pIw8bF5tMhQ.jpeg" /><figcaption>img 12</figcaption></figure><h4>StringBuffer Class</h4><ul><li>The == operator for StringBuffer compares the references of two StringBuffer objects, just like with other classes.</li><li>Example:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*qakxngDZuushmLW2_zGRIw.jpeg" /><figcaption>img 13</figcaption></figure><h3>&#39;equals&#39; Method: <strong>The </strong><strong>equals method checks both the content and the type of the objects.</strong></h3><h4>String Class</h4><ul><li>The equals method in the String class is overridden to <strong>compare the contents</strong> of two strings.</li><li>Example:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*uG8aNhsCaw6CLXrrVnDTmA.jpeg" /><figcaption>img 14</figcaption></figure><h4>StringBuilder Class</h4><ul><li>The equals method in the StringBuilder class is not overridden to compare the contents of two StringBuilder objects. It uses reference equality.</li><li>Example:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*dNvYEadJibZrm77Czg4PcA.jpeg" /><figcaption>img 15</figcaption></figure><p><strong>StringBuffer Class</strong></p><ul><li>The equals method in the StringBuffer class is not overridden to compare the contents of two StringBuffer objects. It uses reference equality.</li><li>Example:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*lFmCaEj8djGDvgxkMdX8Rg.jpeg" /><figcaption>img 16</figcaption></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -</p><ul><li><strong>For </strong><strong>String, it&#39;s common to use </strong><strong>equals to compare the content, as the </strong><strong>== operator compares references, not content.</strong></li><li>For StringBuilder,strinBuffer, you typically compare the contents indirectly by converting them to strings and then using equals:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*uG8aNhsCaw6CLXrrVnDTmA.jpeg" /><figcaption>img 17</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*3hz7w1pnsB2v51TVxWZWlQ.jpeg" /><figcaption>img 18</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*ILxwCWIPsUyCDJJFOPd4rg.jpeg" /><figcaption>img 19</figcaption></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><h4>Compare across the classes</h4><h4>Example 01 :</h4><p>String Vs StringBuffer</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*nL74c9cFzEr74E16Seha6Q.jpeg" /><figcaption>img 20</figcaption></figure><p>str.equals(buffer) Comparison:</p><ul><li>The equals method in the String class is overridden to compare the content of two strings. However, when comparing a String with a StringBuffer, they are considered not equal because their types are different.</li><li><strong>The </strong><strong>equals method checks both the content and the type of the objects.</strong> Since str is a String and buffer is a StringBuffer, the result of str.equals(buffer) is false.</li><li>Output is “Both are not equal”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*4UMxq-E-3uEWGZJhLLAQwA.jpeg" /><figcaption>img 21</figcaption></figure><p>You can use <strong>str.equals(buffer.toString()) </strong>to compair the content <strong>.</strong></p><h4>Example 02 :</h4><p>StringBuilder Vs StringBuilder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*dEvimv-E7-ZSF0X4Eln7Yg.jpeg" /><figcaption>img 22</figcaption></figure><p>Here s1==s2 checks whether the two variables point to the same memory location.Since s1 and s2 are two different StringBuilder objects and pointing to different memory location results is false.</p><p>s1.equals(s2) — equals method in the StringBuilder class is not overridden to compare the content of the StringBuilder objects.The default implementation of equals in the Object class checks for reference equality, so s1.equals(s2) will also evaluate to false.</p><p>Output — Nothing will print since the both if conditions are false.</p><h4>Example 03 :</h4><p><strong>String Vs String</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*BJ958Yb6ARvllMQogQGdSg.jpeg" /></figure><ol><li>str1 == str2 Comparison:</li></ol><ul><li>The == operator checks for reference equality. In this case, both str1 and str2 are string literals, and Java often uses string pooling, which means that identical string literals share the same memory location.</li><li>Therefore, str1 == str2 will evaluate to true because they reference the same memory location.</li></ul><p>2. str1.equals(str2) Comparison:</p><ul><li>The equals method in the String class is overridden to compare the content of the strings. Since both strings have the same content, str1.equals(str2) will also evaluate to true.</li></ul><p>Output:</p><ul><li>Both conditions are true, so the following output will be printed:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*pFz9mWal7twblLfmuOKLDA.jpeg" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p>java.lang.String class provides many useful methods to perform operations on string values. Lets meet again with methods of strings in Java!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0fb2cea37071" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JVM, JRE, JDK Surface Knowledge]]></title>
            <link>https://lkprabha.medium.com/jvm-jre-jdk-surface-knowledge-b05a64eea71c?source=rss-145e3e4b00b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/b05a64eea71c</guid>
            <category><![CDATA[jdk]]></category>
            <category><![CDATA[jvm-architecture]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[jre]]></category>
            <category><![CDATA[jvm]]></category>
            <dc:creator><![CDATA[BuddhiK]]></dc:creator>
            <pubDate>Tue, 19 Dec 2023 00:14:37 GMT</pubDate>
            <atom:updated>2023-12-19T00:14:37.360Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X2c7y2DWnI3byjlwjnk6VA.jpeg" /></figure><h3>- Java Virtual Machine — JVM -</h3><p>As per the name, JVM does not physically exist. It just provides a run time environment to execute Java byte code and convert it into machine language. It also can run programs written in other languages and convert(compile) them into Java byte code and then into the machine language. JVM enables run your program on your machine or in the cloud environment.</p><h4>Features of JVM</h4><ul><li>It can execute programs line by line and interpret byte code to machine code</li><li>It’s independent of OS and the hardware, make once you write Java code you can run it anywhere.</li><li>JVM is customizable. ex: JVM heap size, thread size, garbage collection time, etc.</li></ul><p>Further reading…</p><p><a href="https://github.com/TheUsefulLists/UsefulMods/blob/main/JavaArgumentsOptimization.md">UsefulMods/JavaArgumentsOptimization.md at main · TheUsefulLists/UsefulMods</a></p><h4>Things that JVM do</h4><ol><li>Load the code</li><li>Verify the code</li><li>Execute the code</li><li>Providing run-time environment</li></ol><h4>JVM Architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*drQ4DxHF3hXFWBz3Ifsjhg.jpeg" /><figcaption>fig 01: JVM architecture</figcaption></figure><h4>Class Loader</h4><p>Class loader performs Loading, Linking, and Initialization. Class loader loads necessary classes to run your Java program. There are three main categories of classes loader loads.</p><ol><li>The bootstrap class loader is the supper class extension of the class loader here. It loads the rt.jar class files of packages in Java standard edition like the java.lang package class, java.net package class, etc.</li><li>Then the extension class loader is the child class of the bootstrap class. It loads the jars from <em>$JAVA_HOME/jre/lib/ext</em> directory.</li><li>System Class Loader is the child of the Extension class and loads the class files from the current directory (default location class file path). If you want to have your own class loader you have to extend the ClassLoader class.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*molPKVw4s_8h3YUBfZUH5g.jpeg" /><figcaption>fig 02: Class Loader Architecture</figcaption></figure><p><strong>JVM Memory areas</strong></p><p><strong>Class/Method area</strong>: Runtime constant pool, field and method data, and the code for methods.</p><p><strong>Heap</strong>: Common memory shared across multiple threads which contain,</p><ul><li>Objects</li><li>Objects instance variables</li><li>Object instance arrays</li></ul><p><strong>Language Stack</strong>:</p><ul><li>Stores frames that contain local variables and partial results.</li><li>When a thread is created each time, JVM creates its own private new Language stack.</li><li>When a method invokes a frame will be created and after the invocation is completed the frame will destroy automatically.</li></ul><h4>PC Register: Program Counter Reg</h4><ul><li>Each thread has its own pc register.</li><li>The <strong>address</strong> of the JVM instruction which is currently executing stored in the PC register.</li></ul><h4>Native Method Stack</h4><ul><li>Contains the native methods/instructions used in your application.</li><li>It&#39;s written in other languages, not in Java.</li></ul><h4>Execution Engine</h4><ul><li>Contains a virtual processor, interpreter, and JIT compiler(<strong>J</strong>ust <strong>I</strong>n <strong>T</strong>ime).</li><li>The virtual processor processes the code and then the interpreter interprets the byte code and executes the instructions.</li><li>JIT is used to enhance the performance of the process by translating Java code into fast native machine code. It reduces the burden on the CPU.</li><li><strong>JIT Further</strong></li></ul><p>Not like in other compilers that translate the entire program into machine code before execution, JIT dynamically translates and optimizes the code at runtime, just before it is executed by the computer’s processor.</p><p>JIT can make decisions depending on the codes by analyzing the code behavior and characteristics of the performance such as applying techniques like inlining, loop unrolling, and dead code elimination</p><h4>Native Method Interface</h4><p>Is a framework that provides an interface to communicate with the applications written in languages other than Java.</p><h4>Native Method Libraries</h4><p>Collection of native libraries like C+, C#, C++, etc ..which are used by the execution engine.</p><h3>- Java Runtime Environment — JRE -</h3><ul><li>Java RTE is a set of software tools that are used to develop Java applications. But it does not contain any tool for Java development like a debugger, compiler, etc.</li><li>Therefore developer can write the code using JRE but cannot compile it.</li><li>It contains class libraries, loader class, and JVM</li><li>Unlike the JVM JRE physically exists.</li></ul><h4>JRE Functions</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*Na4fXC0kiSiKCahXONXERA.jpeg" /><figcaption>fig 03: JRE Functions</figcaption></figure><h4>JRE Architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*k0fG5udvCO7tQBclOWcY3g.jpeg" /><figcaption>fig 04: Java Runtime Environment Architecture</figcaption></figure><ul><li>rt.java</li><li>Contains math, swing, util, lang, awt, etc class libraries.</li></ul><h3>- Java Developmet Kit- JDK-</h3><ul><li>JDK is a software development environment for making Java applications.</li><li>Java developers can use the JDK on any platform like Windows, macOS, Solaris, and Linux.</li><li>It helps to code, compile, and run your code.</li><li>It is made out of the required tools to write a program and JRE to execute the program.</li></ul><h4>JDK Architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*tenSbaDXel_ZGaChREKMzg.jpeg" /></figure><h3>JDK Installation</h3><p>You can notice there are two kinds of JDKs, Oracle JDK and Open JDK. Mainly Oracle JDK is not free for commercial use and open JDK is free for commercial use.</p><p>Download <strong>Open JDK</strong>&#39;s newest stable version from below</p><p><a href="https://jdk.java.net/">JDK Builds from Oracle</a></p><p>Download <strong>Oracle JDK</strong> from below</p><p><a href="https://www.oracle.com/java/technologies/downloads/">Download the Latest Java LTS Free</a></p><p>You should download and set paths and Java home according to your OS.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b05a64eea71c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginners guide -Test automation environment setup — Eclipse -Java, Selenium, Maven]]></title>
            <link>https://lkprabha.medium.com/beginners-guide-test-automation-environment-setup-fd383e5cafdb?source=rss-145e3e4b00b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd383e5cafdb</guid>
            <dc:creator><![CDATA[BuddhiK]]></dc:creator>
            <pubDate>Sun, 13 Nov 2022 09:17:40 GMT</pubDate>
            <atom:updated>2022-11-13T09:20:43.981Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DiI1GKftoay2Tggiia4Zqw.png" /></figure><p><strong>Eclipse— Java, Selenium, Maven</strong></p><p>In this guide, I will walk you through the test automation project environment setup using Eclipse(IDE), Maven, java, and Selenium stack.</p><p>Following this guide, you can set up a project environment and run simple test automation.</p><h4><strong>What is Eclipse?</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*v6RPDclkT6P9_vQL8MsBiA.png" /><figcaption>Eclipse logo</figcaption></figure><p><strong>Eclipse</strong> is an open-source <strong>Integrated Development Environment (IDE) </strong>used for<strong> </strong>developing computer software. Eclipse contains a base workspace as well as extensible additional plugins to customize the environment. It is popular mostly among java developers. But it supports C/C++, Python, PERL, Ruby, etc. Eclipse always release under a public license so it is free to download and installed.</p><p>Below I’m explaining just the steps to follow to make a new project in Eclipse beginning with installing the required software packages.</p><p>Step 01: Install Java and Configure the java path.</p><p>Step 02: Install Eclipse</p><p>Step 03: Create a Java Project in Eclipse</p><p>Step 04: Add Selenium JARs to the project</p><p>Step 05: First Selenium Java code to land on a web page</p><p>STEP 06 : Add Geko Web Driver (GekoDriver — Mozzila firefox) / Webdrivermanager</p><h3>Step 01: Install Java and Configure the java path.</h3><p>Go to the command prompt and type,</p><p><em>java -version</em></p><p>If it is already installed will display the version below.<em>(fig 01)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*Bdf9_NXpxFUCdr9uqIEV1g.png" /><figcaption>fig 01</figcaption></figure><p>Or else you have to install java first.</p><p>Here I’m using the Windows platform. So I’m downloading java for windows.</p><ul><li>Java for Windows /Linux</li></ul><p><a href="https://www.java.com/en/download/">Download Java for Linux</a></p><h4>Configure java path</h4><ol><li>Right-click on MyComputer → Go to properties → Go to Advanced system settings. <em>(fig 02)</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*8OJrYFG5UGUaeUdo.png" /><figcaption>fig 02</figcaption></figure><p>2. Click on Environment Variables</p><p>Select the path variable and click on edit.</p><p>Then add the variable value to your jdk bin folder at the end of the path. <em>(fig 03)</em></p><p>ex :</p><p>C:\Users\Praba\projects\drivers;C:\Program Files\JetBrains\PyCharm CommunityEdition2020.3.3\bin;<strong>C:\Program Files\Java\jdk-11.0.2\bin;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*HobCSszhGjNbsaaK.png" /><figcaption>fig 03</figcaption></figure><p>3. Make new System variables for Java. (fig 05)</p><p>System variable section → New → Give the variable name → Variable value → Ok</p><p>example :(fig 04)</p><p>Variable name: JAVA_HOME</p><p>Value: C:\Program Files\Java\jdk-11.0.2\bin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*sJMcmYLk6fFjbhxzPuTzKw.png" /><figcaption>fig 04</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*7k2G9gP1dvRZXf3HQ5bsPg.png" /><figcaption>fig 05</figcaption></figure><p>Point the variable into the jdk bin folder.</p><ul><li><strong>JAVA_HOME should point to a JDK(Development kit), not a JRE(Java Run time Environment)</strong></li></ul><h3>Step 02: Install Eclipse</h3><p><a href="https://www.eclipse.org/downloads/">Eclipse Downloads | The Eclipse Foundation</a></p><p>Select the <strong>Download Packages</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Slju8921R6OLd7ISUneU2w.png" /><figcaption>fig 06</figcaption></figure><p>Then you will land on a page which contains different package downloading options for Eclipse. Select the required download option according to your OS and the system type from the “Eclipse IDE for Java Developers” section shown below. <em>(fig 07)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*RtG1EfZLqqqk6AMLGaB0jA.png" /><figcaption>fig 07</figcaption></figure><p>Then it will navigate you to the download page as below.<em>(fig 08) </em>Select the zip file and it will download to your machine. (fig 09)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*fhbMm42IfJDWaVQ-H9xgOw.png" /><figcaption>fig 08</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*01W5Sdq0HCbzMM7kH4XTZw.png" /><figcaption>fig 09</figcaption></figure><p>After completing the download go to your downloads and move your downloaded eclipse zip file to any required folder you want and extract the zip file. Then go into the extracted folder. Double-click on eclips.exe to launch.<em>(fig 10)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*J4QoVpY7YR_f_udH-zRy2A.png" /><figcaption>fig 10</figcaption></figure><p>Then it will ask for a specific directory to use as the eclipse workspace.<em>(fig 11)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*9eqx-aQhWvgBOZdX1zzUOw.png" /><figcaption>fig 11</figcaption></figure><p>You can change your desired workspace here and press launch.Work space will create according to the locations you have given.See below my workspace in my C:\Users\Praba\eclipse-workspace.<em>(fig 12)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*Y_nfUfHWAaYKT_aUQxm1kg.png" /><figcaption>fig 12</figcaption></figure><p>Then the eclipse welcome page will appear as below.You can explore the eclipse with overview , tutorials, samples and etc.<em>(fig 13)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*V1VqgIDslTjswsq4LAmRRA.png" /><figcaption>fig 13</figcaption></figure><h3>Step 03: Create a Java Project in Eclipse</h3><ol><li>Go to the package explorer → Create Java project<em>(fig 14)</em> or go to the File → New →Java Project <em>(fig 15)</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*6vXc-nqkUHATUrYgkTH4mQ.png" /><figcaption>fig 14</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*TfAdExQkn4YWDQ3GBTwNtQ.png" /><figcaption>fig 15</figcaption></figure><p>Then the new Java Project window will appear.Give a name for your project and press Finish.<em>(fig 16)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*xOdh_EjQWK9MQdxBWfZlQw.png" /><figcaption>fig 16</figcaption></figure><p>Then your first java project created as below.<em>(fig 17)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t5dWtg1syjHuE5lk8ZjUPA.png" /><figcaption>fig 17</figcaption></figure><h3>Step 04 : Add Selenium JARs to the project</h3><p>To download the selenium JARs go to</p><p><a href="https://www.selenium.dev/downloads/">Downloads</a></p><p>Get the latest stable version of selenium.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T-oTbimyesAaHBD1mPIdZQ.png" /><figcaption>fig 18</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*EBokgYFbJ-BSZ9Z_qEWnOQ.png" /><figcaption>fig 19</figcaption></figure><p>Or else you can only download the selenium client and webdriver bindings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9AS9MeD-NEDCr_vC6hxetQ.png" /><figcaption>fig 20</figcaption></figure><p>To add the jars to the project go to your project → Rightclick on your project → Build Path → Configure Build Path</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*SXKu9sD61qPvMHDsmUvyjw.png" /><figcaption>fig 21</figcaption></figure><p>Then the properties for your java project will appear.In there Select Java build path’s Libraries section → Classpath → Add External JARs → Select the Selenium Jars → Apply and Close.(fig 22)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*Vlqof5aVAT46YhuxGn16lA.png" /><figcaption>fig 22</figcaption></figure><p>Go to your project and see the JARs added successfully under the reference lib section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*YzmO9W7c7c1b5Gk9JXCDxg.png" /><figcaption>fig 23</figcaption></figure><h3>Step 05 : First Selenium Java code to land on a web page</h3><p>Right click on the project → New → Class</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*_V9Wn6CUqo-UR90E-5oqgw.png" /><figcaption>fig 23</figcaption></figure><p>Give a name for your class → tick public static void main(String[] args) to make your class the main class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*McwHu5vPU3jRppygYNz0Bw.png" /><figcaption>fig 24</figcaption></figure><p>Then the main testCaseOne class appear as below.(fig 25)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*GhM8mlE65xCqCMAkdXbW3w.png" /><figcaption>fig 25</figcaption></figure><h3>STEP 06 : Add Geko Web Driver (GekoDriver — Mozzila firefox)</h3><p><strong>GeckoDriver</strong> is a link between Selenium tests and the Firefox browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/0*1hLtYcYdX6a6ONjQ.png" /></figure><p>For Mozilla Firefox till version 47, we never needed GeckoDriver. But Mozilla Firefox after version 47, comes with Marionette, which is an automation driver for Mozilla.</p><p><a href="https://github.com/mozilla/geckodriver/releases">Releases · mozilla/geckodriver</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*_RHMhmxr8wRjmDeK.png" /></figure><ol><li>Download Gekodriver for your computer.</li><li>Restore the .exe file in the GekoDriver package</li></ol><p>If you want to download Chrome Driver instead of Geko driver go to the Selenium dev site.</p><p><a href="https://chromedriver.chromium.org/downloads">ChromeDriver - WebDriver for Chrome - Downloads</a></p><p>Lets start to code .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gtBirtX3U2-tZvrdy7Z2xQ.png" /><figcaption>fig 26</figcaption></figure><p>Here I have set the system property key-value pair to<strong> key as geko driver</strong> and the value to the <strong>path to where the geko driver exe located</strong> in the project.</p><p>Then created a Firefoxdriver new object and as it to get the required URL. Then maximize the window.</p><p>To run the class right click on the class → Run As → Java Application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oUxxJGl8a2ofN5UPT15GfA.png" /><figcaption>fig 27</figcaption></figure><p>Then the automated browser will appear as below. You can note that the browser is under remote control. (reason marionette)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tt7xHHFGekOfRA4r3apqow.png" /><figcaption>fig 28</figcaption></figure><h3>Maven</h3><p>Maven is by default in eclipse preference. To see go to Windows → Preferences</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*BHXMfN8pxxFSbZdVBy1ssw.png" /><figcaption>fig 29</figcaption></figure><h3>Creating Maven Project</h3><h4>What is Maven?</h4><p><strong>Apache Maven</strong> is a software project management and comprehension tool based on a <strong>P</strong>roject <strong>O</strong>bject <strong>M</strong>odel (<strong>POM</strong>) concept. Maven can</p><ul><li>manage a project’s build</li><li>reporting and documentation from a central piece of information.</li></ul><p>Go to eclipse → New → Project → Maven Project → Next</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*2K9geNF7mrmcFmAPRDu5cA.png" /><figcaption>fig 30</figcaption></figure><p>Go next and fill required field below and press finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*q5VtPBCKzBGH85cdx5kVDA.png" /><figcaption>fig 31</figcaption></figure><p>Then you can see the well structured handy project created as shown in fig 32 below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/1*Tmh6YkTgxldwkwOvZAwWfA.png" /><figcaption>fig 32</figcaption></figure><h4>pom.xml File</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*ZJ3OwcVCSg47LlLb1_kRQw.png" /><figcaption>fig 33</figcaption></figure><p><strong>pom</strong>. <strong>xml</strong> is an XML file located in the root directory of your project. The <strong>pom.xml file </strong>contains</p><ul><li>information about the project</li><li>packages we used in the project</li><li>and various configuration detail used by Maven to build the project</li></ul><p>To add selenium dependencies go to the selenium download page → Maven Information → MVNRepository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q6tlKpiBFr2PjYNTn3o8mw.png" /><figcaption>fig 33</figcaption></figure><p>It will redirect you to</p><p><a href="https://mvnrepository.com/artifact/org.seleniumhq.selenium">https://mvnrepository.com/artifact/org.seleniumhq.selenium</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4g48kRJETWLD_kNk7VMVuA.png" /><figcaption>fig 34</figcaption></figure><p>Select Selenium Java.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zbgeT51rB51OlacCY0hjTA.png" /><figcaption>fig 35</figcaption></figure><p>Select stable version and copy the code as shown as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hKAfKcyojuJgNJWZyBStA.png" /><figcaption>fig 36</figcaption></figure><p>Go to your pom.xml file in the project and add a dependencies tag. Inside the dependencies, tag adds the new dependency you have copied. <em>(fig 37)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*Lk0clfFP5aDiRH9ZaE9vew.png" /><figcaption>fig 37</figcaption></figure><p>Once you save the pom.xml file the maven dependencies are added to the local automatically from the central repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*MrQEAXSigK-pcxiqypBYRQ.png" /><figcaption>fig 38</figcaption></figure><p>Go to your Project → Src/test/java → Crate new main class very similar as shown in the example above. Then add the piece of code below to automate the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FmHIiwBMysTZlTKEk89Oyw.png" /><figcaption>fig 39</figcaption></figure><p>Right-click on the class and run it as a java application. Then you will see the automated browser landing on the amazon.com site and automatically search for apple watches as per our piece of code in the TestCaseOne.java.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SL1dYK2T5Nq5bts79mtW7Q.png" /><figcaption>fig 40</figcaption></figure><h4>Manage browser drivers -Webdrivermanager</h4><p>In our TestCaseOne.java we provide the path to the browser driver exe. This is not much practicable when we working on a project. So Webdrivermanager will make it easy and automate manual downloads and locating on your locals and much more.</p><ul><li>It verifies the version of the browser(eg chrome, firefox, Edge, etc.)</li><li>If it is unknown then it automatically uses the latest version of the driver(chromedriver, geckodriver, etc.)</li><li>It downloads the webdriver binary if it is not available in the cache.</li><li>It will export proper webdriver java environment variables required for selenium.</li></ul><p>For further studies go to,</p><p><a href="https://bonigarcia.dev/webdrivermanager/#setup">WebDriverManager</a></p><h4><strong>Steps to add Wedrivermanager to your project</strong></h4><ol><li>Go to</li></ol><p><a href="https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager/5.3.1">https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager</a></p><p>2. Select the latest and most stable version of the webdrivermanager . Copy the code.</p><p>3. Go to your pom.xml.Place your copied codes within the dependencies tags and save.</p><p>4. Go to your test case and remove your code part of System.setProerty .</p><p>5. Save and run it as a java application. You will see the same outcome as before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*yYfX_6_Xm2-w4XowsKjRqw.png" /><figcaption>fig 41 — pom.xml</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*udC4ibMav_Ue7YMNajiVag.png" /><figcaption>fig 42 — TestcaseOne.java</figcaption></figure><h4>A most common error you might face</h4><h4>- Project cannot be built until build path errors are resolved eclipse</h4><p>This is the most common error you will get into. This is actually due to jre version mismatch. To correct it go to yours go to ,</p><p>Package Explorer → Right Click → Build Path → Configure Build Path → Libraries</p><p>Check whether the version of the jre library is correct.</p><p>If not Delete the appeared library in the window and then press</p><p>Add Library → JRE System Library → Environments → &lt;Select your required library&gt; → Finish.</p><p>So hope you understand the environment setup clearly. Stay connected for upcoming tech stories!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd383e5cafdb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Cloud Practioner Exam Guide]]></title>
            <link>https://lkprabha.medium.com/aws-cloud-practioner-exam-guide-1ba1cd016c3d?source=rss-145e3e4b00b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ba1cd016c3d</guid>
            <category><![CDATA[aws-cloud-practitioner]]></category>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[BuddhiK]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 00:20:45 GMT</pubDate>
            <atom:updated>2023-02-27T22:12:28.662Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction to Cloud Computing</h3><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*_yfJ6305GkWXslEILtbSOA.png" /></figure><p>In this guide, I will walk you through the basic understanding of cloud computing you should be aware of.</p><h3>Why Cloud Computing?</h3><p>Cloud computing has become a much-needed and handy tech over the past few years.</p><p>Let’s take a suit and tuxedo renting shop as an example to discuss this further.</p><p>The core business is renting suits for any kind of event. So the customer just has to rent out the suit they choose and pay for hours they are planning to keep the suit with them.</p><p>The customer does not have to worry about the cost of the materials of the suit, sewing fees, ironing, and dry cleaning processes, and other maintenance costs. The customer only uses the suit and pays for the duration he uses it. By using this rental service customer benefits in many ways.</p><p>Think that you are planning to start an online business and it has its own web application. In the initial stage, you may buy a computer, server, routers, and other networking devices required to maintain your online web application. So you have to spend on basic IT infrastructure and have to maintain them. Later the business expanded due to high demands and then your capacity of IT infrastructure may not be enough to handle the customer load.</p><p>Then you have to invest more in IT infrastructure. The more you expand the hardware and resources, the more you have to maintain. Then think about a worst-case situation like your business suddenly losing some of the customers and now there is no meaning in maintaining and keeping a lot of servers and IT infrastructure. Then all that you spend on the business become such a waste of money. You cannot resell all the unwanted items for the prices you have to buy them. So it will become a great loss.</p><p>Usually, businessmen/women may not like to take that kind of risk for their businesses. In that case, here come the cloud computing service solutions at your service.</p><p>Because of the high availability, elasticity, scalability, security, adopting options they provide and specialist service, easy options for migrations, and many more benefits, most businesses nowadays very much like to go with cloud computing services.</p><p>This will explain more in upcoming sub-topics.</p><h3>What is Cloud computing?</h3><p>Before we start digging into cloud computing let’s begin by understanding the technology term “Client-server architecture” because this will be very useful for you to understand more about cloud computing.</p><h4>Client Server Architecture</h4><p>Most people nowadays experience client-server architecture in day-to-day life through their smartphones, laptops, tablets, etc.</p><p>For example, take a hotel reservation online site. You may go to the site and enter your required details such as which dates you are looking to a booking, no of guests you have, etc. Then you will press the search button to make a request from the hotel side to get the relevant details. Then your request went to the hotel side through the website and they will respond with relevant data according to the request you make. Such as the availability of requested dates, the options you have when selecting rooms according to the number of guests, ongoing promotions, etc.</p><p>Here your smartphone act as the client. And the hotel-side response made by the server. So in this example, many clients can request information from the above server.</p><p>So any user who seeks information is called a client and any provider who provides the relevant information is called a server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iz1YZb3TE2NoTctHSpeuSQ.gif" /><figcaption>Simple client-server architecture</figcaption></figure><p><strong>In cloud computing, this server can be a cloud service.</strong></p><p>Cloud computing is delivering on-demand computer system resources and technology services like data storage, servers, databases, networking, and software over the Cloud.</p><p>Since we are preparing for the AWS Cloud Practioner Exam let’s see how AWS defines cloud computing.</p><p><strong><em>“Cloud computing is the on-demand delivery of IT resources over the Internet with pay-as-you-go pricing. Instead of buying, owning, and maintaining physical data centers and servers, you can access technology services, such as computing power, storage, and databases, on an as-needed basis from a cloud provider like Amazon Web Services (AWS).”</em></strong></p><p><a href="https://aws.amazon.com/what-is-cloud-computing/">What is Cloud Computing? - Cloud Computing Services, Benefits, and Types - AWS</a></p><h4>What is “ On-demand delivery of resources “</h4><p>Think that you have started a little business and need 2 virtual servers for your business initially. So you start with that amount and then a few months later, you realize that you need more space and want to make 10 virtual servers. Then you run your business smoothly. But suddenly some of your customers left and you cannot afford 10 servers. Then you adjust with 5. So all these scenarios are possible with cloud computing.</p><p>You can use any amount of resources at any time.</p><p>Before cloud computing, this type of situation was tough to manage. Think that you have to buy all of these physical servers by yourself on behalf of the business. Then it will be an extra cost to purchase these resources, maintain these computer-related resources, and pay bills for consuming energy. Assume that when you don’t need many servers as per the earlier case, you cannot return the servers where you buy them. Therefore you have to either keep them or sell them for the lowest prices.</p><p>So<strong> on-demand delivery of resources </strong>is an excellent advantage for the users of cloud computing services.</p><h4>What is “ Pay-as-you-go pricing “</h4><p><strong>You have only to pay for what you exactly use.</strong></p><p>For example, think about your water bill. You have to pay for what you consume. And think about a postpaid internet connection. You pay for what you used.</p><p>Likewise in cloud computing services, you have to pay exactly what you used.</p><h3>Cloud providers and their services</h3><ul><li>Amazon Web Services</li></ul><p><a href="https://aws.amazon.com/">Cloud Computing Services - Amazon Web Services (AWS)</a></p><ul><li>Google Cloud Platform</li></ul><p><a href="https://cloud.google.com/">AI and Cloud Computing Services</a></p><ul><li>Microsoft Azure</li></ul><p><a href="https://azure.microsoft.com/">Cloud Computing Services | Microsoft Azure</a></p><ul><li>IBM Cloud</li></ul><p><a href="https://www.ibm.com/">IBM - United States</a></p><ul><li>Alibaba Cloud</li></ul><p><a href="https://my.alibabacloud.com/">Empower Your Business in Malaysia with Alibaba Cloud&#39;s Support in Digital Transformation</a></p><h4>Cloud Service models</h4><p>Depending on the services the provider provides there are a few main models in cloud services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*gZx-T_at8v5idm-Gm_98RQ.png" /></figure><h4>- Infrastructure as a service (IaaS)</h4><p><strong>Getting only the infrastructure from the cloud.</strong></p><p>example: Servers, Networking features, data storage, or any other virtual or dedicated hardware</p><p>Since you are only taking the infrastructure you have full control of managing the underlying infrastructure. (patches, upgrade SW)</p><h4>- Platform as a service (PaaS)</h4><p>Here cloud providers manage the underlying infrastructure. The cloud provides a platform to implement the service. It makes it easy to focus on the deployment and management of your application.</p><h4>- Software as a service (SaaS)</h4><p>Cloud will provide you directly with the application or Software. So you do not have to manage service or infrastructure. Provides complete product that runs and is managed by the service provider. Only have to think about how to use the particular software.</p><p>example: Like organizations are using Gmail.</p><h3>Deployment Methods</h3><p>There are three main deployment models in the cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*5EcMm-U1OaZiRtl2qNtf3w.png" /></figure><h4>Cloud-Based Deployment :</h4><p>The cloud-based deployment method is used for designing and building a new application, migrating applications to the cloud you already have, or just running some of the parts of an application in the cloud.</p><p>Hardware, software, and other supporting infrastructure are owned and managed by the cloud provider. Services and infrastructure are shared by multiple customers and work as a virtual private cloud.</p><h4>On-Premises Deployment (Private cloud)</h4><p>Resources are deployed using virtualization and resource management tools. Services and infrastructure are maintained on a private network.</p><h4>Hybrid cloud</h4><p>Combination of the public and private cloud where cloud-based resources are connected to on-premises infrastructure.</p><p>Ex: Your application is well-stable on your premises and it is based on legacy technologies. So the application maintained within your on-premises deployment model and other facilities as analytics and data processing could be based on a cloud-based deployment model.</p><h3>Benefits of Cloud Computing</h3><ol><li><strong>Trade Upfront expenses for variable expenses</strong></li></ol><p>Before spending on resources without knowing how you are going to use them you can pay only for what you use.</p><p><strong>2. Stop spending money to run and maintain data centers</strong></p><p>You don’t have to worry about spending money on and maintaining infrastructure. Cloud providers will do these for you and then you only have to focus on your business.</p><p><strong>3. Stop guessing capacity</strong></p><p>You do not have to guess the capacity prior and pay for more resources or handle your work with fewer resources due to bad guessing of the number of resources you wanted. You can access whatever amount of capacity you needed. (Scaling up and down the capacities.)</p><p><strong>4. Benefit from massive economies of scale</strong></p><p>Since there are many other users using the cloud you will have to pay the lowest cost for what you use.</p><p><strong>5. Increase speed and agility</strong></p><p>By reducing the time and cost to make resources available organizations can accelerate their work.</p><p><strong>6. Go global in minutes</strong></p><p>Easy to deploy your application in minutes around the world. (Making available in multiple regions within a few clicks)</p><p>Since AWS is providing so many services free to play with, let’s create an Amazon account for future uses.</p><h4>- Creating an AWS account</h4><p><a href="https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-creating.html">Create an AWS account</a></p><p>Once you create your AWS account then log in and expand the services to see the available services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*GHO2I-Bf8U15T8w51FrxOw.png" /></figure><p>According to the above image, you can see all the available services categorized.</p><p>Stay tuned. With the next guides, I will walk you through these services. Hope the guide helps you a bit in your journey.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ba1cd016c3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginner guide to Selenium WebDriver]]></title>
            <link>https://lkprabha.medium.com/beginner-guide-to-selenium-webdriver-51b33961314e?source=rss-145e3e4b00b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/51b33961314e</guid>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[qa-testing]]></category>
            <category><![CDATA[selenium-test-automation]]></category>
            <dc:creator><![CDATA[BuddhiK]]></dc:creator>
            <pubDate>Wed, 22 Dec 2021 10:02:12 GMT</pubDate>
            <atom:updated>2021-12-22T10:08:02.790Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*4QXgLU-QvTSd2woJxn6X0w.png" /></figure><h3><strong>Selenium Web Driver Beginner Guide</strong></h3><p><strong><em>Guide 01</em></strong></p><h3>Introduction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/211/1*kspUQOiqRV88aoCMiswthw.png" /></figure><h4>History</h4><p>Let me start with an interesting story about naming this product kit by the name of ‘selenium’.</p><p>If anyone is quite curious about this topic you can dig into the internet and will be able to find this same story with different versions.</p><p>In <strong>2004 Jason Huggins, an engineer working on a web project,</strong> realized that he has to repeat the same manual test cases more frequently. So to make this efficient he wrote a JavaScript program to automate the browser actions. He named it “JavaScript test runner” and later made open-sourced this test runner and renamed it “<strong>Selenium Core</strong>”.</p><p>While the selenium development going on there was another popular test framework QTP made by a competitive company “Mercury Interactive”. Later QTP was taken by HP.So some say Jason Huggings crack a joke in their daily meeting and some say he mentioned in their group email, that the“Selenium will cure the mercury poisoning. Because the Selenium is an antidote in the treatment of mercury intoxication. To give competition to Mercury Interactive so the team took the name “Selenium”.</p><h3><strong>What is Selenium?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/203/1*TI0y0QjMKzzfaFS8r5uztA.png" /></figure><p>Selenium is an automated testing framework. It’s free and open-source. We can use it within different platforms like Windows, Linux, Mac OS, Solaris, and over multiple browsers like Chrome, Firefox, InternetExplorer, Opera, etc.</p><p>And we can use multiple client libraries to bind with selenium. (Java, Python, C#, Rubby.)</p><h4>Selenium Product Kit :</h4><p>Under the selenium product, there are</p><ul><li><strong>Selenium IDE</strong>: <strong>Selenium IDE</strong>(Integrated Development Environment) is primarily a record/run tool that a test case developer uses to develop selenium test cases.</li><li><strong>Selenium RC</strong>: <strong>Selenium Remote Controller</strong> is now not in use. It was a testing framework that enables a QA or a developer to write test cases in any programming language in order to automate UI tests for web applications against any HTTP website. By improving SRC then the Selenium web driver was created.</li><li><strong>Selenium Web driver: </strong>Selenium Web driver is an open-source collection of APIs which is used for testing web applications. The Selenium Web driver tool is used for automating web application testing to verify that it works as expected or not.</li><li><strong>Selenium Grid: </strong>Selenium Grid is used with the SRC to perform parallel runs of multiple test cases within the same time in different browsers and machines.</li></ul><p><strong><em>Download link: </em></strong><a href="https://www.selenium.dev/"><strong><em>https://www.selenium.dev</em></strong></a></p><h3><strong>Selenium Web Driver</strong></h3><p>Selenium web driver is an open-source collection of APIs as mentioned above. It facilitates the user to automate any of the modern browsers.</p><h4><strong>Selenium web driver Architecture</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nXtajUv7900dGpQjqufUpw.png" /></figure><p>As mentioned in the diagram above, Java, JavaScript, Python, C#, and Rubi have Selenium support client libraries. Selenium client libraries are different kinds of jars. The client libraries(jars) contain nothing but classes and methods of selenium web drivers which use to write automated test scripts.</p><p>ex: If you are writing your test script in java, you need to install selenium client libraries.</p><h3>Selenium Installation</h3><p>All the support language binding libraries are available on Selenium&#39;s official site where you can download and install.</p><p><a href="https://www.selenium.dev/downloads/#client-drivers">Downloads</a></p><p>Your automation test script can use the selenium client libraries and bind with the selenium. Here selenium client libraries act as an API to execute the selenium commands.</p><p>Using browser drivers which are supporting the real browsers we can interact and automate the browser activities of the real browsers.</p><p>ex:</p><ul><li>Geko driver — Firefox</li><li>Chrome driver</li><li>Chrome Browser</li><li>Internet Explora driver</li><li>Internet Explora browser</li><li>etc.</li></ul><p>If you are making a java maven project then the selenium bindings can be imported to the project via pom.xml by adding dependencies as below.</p><p><a href="https://mvnrepository.com/">https://mvnrepository.com/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*adA6gt28ci7f2DG2RGgPXg.png" /></figure><p>In addition, you have to add the relevant dependencies to the pom.xml which browsers you are planning to run the test automation.</p><p>ex: Firefox</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*RzKoKz4jbeQ4tQQP1Zts4A.png" /></figure><h4><strong>What is JSON Wire protocol?</strong></h4><p>JSON stands for JavaScript Object Notation. Its uses as a data exchange format among the client and servers on the web which supports any data format available in languages Java, C#, Python, Ruby, etc.</p><p>When we look furthermore at the JSON wire protocol it is using REST API to transfer the data between HTTP servers. (Each web driver browser has its own HTTP server)</p><p>Then the browser will handle the rest of the part as same as a simple client-server architecture. That means the HTTP connection will establish between the client and the server. And will be able to communicate(http request/response) with XML/JSON.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*kkzWI5AWUIDlbVnqQFpjLQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*Wia9Pn_WDyltmxKMbn-03w.png" /></figure><h4><strong>Web drivers API are available in Selenium</strong></h4><ul><li>FirefoxDriver.</li><li>InternetExplorerDriver.</li><li>ChromeDriver.</li><li>SafariDriver.</li><li>OperaDriver.</li><li>AndroidDriver.</li><li>IPhoneDriver.</li><li>HTMLUnitDriver.</li></ul><h4><strong>Languages support Selenium web driver</strong></h4><p>Java, Python, Ruby, C#, JavaScript, Perl, and PHP.</p><h3>Selenium web driver Locating Strategies</h3><p>To automate your test script first you should know the basics of locating the web elements in a web page.</p><h4>Inspect an element of a web page</h4><p>For example, just consider the login page of a web application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*9gEacbVd5kNMARj_lSNS4w.png" /></figure><p>Consider a simple test scenario for this page.</p><p>example :</p><ol><li>The user enters the user name.</li><li>The user enters the password.</li><li>User press login button.</li><li>Then the user sees the welcome page.</li></ol><p>So to automate the page given above we should know how to locate the user name text input field, password field, and then the login button in the web page for a basic level of automation script.</p><p>To inspect the element</p><p>shortcut :</p><p>Short cut for chrome (windows) — Ctrl + shift + c</p><p>Long way :</p><ol><li>First press F12 to see the developer tool where you can see the internal structure of the page.</li></ol><p>ex:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NZ3RDvjHhhqKVp51G0pqjw.png" /><figcaption>when you press F12 you will see the developer tools</figcaption></figure><p>2. Right-click on the element you need to inspect. And select inspect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*4ei8zYEdmyN472KE7fXcMQ.png" /></figure><p>3. Decide the best way to locate the element by using Locator selecting options.</p><p>4. Optional: You can test whether your actually locating the selector in the console with xpath, css selector.</p><p>ex: inspecting an input field with id = “id_fullname”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*qS2IADg6HanUaKBML89n0g.png" /></figure><p>With the console, you can be sure about the accuracy before you add the element locating a piece of code segments into the program.</p><p>This is a bit difficult and complex work sometimes. So we can use addons and tools to pic the element. Most industrial practices to using addons and tools to pic the element.</p><h4>Element Locating Extensions/Addons</h4><p>FireFox Browser</p><p>ex: Firebug, FirePath, Xpath Finder for firefox</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*mFGED5P_fclSKv0C_FIZoA.png" /><figcaption>firefox browser addon — firebug</figcaption></figure><p>Chrome browser</p><p>01. XPath Finder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PHcy0CDJ5w44LyBRoSAXbQ.png" /></figure><p>02.SelectorsHub</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4EOq4ehzWlmvxlPzMWcjLw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1KYf9mzfhFtd2RwvvL4kMA.png" /></figure><p>04.RexPath</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*HWqoElATMVmpHQS7di791A.png" /></figure><p>05. Firebug Lite for Chrome</p><p>Support to inspect HTML elements and compute CSS styles.</p><p><a href="https://getfirebug.com/index.html">Firebug</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*cRE9DzI6fV4E0bTWcJKXog.png" /></figure><p>06.TruePath Extension</p><p>the true path extension generates the relative Xpath .</p><p><a href="https://chrome.google.com/webstore/detail/truepath/mgjhkhhbkkldiihlajcnlfchfcmhipmn">TruePath</a></p><h3>Selenium Locators</h3><p>Selenium locators use to identify the Elements such as text fields, buttons, checkboxes, radio buttons, etc. This should be done more carefully and with onhand experiences, otherwise, you will end up with a faulty test script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TvsPA15VQAIxwKyyJWD9Zg.png" /></figure><p>Sometimes it is easy to locate the elements with their id, name, class name, tag name, and text name since they are very unique for the element.</p><p>ex :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*Jbm1Bdx2W4nzXMJKLIoUFg.png" /></figure><h3>css selector</h3><h4>what is css?</h4><p>css stands for cascading style sheets. It is a language that use in html pages to easily style the webpages. Basically, css explains the web elements to how they should be displayed within the webpage.</p><h4>css selectors types</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RQu-dNnPRQ2HGK8wh7QCgQ.png" /></figure><h3>Xpath : XML path Language</h3><p>XPath is used to navigate through the elements and attributes in an XML structure of an XML/HTML document. Xpath is normally used when an element cannot locate by id, name, class, etc.</p><p>Xpath is just like we use the file structures in our computers. For example, my lecture notes are located in E:\Zoom\Maths\Lecture_01.pdf</p><p>This means my maths Lecture_01.pdf is located in: Go to E drive inside it there is a folder call Zoom. Inside this Zoom folder, there is another folder called Maths. Inside the Maths folder, there is my Lecture_01.pdf</p><p>Likewise, we can navigate through the XML/HTML document/page as mentioned below.</p><p>Example: consider the search text box by the name and id =’q’ here. Let&#39;s inspect the element and see what will be the XPath is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wyF23InQ6P1ew5-3T6n2sQ.png" /></figure><p>Here my relative xpath is //input[<a href="http://twitter.com/id">@id</a>=’q’]</p><p>means navigate to where input id =’ q&#39;s. This is applicable and suits when only there is one element id=’q’ is exists. If there are many of them then it will return a list of elements that fulfill the requirement.</p><p>Again consider that I have many files called Lecture_01.pdf on my PC.So If I search for Lecture_01.pdf on my computer then all the results will show. But if I have only one unique file then only one will display as the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oVRBIv0iyefmQh4hAut2qA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LgsN4GMBGvrYerkr5ZvxHA.png" /></figure><p>Aabsolute path is as below.</p><p>/html[1]/body[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[2]/form[1]/div[1]/div[1]/input[1]</p><p>This describe the whole structure/path to navigate to the input field called q.</p><h4><strong>Absolute Xpath Vs. Relative Xpath</strong></h4><h4>Absolute Xpath :</h4><p>Lets take the above example.</p><p>/html[1]/body[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[2]/form[1]/div[1]/div[1]/input[1]</p><p>Here the path is described from the very beginning. Here HTML page in body, in divs likewise. It very clearly navigates to the exact element. Absolute Xpath starts with syntax /.</p><p>Disadvantage: Think that if we change any div due to some reason in the design. Then the whole Xpath will fail to locate the exact element.</p><h4>Relative Xpath :</h4><p>When we consider the above example relative path is //input[<a href="http://twitter.com/id">@id</a>=’q’]. It explains to find an input field in which id is equal to q.</p><p>Normally relative path can be written by starting from anywhere from the DOM structure.Syntax starts from // .The relative path is the most effective one compared with the absolute.</p><p>Will discuss more and dig in deep further with the coming up next story !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51b33961314e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginners guide — Test automation environment setup]]></title>
            <link>https://lkprabha.medium.com/beginners-guide-test-automation-environment-setup-65330345f492?source=rss-145e3e4b00b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/65330345f492</guid>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[intellij]]></category>
            <category><![CDATA[cucumber]]></category>
            <dc:creator><![CDATA[BuddhiK]]></dc:creator>
            <pubDate>Thu, 19 Aug 2021 16:25:12 GMT</pubDate>
            <atom:updated>2022-11-13T09:20:32.290Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KsA6_JYqufTLJjgsVV_NdQ.png" /></figure><h3><strong>Beginners guide -Test automation environment setup — IntelliJ — Java, Selenium, Maven, Cucumber</strong></h3><p><strong>IntelliJ — Java, Selenium, Maven, Cucumber</strong></p><p>In this guide, I will walk you through the test automation project environment setup using IntelliJ(IDE), Maven, java, Selenium, and Cucumber stack.</p><p>By following this guide, you can set up a project environment and run simple test automation.</p><p><strong>What is Intellij?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/184/1*mGyxCx0aqdTJKVScddbroA.png" /><figcaption>Computer Software</figcaption></figure><p>IntelliJ IDEA is an <strong>Integrated Development Environment (IDE) </strong>written in Java for developing computer software. Below I’m explaining just the steps to follow to make a new project in IntelliJ beginning with installing the required software packages.</p><p>Before proceeding check whether you are having java on your computer or not. Go to the command prompt and type,</p><p><em>java -version</em></p><p>If it is already installed will display the version as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*pBpZDMsF7VdwsEaxRAAAUw.png" /></figure><p>Or else you have to install java first.</p><ol><li><strong>Install JAVA</strong></li></ol><p>Here I’m using the Windows platform. So I’m downloading java for windows.</p><ul><li>Java for Windows /Linux</li></ul><p><a href="https://www.java.com/en/download">Download Java for Linux</a></p><p><strong>2. Install IntelliJ IDEA community — for windows</strong></p><p>Here I have selected the community edition since it is free. If you want, you can select the ultimate over the community edition. There are many features included in ultimate other than the community edition.</p><p><a href="https://www.jetbrains.com/idea/download/#section=windows">Download IntelliJ IDEA - The Leading Java and Kotlin IDE</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*oAyXGTtn3w2pOS5t_vvwYA.png" /></figure><p><strong>3. MAVEN DownLoad</strong></p><p><strong>Apache Maven</strong> is a software project management and comprehension tool based on a <strong>P</strong>roject <strong>O</strong>bject <strong>M</strong>odel (<strong>POM</strong>) concept. Maven can</p><ul><li>manage a project’s build</li><li>reporting and documentation from a central piece of information.</li></ul><p><a href="https://maven.apache.org/download.cgi">Apache Maven</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XikdE_TFe2RTrC40ASrrFQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5qXDim-SQYZNI3QlpJFr1w.png" /></figure><p><strong>4. Set system path variable</strong></p><p>After downloading and setting up Java, IntelliJ, and Maven, you must set the system paths.</p><p>Right-click on MyComputer → Go to properties</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*gzcqPNDL58hkZA73LtV6Mg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r7P4pHr6sMnkTXKMsC2WQQ.png" /></figure><ul><li>Make new System variables for Java and Maven</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*F5t8aAyWmdf7ZEhzdHHR9A.png" /></figure><p>Ex :</p><p>JAVA_HOME -C:\Program Files\Java\jdk-11.0.2\bin</p><p>MAVEN_HOME -C:\Program Files\apache-maven-3.8.1-bin\apache-maven-3.8.1</p><p><strong>Verify you have installed Maven correctly.</strong></p><ul><li>Type mvn -version in cmd prompt. If it is ready to use will indicate below the version you have.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*gng1TkYGkutgXPk6vYVkXg.png" /></figure><p>If not you will get the below messages</p><p><strong>Two most common error messages</strong></p><ul><li><strong>‘mvn’ is not recognized as an internal or external command</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*9p2a8VOnhUyRCSAoJ7Yzsg.png" /></figure><p>Solution: Set the %MAVEN_HOME%\bin is added to the PATH system variable.</p><p><strong>*JAVA_HOME should point to a JDK(Development kit), not a JRE(Java Run time Environment)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*R9pHc9QGwiSIE9OpfgOaiw.png" /></figure><p>Solution: Verify JDK is installed and the JAVA_HOME system variable is configured.</p><p>ex :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*fv0qY8QRd6lQOrHnTBBnJA.png" /></figure><h4>5. Create a New Project n IntelliJ IDEA and add plugins cucumber and gherkin.</h4><p>Open IntelliJ IDEA</p><p>Add pluggings to the project</p><ul><li>Cucumber for Java</li><li>Gherkin Plugin</li></ul><p>a. Go to File → Settings → Plugins → Marketplace</p><p>To install ‘Cucumber for Java’ first you have to install the Gherkin plugin. Then install Cucumber for plugging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*pI2fQWudx6kGb_qNAIeZ4Q.png" /><figcaption>Warning</figcaption></figure><p>b. Add the Gherkin plugin and then add the Cucumber plugin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uvFYCwyVTnivj-ci0MsrhA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ODlwloi-HgVkNR5wbNqtVQ.png" /></figure><p>c. After installing you can check whether the pluggings are already installed in the Installed section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*Ubi1bnA-Z6522wGYHc0Zjg.png" /></figure><p><strong>Making New Project in IntelliJ</strong></p><p>a. File → New → Project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*QZWtFZwKEeQprh_O14SLQw.png" /></figure><p>b. Here you should select the JDK version of your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*FDaOcZGtcFzO6nFyX0ZIMw.png" /></figure><p>c. Select Maven and then click on Next</p><p>d. Enter the project name as you preferred and then you can fill artifact coordinated accordingly. group-id etc… and then finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*h6bKlBLkqopBohaw-96znQ.png" /></figure><p>Here is the view of your newly created project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aYQkcLfwwoWBhMFtKwGkKw.png" /></figure><p><strong>6. Add Selenium dependencies</strong></p><p>All the external libraries that you want within the project can be added as dependencies to the pom.xml file. Maven has an excellent feature to automatically download the dependencies in pom.xml from the central repository to your local. So you don’t need to download and locate those in your local. Let&#39;s see how we can do it.</p><p>a. Go to the maven central repository.</p><p><a href="https://mvnrepository.com/">https://mvnrepository.com</a></p><p>b. Search dependencies for “Selenium java”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ptimnoIN7IOhNlzD3sAEzQ.png" /></figure><p>c. Select the Selenium Java “ org.seleniumhq.selenium”</p><p>d. Select a relevant and stable version. (You can check the usage)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z_u-4sR9D8sG_Ho3_UYf5A.png" /></figure><p>f. Copy the code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*AxHTpPk1b2Qk1ZUjj92pQA.png" /></figure><p>g. Go to your pom.xml file</p><p>h. Open tags for dependencies and paste the piece of code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*ZffXfsp4Uy_-tbSVLNaiEQ.png" /></figure><p>i. add other dependencies as same as we have done this.</p><p>e. After modifying the pom.xml press the refresh icon to download all the dependencies files from the central repository to the local repository.<br>After all, files are downloaded from the central repository to the local repository it will appear as done with a tick mark. (See below topic pom.xml)</p><h4>7. Add the web driver (GekoDriver — Mozzila firefox)</h4><p><strong>GeckoDriver</strong> is a link between Selenium tests and the Firefox browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*f48Zo_AV1TOExemcMmMxBw.png" /></figure><p>For Mozilla Firefox till version 47, we never needed GeckoDriver. But Mozilla Firefox after version 47, comes with Marionette, which is an automation driver for Mozilla.</p><p><a href="https://github.com/mozilla/geckodriver/releases">Releases · mozilla/geckodriver</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*GwrEWUWZDzgL_ZXzpuShSg.png" /></figure><p>a. Locate the Geko driver exe inside the project as below.</p><p>b. test → java → right-click → New → Package</p><p>c. Package name -GekoDriver</p><p>d. Download Gekodriver for your computer.</p><p>e. Restore the .exe file in the GekoDriver package</p><p>f. Install the driver by .exe file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*YiOOD2zz4dg3F0yEDj6dgQ.png" /></figure><p>If you want to download Chrome Driver instead of Geko driver go to the Selenium dev site.</p><p>a. Select the Chrome driver</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZLvYpRaja68amCsRc1KRHA.png" /></figure><p>b. Then you will be able to see the latest versions and the stable version details of the driver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8VHMKAeMFO1GsTtnLa_-lA.png" /></figure><p>c. Once you select one, click on a suitable zip file for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*P0_4EXb0WKwLJnnlUbSRQg.png" /></figure><p>d. Then you can see the exe in the download directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/108/1*c9qOq9cTKhnWCrjfo44U0g.png" /></figure><p>e. If you want to check the version just double-click on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*BuRTM_tChShu4xnHPIizbw.png" /></figure><p>f. Locate this as same as we have done in the Geko driver.</p><h4><strong>7. Create a New java class file for test</strong></h4><p>a. Go to your project → right click on java → New → Java Class</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*YkHpDANXLBHT1bj9yRnYFQ.png" /></figure><p>b. Give a suitable name → select on “Class” → Press Enter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*C34PddMw4oV6bep3sJx6kQ.png" /></figure><p>c. Your empty class will appear like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*8u_qA7C7UInEmwpTK0Wmrg.png" /></figure><p>First codes to automate the browser to navigate to google.com</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*D4nVvZEGOYLiRq6Po3_ZfQ.png" /></figure><h3><strong>Important things in your project you should know</strong></h3><h3>pom.xml</h3><p><strong>pom</strong>. <strong>xml</strong> is an XML file located in the root directory of your project. The <strong>pom.xml file </strong>contains</p><ul><li>information about the project</li><li>packages we used in the project</li><li>various configuration detail used by Maven to build the project</li></ul><p>Before creating a <strong>POM</strong>, we should first decide the project group (groupId), its name (artifactId), and its version as these attributes help in uniquely identifying the project in the repository.</p><p>Sample code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/126d6a0b7d3c13a28a408b36fd1d4812/href">https://medium.com/media/126d6a0b7d3c13a28a408b36fd1d4812/href</a></iframe><p>After modifying the pom.xml press the refresh icon to download all the dependencies files from the central repository to the local repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*NlR26Nx6mSWR6QbapNudDQ.png" /></figure><p>After all, files are downloaded from the central repository to the local repository it will appear as done with a tick mark.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*DSKYNxRCxiMFuZSiJK1d1g.png" /></figure><p>After doing it save the pom.xml and run the cleaner to clean the cash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*iIhcyX4NzBOd5TGJ5zKuYg.png" /></figure><p>To copy the codes you need for dependencies can be found in the below link.</p><p><a href="https://mvnrepository.com/">https://mvnrepository.com</a></p><p>Search for the artifact you need</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VEPALtQRBap471gxJciF4g.png" /></figure><p>Then select one from with the highest usages</p><p>ex:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*6NEBHzAF1jpMOFtsU3ZF5A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jZC-3z-6qYPUfFFhu2Vg3A.png" /></figure><p>Simply copy the dependency and modify the pom.xml file.</p><p>Do not forget to update the version in the properties section.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9cad4d3d0028bd38a4f239b0273a0319/href">https://medium.com/media/9cad4d3d0028bd38a4f239b0273a0319/href</a></iframe><p>I’m using the Mozilla Firefox browser for this testing. So here I have to download the Geko driver to perform the tests.</p><h3><strong>*TestRunner.java</strong></h3><p>A JUnit <strong>Runner</strong> is a <strong>class</strong> that extends JUnit’s abstract <strong>Runner class</strong>. <strong>Runners</strong> are used for running <strong>test classes</strong>.</p><p>Junit Runner class is highly customizable and lets you change the whole test execution process. The <strong>Runner</strong> that should be used to run a <strong>test</strong> can be set using the @RunWith annotation.</p><ol><li>test → java → right-click → New → Package</li></ol><p>2. Package name- Runner</p><p>3. Right-click on the Runner package → New → java class</p><p>4. New class name — TestRunner</p><p><strong>Example code for Test Runner class</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33a9ab96a74f3af5279a1bf9a57429d6/href">https://medium.com/media/33a9ab96a74f3af5279a1bf9a57429d6/href</a></iframe><p><strong><em>Things in runner class</em></strong></p><ol><li><a href="http://twitter.com/RunWith"><em>@RunWith</em></a><em>(Cucumber.class) </em>— JUnit annotation</li></ol><p><em>2. features={“src/test/java/features” </em>— Path to feature folder where cucumber test scenarios exist</p><p><em>3. plugin = {“pretty”, “html:target/cucumber.html”,”json:target/cucumber.json” </em>— Reporting</p><p><em>4. glue = {“src/test/java/steps/MyLogin”} </em>— Path to Step definition class of scenario</p><h3><strong>*Creating Feature file — (Cucumber)</strong></h3><p>a. Features → Right-click → New → File</p><p>b. Name — &lt;name.feature&gt;</p><p>Then the system will automatically take it as a cucumber file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/1*OCGeDJevwS6acIJQsHbnaw.png" /></figure><p>In the cucumber file you have to write your test scenario as below by using the keywords Scenario, Given, When, And, Then.</p><p>Until you create the java class for the step definition the scenario will highlight as below picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*CajcGZmb-mOUHeWI_PQHPQ.png" /></figure><h3><strong>Create Step definition java class</strong></h3><p>Press Alt + Ctrl+B and then the list of suggested intention actions opens.</p><p>Select create all step definitions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*0q24e_BOj3126vj11qG3uQ.png" /></figure><p>You have to give the java file name and select the type of the file as Java.</p><p>Then the file location will automatically display as per created file structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*4eRyVoPttRg1X5QgEDT6NA.png" /></figure><p>According to the above-given scenario below java class will create.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99578c22476c44d8cd21e9f65edfb571/href">https://medium.com/media/99578c22476c44d8cd21e9f65edfb571/href</a></iframe><p><strong>selenium java cheat sheet</strong></p><p><a href="https://medium.com/@madhankumaravelu93/selenium-cheat-sheet-a-comprehensive-list-of-selenium-commands-fa4c5c9d11ab">https://medium.com/@madhankumaravelu93/selenium-cheat-sheet-a-comprehensive-list-of-selenium-commands-fa4c5c9d11ab</a></p><ul><li><a href="https://intellipaat.com/blog/tutorial/selenium-tutorial/selenium-cheat-sheet/">Selenium Cheat Sheet - Download in PDF &amp; JPG Format - Intellipaat</a></li><li><a href="https://devhints.io/xpath">Xpath cheatsheet</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65330345f492" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>