<?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 Hansani Maleesha on Medium]]></title>
        <description><![CDATA[Stories by Hansani Maleesha on Medium]]></description>
        <link>https://medium.com/@maleesha0003?source=rss-c329cac78660------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nYOulqshl9dRU7v1SoQhQA.jpeg</url>
            <title>Stories by Hansani Maleesha on Medium</title>
            <link>https://medium.com/@maleesha0003?source=rss-c329cac78660------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:06:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maleesha0003/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[ What is Machine Learning? A Beginner’s Guide to AI’s Most Practical Subfield.]]></title>
            <link>https://medium.com/@maleesha0003/what-is-machine-learning-a-beginners-guide-74bfc07f2b8a?source=rss-c329cac78660------2</link>
            <guid isPermaLink="false">https://medium.com/p/74bfc07f2b8a</guid>
            <dc:creator><![CDATA[Hansani Maleesha]]></dc:creator>
            <pubDate>Sat, 14 Jun 2025 17:11:54 GMT</pubDate>
            <atom:updated>2025-06-14T17:18:24.455Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1aHgbG_xqJNtZrj8n2rKJw.png" /></figure><h3>👋 Hey Developers,</h3><p>Ever wondered how Netflix knows what movie you’ll love next, or how your email filters out spam without fail? These smart features are made possible by <strong>Machine Learning (ML)</strong></p><p>In this article, let’s get a quick and clear start on Machine Learning:</p><ul><li>What it is</li><li>How it’s different from AI and Deep Learning</li><li>The main types of Machine Learning</li></ul><h3><strong>🤖 What is Machine Learning?</strong></h3><p><strong>Machine Learning (ML)</strong> is a field of computer science that enables systems to <strong>learn from data</strong>, <strong>identify patterns</strong>, and <strong>make decisions</strong> with minimal human intervention.</p><p>Instead of explicitly programming every rule, we train machines with data so they can learn and improve over time.</p><p><em>“The field of study that gives computers the ability to learn without being explicitly programmed.” — </em>Arthur Samuel</p><h3>🤔How Machine Learning Differs from AI and Deep Learning</h3><p>Understanding the difference between <strong>Artificial Intelligence (AI)</strong>, <strong>Machine Learning (ML)</strong>, and <strong>Deep Learning (DL)</strong> is essential for anyone starting in the field of data science or AI development.</p><h4>🌐 Artificial Intelligence (AI)</h4><p>AI is the <strong>broadest concept</strong>, focused on building machines that can simulate human intelligence. This includes decision-making, problem-solving, understanding language, and perception.</p><p><strong>Examples : </strong>Chat-bots, expert systems, robotics</p><h4>📊 Machine Learning (ML)</h4><p>ML is a <strong>subset of AI</strong> that enables machines to <strong>learn from data</strong>. Instead of being explicitly programmed, ML models are trained on data to make predictions or decisions.</p><p><strong>Examples : E</strong>mail spam filters, recommendation engines</p><h4>🧠 Deep Learning (DL)</h4><p>DL is a <strong>subset of ML</strong> that uses <strong>neural networks with many layers</strong> (deep architectures) to process data. It is particularly powerful for tasks involving large-scale unstructured data like images, audio, or natural language.</p><p><strong>Examples : </strong>Image recognition, voice assistants</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jax-ap60TC1zyL0D7fck6g.png" /></figure><h3>🧩Types of Machine Learning</h3><p>Machine Learning comes in <strong>three main types</strong>, each suited for different problems.</p><h4>1. Supervised Learning</h4><p>The model is trained on a <strong>labeled dataset</strong> (data with correct answers).</p><p>🎯 <strong>Goal:</strong> Predict outcomes based on input features.</p><p>📌<strong>Examples:</strong></p><ul><li>Spam detection (emails labeled as spam or not)</li><li>House price prediction (based on size, location, etc.)</li></ul><p><strong>🛠 Common Algorithms:</strong></p><ul><li>Linear Regression</li><li>Logistic Regression</li><li>Decision Trees</li><li>Support Vector Machines (SVM)</li></ul><h4>2. 🔍 Unsupervised Learning</h4><p>The model is trained on <strong>unlabeled data</strong> and must find patterns or groupings on its own.</p><p><strong>🎯 Goal: </strong>Discover hidden structures in data.</p><p><strong>📌 Examples:</strong></p><ul><li>Customer segmentation</li><li>Market basket analysis (items frequently bought together)</li></ul><p><strong>🛠 Common Algorithms:</strong></p><ul><li>K-Means Clustering</li><li>Hierarchical Clustering</li><li>Principal Component Analysis (PCA)</li></ul><h4>3. 🕹 Reinforcement Learning</h4><p>An <strong>agent</strong> learns by interacting with an environment and receiving <strong>rewards or penalties</strong>.</p><p><strong>🎯 Goal: </strong>Learn the best strategy to <strong>maximize reward</strong> over time.</p><p><strong>📌 Examples:</strong></p><ul><li>Game playing (e.g., AlphaGo, Chess engines)</li><li>Self-driving cars</li></ul><p><strong>🛠 Core Concepts:</strong></p><ul><li>Q-Learning</li><li>Deep Q-Networks (DQN)</li><li>Markov Decision Processes (MDP)</li></ul><h3>💡 Why is Machine Learning Important?</h3><ul><li><strong>Automation</strong>: Replaces repetitive, rule-based tasks</li><li><strong>Data Utilization</strong>: Unlocks insights from large data sets</li><li><strong>Real-Time Decisions</strong>: Helps in dynamic environments (e.g., traffic, finance)</li><li><strong>Innovation</strong>: Fuels cutting-edge tech (e.g., ChatGPT, self-driving cars)</li></ul><h3>🔚 Final Thoughts</h3><p>Machine Learning is at the core of modern intelligent systems. It allows computers to learn from data and improve over time, without being hard-coded for every task.</p><p><em>ML is not just for researchers - it’s for developers, analysts, business leaders, and anyone curious about the future.</em></p><p>👀 <strong>Coming Up Next</strong>:</p><p>In the next article, I’ll show you how to <strong>set up your machine learning environment</strong> using Python and popular libraries like Pandas, NumPy, and Scikit-learn.</p><p>Stay tuned - and start thinking about problems in your life that <strong>data</strong> might be able to solve!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74bfc07f2b8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design Smarter, Not Harder: A Beginner’s Guide to Visily and Its AI-Powered Features]]></title>
            <link>https://medium.com/@maleesha0003/design-smarter-not-harder-a-beginners-guide-to-visily-and-its-ai-powered-features-c5a56aea746b?source=rss-c329cac78660------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5a56aea746b</guid>
            <dc:creator><![CDATA[Hansani Maleesha]]></dc:creator>
            <pubDate>Thu, 17 Apr 2025 03:58:49 GMT</pubDate>
            <atom:updated>2025-04-17T04:07:33.151Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LKnVKP4Zs3kSb0E1LJIqLg.jpeg" /></figure><h3>👋 Hey Developers,</h3><p>Are you still spending countless hours manually creating wireframes and UI designs for your applications? Struggling to translate your app ideas into functional layouts?</p><p>It’s time to <strong>upgrade your workflow with AI-powered design assistance</strong>.</p><p><strong>Visily</strong> lets you transform simple text prompts or sketches into interactive, editable UI designs — <strong>saving time, improving efficiency, and boosting productivity</strong>.</p><h3>💡 What is Visily?</h3><p><strong>Visily</strong> is a next-generation UI/UX design tool built for developers, product teams, and non-designers who want to create clean, functional wireframes and prototypes — <strong>without deep design expertise</strong>.</p><p>With its powerful <strong>AI-driven features</strong>, Visily automates much of the design process so you can focus on what matters: <strong>building great software</strong>.</p><p>Whether you’re:</p><ul><li>A <strong>startup founder</strong> brainstorming ideas</li><li>A <strong>product manager</strong> planning features</li><li>A <strong>developer</strong> creating front ends</li></ul><p>Visily makes UI design fast, accessible, and intelligent.</p><h3>🤖 Visily AI: Design Smarter, Not Harder</h3><p>Let’s explore the AI features that make Visily stand out:</p><h4>1. ✍️ Text-to-UI Generation</h4><p>Visily can transform plain text descriptions into editable, ready-to-use screens.</p><p><em>💬 </em>Example: “I need a mobile app with a sign-in screen, a product list, and a shopping cart page.”</p><p><em>✅ Visily instantly generates this structure using intelligent, pre-designed components.</em></p><h4>2. 🖼️ Image-to-UI Conversion</h4><p>Have a sketch or screenshot of an app?</p><ol><li>Upload the image to Visily</li><li>The AI detects UI elements and reconstructs the layout</li><li>You get an <strong>editable wireframe</strong> to refine and build upon</li></ol><p>Perfect for converting hand-drawn mockups or redesigning existing apps.</p><h4>3. 🧠 Smart Suggestions</h4><p>Visily provides intelligent, real-time design guidance:</p><ul><li>Auto-aligns elements</li><li>Recommends missing components</li><li>Optimizes common patterns (e.g., login forms, modals, checkout flows)</li></ul><p>These features help you avoid common design pitfalls and keep your UI clean and usable.Who Should Use Visily?</p><h3>👥 Who Should Use Visily?</h3><p>Visily is perfect for:</p><ul><li><strong>Developers</strong>: Quickly create UI mockups without relying on designers</li><li><strong>Product Managers</strong>: Visualize features and user flows easily</li><li><strong>Startups &amp; Founders</strong>: Pitch polished product ideas with zero design overhead</li><li><strong>Agile Teams</strong>: Collaborate, iterate, and refine features faster</li></ul><p>With <strong>templates</strong>, <strong>UI libraries</strong>, and <strong>collaboration tools</strong>, Visily fits perfectly into modern product development workflows.</p><h3>🛠️ How to Get Started</h3><p>Getting started with Visily is easy:</p><ol><li>Visit <a href="https://www.visily.ai/">visily.ai</a></li><li>Create a new project (from scratch, template, or AI prompt)</li><li>Use the drag-and-drop editor to build or modify your layout</li><li>Invite your team to collaborate, comment, or co-design</li><li>Export your wireframes or share a prototype link</li></ol><h3>⚡ Quick Demo: Build a Task Manager UI with AI</h3><p>Need a basic Task Manager app UI?</p><ol><li>Click “Start with AI”</li><li>Enter the prompt:</li></ol><p>“A web app with a task list, add new task input, and checkboxes to mark tasks complete.”</p><ol><li>Let Visily do the rest — your UI is generated in seconds!</li><li>Now customize fonts, colors, layout, or component behavior — no need to start from scratch.</li></ol><h3>🔚 Final Thoughts</h3><p>In today’s fast-paced development environment, <strong>speed and flexibility</strong> are key. Visily’s <strong>AI-powered design tools</strong> empower you to go from idea to interactive UI faster than ever.</p><p><em>Why spend hours designing manually when Visily can do the heavy lifting </em>Start building smarter — <strong>with Visily.</strong></p><p>👀 <strong>Coming Up Next</strong>:<br> Stay tuned for my next article where I’ll dive into <strong>Visily’s Premium Features</strong> — unlocking even more powerful tools for advanced prototyping, team collaboration, and productivity.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5a56aea746b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Harnessing the Power of the`useEffect` Hook in Custom React Hooks for Data Fetching]]></title>
            <link>https://medium.com/@maleesha0003/harnessing-the-power-of-the-useeffect-hook-in-custom-react-hooks-for-data-fetching-24c0275ffe1c?source=rss-c329cac78660------2</link>
            <guid isPermaLink="false">https://medium.com/p/24c0275ffe1c</guid>
            <dc:creator><![CDATA[Hansani Maleesha]]></dc:creator>
            <pubDate>Tue, 03 Sep 2024 17:08:02 GMT</pubDate>
            <atom:updated>2024-09-03T17:08:02.058Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fvwoOyqZtPtSXveUslCJAw.jpeg" /></figure><p>React is a popular JavaScript library for building user interfaces, known for its ability to create reusable components that enhance code quality and development speed. One of the core features that makes React so powerful is its ability to handle side effects using the `useEffect`hook. In this article, we’ll explore how `useEffect`works, why it&#39;s essential for side effect management, and how to leverage it to create custom hooks for data fetching in React applications.</p><h4><strong>Understanding `</strong><strong>useEffect`: The Key to Managing Side Effects</strong></h4><p>The `useEffect`hook is fundamental to handling side effects in React&#39;s functional components. Side effects are operations that interact with the outside world or change states that affect the UI, such as data fetching, subscriptions, or directly manipulating the DOM. `useEffect`helps developers manage these side effects efficiently by providing a structured way to run a piece of code at specific points in a component&#39;s lifecycle.</p><p><strong><em>Basic Syntax of `</em></strong><strong><em>useEffect`</em></strong></p><pre>import { useEffect } from &#39;react&#39;;<br><br>useEffect(() =&gt; {<br>  // Code to run on mount and updates<br>  return () =&gt; {<br>    // Cleanup code (optional)<br>  };<br>}, [dependencies]);</pre><ul><li><strong>Effect Callback</strong>: The first argument of `useEffect`is a function containing the side effect code. This function runs after the component renders or when certain dependencies change.</li><li><strong>Cleanup Function</strong>: The function returned from the effect callback acts as a cleanup function, running when the component unmounts or before the effect is re-executed. This is crucial for cleaning up subscriptions, timers, or other resources to avoid memory leaks.</li><li><strong>Dependencies Array</strong>: The second argument is an array of dependencies. The effect runs only when the values in this array change. If omitted, the effect will run after every render.</li></ul><h4><strong>Creating a Custom Hook for Data Fetching Using `</strong><strong>useEffect`</strong></h4><p>Custom hooks in React are a way to reuse stateful logic without changing your component hierarchy. By combining `useState`and `useEffect`, you can encapsulate data fetching logic in a custom hook. Let&#39;s create a simple custom hook named useFetch that uses `useEffect `to fetch data from an API and manage loading and error states.</p><p><strong><em>Basic Implementation</em></strong></p><pre>import { useState, useEffect } from &#39;react&#39;;<br><br>function useFetch(url) {<br>  const [data, setData] = useState(null);<br>  const [loading, setLoading] = useState(true);<br>  const [error, setError] = useState(null);<br><br>  useEffect(() =&gt; {<br>    const fetchData = async () =&gt; {<br>      try {<br>        setLoading(true);<br>        const response = await fetch(url);<br>        if (!response.ok) {<br>          throw new Error(&#39;Network response was not ok&#39;);<br>        }<br>        const result = await response.json();<br>        setData(result);<br>      } catch (error) {<br>        setError(error.message);<br>      } finally {<br>        setLoading(false);<br>      }<br>    };<br><br>    fetchData();<br>  }, [url]); // Re-run effect if `url` changes<br><br>  return { data, loading, error };<br>}</pre><p><strong><em>Usage Example</em></strong></p><pre>import React from &#39;react&#39;;<br>import useFetch from &#39;./useFetch&#39;; // Adjust the path as necessary<br><br>function DataFetchingComponent() {<br>  const { data, loading, error } = useFetch(&#39;https://api.example.com/data&#39;);<br><br>  if (loading) return &lt;p&gt;Loading...&lt;/p&gt;;<br>  if (error) return &lt;p&gt;Error: {error}&lt;/p&gt;;<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Data:&lt;/h1&gt;<br>      &lt;pre&gt;{JSON.stringify(data, null, 2)}&lt;/pre&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default DataFetchingComponent;</pre><h4>Enhancing the Custom Hook with Additional Options</h4><p>You can extend the `useFetch` hook to accept additional options, such as custom headers or HTTP methods, by passing a configuration object.</p><pre>import { useState, useEffect } from &#39;react&#39;;<br><br>function useFetch(url, options = {}) {<br>  const [data, setData] = useState(null);<br>  const [loading, setLoading] = useState(true);<br>  const [error, setError] = useState(null);<br><br>  useEffect(() =&gt; {<br>    const fetchData = async () =&gt; {<br>      try {<br>        setLoading(true);<br>        const response = await fetch(url, options);<br>        if (!response.ok) {<br>          throw new Error(&#39;Network response was not ok&#39;);<br>        }<br>        const result = await response.json();<br>        setData(result);<br>      } catch (error) {<br>        setError(error.message);<br>      } finally {<br>        setLoading(false);<br>      }<br>    };<br><br>    fetchData();<br>  }, [url, options]); // Re-run effect if `url` or `options` change<br><br>  return { data, loading, error };<br>}<br></pre><p><strong><em>Usage with Options</em></strong></p><pre>import React from &#39;react&#39;;<br>import useFetch from &#39;./useFetch&#39;; // Adjust the path as necessary<br><br>function DataFetchingComponent() {<br>  const { data, loading, error } = useFetch(&#39;https://api.example.com/data&#39;, {<br>    method: &#39;GET&#39;,<br>    headers: {<br>      &#39;Content-Type&#39;: &#39;application/json&#39;,<br>      &#39;Authorization&#39;: &#39;Bearer your-token&#39;<br>    }<br>  });<br><br>  if (loading) return &lt;p&gt;Loading...&lt;/p&gt;;<br>  if (error) return &lt;p&gt;Error: {error}&lt;/p&gt;;<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Data:&lt;/h1&gt;<br>      &lt;pre&gt;{JSON.stringify(data, null, 2)}&lt;/pre&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default DataFetchingComponent;</pre><h4>Best Practices for Custom Hooks Using `useEffect`</h4><ul><li><strong>Code Reusability</strong>: Custom hooks should encapsulate logic that can be reused across different components, helping to avoid code duplication.</li><li><strong>Separation of Concerns</strong>: Keep the business logic separate from the UI logic, making components cleaner and easier to understand.</li><li><strong>Testing</strong>: Use libraries like @testing-library/react-hooks to test custom hooks in isolation, ensuring their reliability.</li></ul><p><strong><em>Testing a Custom Hook</em></strong></p><pre>import { renderHook } from &#39;@testing-library/react-hooks&#39;;<br>import useFetch from &#39;./useFetch&#39;; // Adjust the path as necessary<br><br>test(&#39;should fetch data&#39;, async () =&gt; {<br>  const { result, waitForNextUpdate } = renderHook(() =&gt; useFetch(&#39;https://api.example.com/data&#39;));<br><br>  expect(result.current.loading).toBe(true);<br><br>  await waitForNextUpdate();<br><br>  expect(result.current.data).toBeDefined();<br>  expect(result.current.loading).toBe(false);<br>});</pre><h4>Conclusion</h4><p>The `useEffect `hook is a powerful tool in React for managing side effects, and when used in custom hooks, it enables clean and maintainable code. By creating a custom hook for data fetching, you can simplify your component code and make it easier to manage asynchronous operations. Remember to follow best practices, including testing and documenting your hooks, to make them robust and user-friendly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24c0275ffe1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Control Flow: Conditionals in Java]]></title>
            <link>https://medium.com/@maleesha0003/control-flow-conditionals-in-java-57228d7ec115?source=rss-c329cac78660------2</link>
            <guid isPermaLink="false">https://medium.com/p/57228d7ec115</guid>
            <dc:creator><![CDATA[Hansani Maleesha]]></dc:creator>
            <pubDate>Sun, 14 Jul 2024 19:07:36 GMT</pubDate>
            <atom:updated>2024-07-14T19:07:36.254Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qzc_BZ9rW7gUxTYFtamyDw.jpeg" /></figure><p>Welcome back to our journey through Java programming! In our previous articles, we’ve laid the groundwork with <a href="https://medium.com/@maleesha0003/basic-concepts-data-types-variables-and-operators-4920d6ef2422"><strong>Basic Concepts: Data Types, Variables, and Operators in Java</strong>.</a> Now, it’s time to delve deeper into the heart of programming logic: control flow.</p><h3>If-else statements</h3><p>If-else statements are fundamental to controlling the flow of a program. They allow your code to make decisions based on certain conditions. Here’s how they work in Java:</p><p><strong>Syntax of If-else Statements:</strong></p><pre>if (condition) {<br>// code to be executed if the condition is true<br>} else {<br>// code to be executed if the condition is false<br>}</pre><p><strong>Example : Checking if a Number is Positive or Negative.</strong></p><pre>public class Main {<br>  public static void main(String[] args) {<br>    int number = 10;<br>    if (number &gt; 0) {<br>      System.out.println(&quot;The number is positive.&quot;);<br>    } else {<br>      System.out.println(&quot;The number is negative.&quot;);<br>    }<br>  }<br>}</pre><p>In this example, if the condition `number &gt; 0` is true, the program prints &quot;The number is positive.&quot; Otherwise, it prints &quot;The number is not positive.&quot;</p><h3>Nested If-Else</h3><p>Sometimes, you need to check multiple conditions. This is where nested if-else statements come in handy.</p><p><strong>Example: Checking if a Number is Positive, Negative, or Zero.</strong></p><pre>int number = -12;<br><br>if (number &gt; 0) {<br>  System.out.println(&quot;The number is positive.&quot;);<br>} else {<br>  if (number == 0) {<br>    System.out.println(&quot;The number is zero.&quot;);<br>  } else {<br>    System.out.println(&quot;The number is negative.&quot;);<br>  }<br>}</pre><p>In this example, the program first checks if the number is greater than 0. If it’s not, it then checks if the number is equal to 0. If neither condition is true, it concludes that the number is negative.</p><h3>If-Else Ladder</h3><p>When you have multiple conditions to check, using an if-else ladder can make your code cleaner and more readable.</p><p><strong>Example of If-Else Ladder</strong></p><pre>int score = 85;<br><br>if (score &gt;= 90) {<br>  System.out.println(&quot;Grade: A&quot;);<br>} else if (score &gt;= 80) {<br>  System.out.println(&quot;Grade: B&quot;);<br>} else if (score &gt;= 70) {<br>  System.out.println(&quot;Grade: C&quot;);<br>} else if (score &gt;= 60) {<br>  System.out.println(&quot;Grade: D&quot;);<br>} else {<br>  System.out.println(&quot;Grade: F&quot;);<br>}</pre><p>In this example, the program checks the score against multiple conditions to determine the grade. It first checks if the score is 90 or above, then 80 or above, and so on.</p><h3>Examples and Exercises</h3><p>Exercise 1: Basic If-Else</p><p>Write a program that takes an integer input from the user and prints whether the number is even or odd.</p><pre>import java.util.Scanner;<br><br>public class EvenOdd {<br>  public static void main(String[] args) {<br>    Scanner scanner = new Scanner(System.in);<br>    System.out.print(&quot;Enter a number: &quot;);<br>    int number = scanner.nextInt();<br><br>    //write your logic here<br>  }<br>}</pre><p>Solution :</p><pre>import java.util.Scanner;<br><br>public class EvenOdd {<br>  public static void main(String[] args) {<br>    Scanner scanner = new Scanner(System.in);<br>    System.out.print(&quot;Enter a number: &quot;);<br>    int number = scanner.nextInt();<br><br>    if (number % 2 == 0) {<br>      System.out.println(&quot;The number is even.&quot;);<br>    } else {<br>      System.out.println(&quot;The number is odd.&quot;);<br>    }<br>  }<br>}</pre><p>Exercise 2: Nested If-Else</p><p>Modify the above program to also check if the number is positive, negative, or zero.</p><pre>import java.util.Scanner;<br><br>public class EvenOddPositiveNegative {<br>  public static void main(String[] args) {<br>    Scanner scanner = new Scanner(System.in);<br>    System.out.print(&quot;Enter a number: &quot;);<br>    int number = scanner.nextInt();<br><br>    //write your logic here<br>  }<br>}</pre><p>Solution:</p><pre>import java.util.Scanner;<br><br>public class EvenOddPositiveNegative {<br>  public static void main(String[] args) {<br>    Scanner scanner = new Scanner(System.in);<br>    System.out.print(&quot;Enter a number: &quot;);<br>    int number = scanner.nextInt();<br><br>    if (number &gt; 0) {<br>      if (number % 2 == 0) {<br>        System.out.println(&quot;The number is positive and even.&quot;);<br>      } else {<br>        System.out.println(&quot;The number is positive and odd.&quot;);<br>      }<br>    } else if (number &lt; 0) {<br>      if (number % 2 == 0) {<br>        System.out.println(&quot;The number is negative and even.&quot;);<br>      } else {<br>        System.out.println(&quot;The number is negative and odd.&quot;);<br>      }<br>    } else {<br>      System.out.println(&quot;The number is zero.&quot;);<br>    }<br>  }<br>}</pre><p>Exercise 3: If-Else Ladder</p><p>Write a program that takes a percentage score as input and prints the corresponding grade.</p><pre>import java.util.Scanner;<br><br>public class GradeCalculator {<br>  public static void main(String[] args) {<br>    Scanner scanner = new Scanner(System.in);<br>    System.out.print(&quot;Enter your score: &quot;);<br>    int score = scanner.nextInt();<br><br>   //write your logic here<br>  }<br>}</pre><p>Solution:</p><pre>import java.util.Scanner;<br><br>public class GradeCalculator {<br>  public static void main(String[] args) {<br>    Scanner scanner = new Scanner(System.in);<br>    System.out.print(&quot;Enter your score: &quot;);<br>    int score = scanner.nextInt();<br><br>    if (score &gt;= 90) {<br>      System.out.println(&quot;Grade: A&quot;);<br>    } else if (score &gt;= 80) {<br>      System.out.println(&quot;Grade: B&quot;);<br>    } else if (score &gt;= 70) {<br>      System.out.println(&quot;Grade: C&quot;);<br>    } else if (score &gt;= 60) {<br>      System.out.println(&quot;Grade: D&quot;);<br>    } else {<br>      System.out.println(&quot;Grade: F&quot;);<br>    }<br>  }<br>}<br></pre><p>Understanding if-else statements is crucial for any Java programmer. These control flow constructs enable your programs to make decisions based on different conditions, enhancing their flexibility and functionality. By practicing the examples and exercises provided, you’ll gain confidence in using if-else statements, nested if-else, and if-else ladders.</p><p>In our next article, we will continue exploring control flow by diving into loops, including for loops, while loops, and more advanced concepts like break and continue statements. Stay tuned and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57228d7ec115" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basic Concepts: Data Types, Variables, and Operators in Java]]></title>
            <link>https://medium.com/@maleesha0003/basic-concepts-data-types-variables-and-operators-4920d6ef2422?source=rss-c329cac78660------2</link>
            <guid isPermaLink="false">https://medium.com/p/4920d6ef2422</guid>
            <dc:creator><![CDATA[Hansani Maleesha]]></dc:creator>
            <pubDate>Wed, 10 Jul 2024 15:50:09 GMT</pubDate>
            <atom:updated>2024-07-10T16:44:35.299Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ekccszoZ2tWs_5Z6CwB4rg.jpeg" /></figure><p>Welcome back! After successfully writing your first Java program in “<a href="https://medium.com/@maleesha0003/introduction-to-programming-with-java-a-beginners-guide-7f8dda361e15">Introduction to Programming with Java: A Beginner’s Guide</a>,” it’s time to dive deeper. In this article, we’ll explore the fundamental building blocks of Java: data types, variables, and operators. These basics will help you create more dynamic and complex programs. Ready? Let’s jump right in!</p><h3>1. Understanding Data Types</h3><p>Java provides various data types to store different kinds of information. Here are the most commonly used ones:</p><h4>Integers</h4><p>They are used to store whole numbers without a decimal point.</p><p><strong>Examples and Ranges:</strong></p><ul><li>byte: 8-bit signed integer, <strong>range: -128 to 127</strong></li></ul><pre>byte smallNumber = 100;</pre><ul><li>short: 16-bit signed integer, <strong>range: -32,768 to 32,767</strong></li></ul><pre>short mediumNumber = 30000;</pre><ul><li>int: 32-bit signed integer, <strong>range: -2³¹ to 2³¹-1</strong></li></ul><pre>int age = 25;</pre><ul><li>long: 64-bit signed integer, <strong>range: -2⁶³ to 2⁶³-1</strong></li></ul><pre>long largeNumber = 123456789L;</pre><h4><strong>Floats</strong></h4><p>Used to store numbers with a fractional part (decimal point).</p><p><strong>Examples and Ranges:</strong></p><ul><li>float: 32-bit IEEE 754 floating point, <strong>range: approximately ±3.4e-38 to ±3.4e+38</strong></li></ul><pre>float price = 19.99f;</pre><ul><li>double: 64-bit IEEE 754 floating point,<strong> range: approximately ±1.7e-308 to ±1.7e+308</strong></li></ul><pre>double distance = 12345.678;</pre><h4><strong>Strings</strong></h4><p>Used to store sequences of characters.</p><pre>String name = &quot;Hansani&quot;;</pre><h4><strong>Booleans</strong></h4><p>Used to store true or false values.</p><pre>boolean isJavaFun = true;</pre><h3><strong>2. Declaring and Using Variables:</strong></h3><p>Variables are used to store data that can be referenced and manipulated in a program. Here’s how to declare and use them:</p><h4><strong>1. Declaration and Initialization:</strong></h4><ul><li><strong>Syntax:</strong> “dataType variableName = value; ”</li></ul><pre>int number = 10;<br>String greeting = &quot;Hello, Java!&quot;;</pre><h4><strong>2. Updating Variables:</strong></h4><pre>number = 20; // updating the value of &#39;number&#39;</pre><h4><strong>3. Variable Scope:</strong></h4><p>Variable scope refers to the region of a program where a variable can be accessed. It defines the visibility and accessibility of variables within different parts of your code.</p><p><strong>Types of Variables Based on Scope:</strong></p><p>1. <strong>Local Variables:</strong></p><ul><li>Local variables are declared within a method, constructor, or any block of code (such as loops or conditional statements).</li><li><strong>Scope:</strong> Local variables are accessible only within the block of code in which they are declared.</li></ul><pre>public class Main {<br>  public static void main(String[] args) {<br>    int localVariable = 10;  // Local variable<br>    System.out.println(localVariable);<br>  }<br>}</pre><ul><li>In this example, ‘localVariable’ is a local variable of the ‘main’ method. It can only be accessed within the {} block of the ‘main’ method where it is declared.</li></ul><p>2. <strong>Instance Variables (Global to Object):</strong></p><ul><li>Instance variables are declared within a class but outside any method, constructor, or block. Each instance of the class (object) has its own copy of instance variables.</li><li><strong>Scope:</strong> Instance variables are accessible to all methods, constructors, and blocks of the class in which they are declared.</li></ul><pre>public class Example {<br>  int instanceVar = 20;  // Instance variable<br><br>  public void method() {<br>    System.out.println(instanceVar);  // Accessing instanceVar<br>  }<br>}</pre><ul><li>‘instanceVar’ is an instance variable of the ‘Example’ class. It can be accessed within any method (method() in this case) of the ‘Example’ class.</li></ul><p>3. <strong>Class Variables (Static Variables — Global to Class):</strong></p><ul><li>Class variables are declared with the ‘static’ keyword within a class but outside any method, constructor, or block. They belong to the entire class rather than any specific instance.</li><li><strong>Scope:</strong> Class variables are accessible to all instances of the class and can also be accessed through the class name itself.</li></ul><pre>public class Example {<br>  static int classVar = 30;  // Class variable (static)<br><br>  public static void main(String[] args) {<br>    System.out.println(classVar);  // Accessing classVar<br>  }<br>}</pre><ul><li>‘classVar’ is a class variable (static variable) of the ‘Example’ class. It can be accessed directly within static methods (such as ‘main’ in this case) and through instances of the Example class.</li></ul><p>Understanding variable scope is essential for managing and controlling data within your Java programs. Different types of variables (local, instance, and class variables) have distinct scopes that determine where they can be accessed and how long they exist. By grasping these concepts, programmers can ensure effective data management and maintainability in their Java applications.</p><h3><strong>3. Arithmetic, Comparison, Logical, and Bitwise Operators</strong></h3><p>Operators are used to perform operations on variables and values. Here are the main types:</p><h4><strong>1. Arithmetic Operators</strong></h4><p>Arithmetic operators perform mathematical operations on numeric operands. They are used to perform basic calculations such as addition, subtraction, multiplication, division, and modulo operations.</p><p>· <strong>Operators:</strong> Symbols that represent specific operations.</p><p>Examples : ‘+, -, *, /, and %’.</p><p>· <strong>Operands:</strong> The values or variables on which the operators act.</p><p>For example, in the expression ’10 + 5’, ‘10’ and ‘5’ are operands, and ‘+’ is the operator.</p><p><strong>Examples and Usage:</strong></p><p>1. <strong>Addition (+):</strong> Adds two operands.</p><pre>int sum = 10 + 5; // sum is 15</pre><p>2. <strong>Subtraction (-):</strong> Subtracts the second operand from the first.</p><pre>int difference = 10–5; // difference is 5</pre><p>3. <strong>Multiplication (*):</strong> Multiplies two operands.</p><pre>int product = 10 * 5; // product is 50</pre><p>4. <strong>Division (/):</strong> Divides the first operand by the second. Note that integer division discards the remainder.</p><pre>int quotient = 10 / 5; // quotient is 2</pre><p>5. <strong>Modulo (%):</strong> Returns the remainder when the first operand is divided by the second.</p><pre>int remainder = 10 % 3; // remainder is 1</pre><p><strong>Compound Assignment Operators:</strong></p><p>Java provides compound assignment operators that combine arithmetic operations with assignments, making the code more concise. These shortcuts are particularly useful for updating the value of a variable based on its current value.</p><p>1. <strong>Addition Assignment (+=):</strong> Adds the right operand to the left operand and assigns the result to the left operand.</p><pre>int sum = 10;<br>sum += 5; // Equivalent to sum = sum + 5; sum is now 15</pre><p>2. <strong>Subtraction Assignment (-=):</strong> Subtracts the right operand from the left operand and assigns the result to the left operand.</p><pre>int difference = 10;<br>difference -= 5; // Equivalent to difference = difference - 5; difference is now 5</pre><p>3. <strong>Multiplication Assignment (*=):</strong> Multiplies the left operand by the right operand and assigns the result to the left operand.</p><pre>int product = 10;<br>product *= 5; // Equivalent to product = product * 5; product is now 50</pre><p>4. <strong>Division Assignment (/=):</strong> Divides the left operand by the right operand and assigns the result to the left operand.</p><pre>int quotient = 10;<br>quotient /= 5; // Equivalent to quotient = quotient / 5; quotient is now 2</pre><p>5. <strong>Modulo Assignment (%=):</strong> Applies the modulo operation to the left operand with the right operand and assigns the result to the left operand.</p><pre>int remainder = 10;<br>remainder %= 3; // Equivalent to remainder = remainder % 3; remainder is now 1</pre><h4><strong>2. Comparison Operators</strong></h4><p>Comparison operators compare two values and return a boolean result (true or false). These operators are used to evaluate conditions and make decisions in control flow statements like ‘if’, ‘for’, and ‘while’ loops.</p><p><strong>Examples and Usage:</strong></p><p><strong>1.Equal to (==): </strong>Checks if two values are equal.</p><pre>boolean isEqual = (10 == 5); // false</pre><p><strong>2. Not equal to (!=):</strong> Checks if two values are not equal.</p><pre>boolean isNotEqual = (10 != 5); // true</pre><p><strong>3. Greater than (&gt;):</strong> Checks if the left operand is greater than the right operand.</p><pre>boolean isGreater = (10 &gt; 5); // true</pre><p><strong>4. Less than (&lt;):</strong> Check if the left operand is less than the right operand.</p><pre>boolean isLess = (10 &lt; 5); // false</pre><p><strong>5. Greater than or equal to (&gt;=):</strong> Check if the left operand is greater than or equal to the right operand.</p><pre>boolean isGreaterOrEqual = (10 &gt;= 5); // true</pre><p><strong>5. Less than or equal to (&lt;=):</strong> Check if the left operand is less than or equal to the right operand.</p><pre>boolean isLessOrEqual = (10 &lt;= 5); // false</pre><p><strong>Usage Example:</strong></p><pre>public class ComparisonExample {<br>  public static void main(String[] args) {<br>    int a = 10;<br>    int b = 5;<br>    boolean isEqual = (a == b); // false<br>    boolean isNotEqual = (a != b); // true<br>    boolean isGreater = (a &gt; b); // true<br>    boolean isLess = (a &lt; b); // false<br>    boolean isGreaterOrEqual = (a &gt;= b); // true<br>    boolean isLessOrEqual = (a &lt;= b); // false<br>    System.out.println(&quot;isEqual: &quot; + isEqual);<br>    System.out.println(&quot;isNotEqual: &quot; + isNotEqual);<br>    System.out.println(&quot;isGreater: &quot; + isGreater);<br>    System.out.println(&quot;isLess: &quot; + isLess);<br>    System.out.println(&quot;isGreaterOrEqual: &quot; + isGreaterOrEqual);<br>    System.out.println(&quot;isLessOrEqual: &quot; + isLessOrEqual);<br>  }<br>}</pre><h4><strong>3. Logical Operators</strong></h4><p>Logical operators are used to combine multiple boolean expressions or values, resulting in a boolean value (true or false). They are particularly useful in control flow statements, such as if statements, to create more complex conditional logic.</p><p><strong>Examples and Usage:</strong></p><p><strong>1.Logical AND (</strong><strong>&amp;&amp;): </strong>The &amp;&amp; operator returns true if both operands are true; otherwise, it returns false.</p><pre>boolean result1 = (10 &gt; 5) &amp;&amp; (5 &lt; 10);   // true &amp;&amp; true -&gt; true <br>boolean result2 = (10 &gt; 5) &amp;&amp; (5 &gt; 10);   // true &amp;&amp; false -&gt; false</pre><p><strong>2. Logical OR (</strong><strong>||):</strong> The || operator returns true if at least one of the operands is true; if both operands are false, it returns false.</p><pre>boolean result1 = (10 &gt; 5) || (5 &gt; 10);   // true || false -&gt; true <br>boolean result2 = (10 &lt; 5) || (5 &gt; 10);   // false || false -&gt; false</pre><p><strong>3.Logical NOT (</strong><strong>!):</strong> The ! operator inverts the value of a boolean expression. If the expression is true, it returns false, and if it is false, it returns true.</p><pre>boolean result1 = !(10 &gt; 5);   // !(true) -&gt; false <br>boolean result2 = !(5 &gt; 10);   // !(false) -&gt; true</pre><p><strong>Examples and Detailed Usage:</strong></p><ol><li><strong>Logical AND (</strong><strong>&amp;&amp;):</strong></li></ol><pre>public class LogicalAndExample {     <br>  public static void main(String[] args) {         <br>    boolean condition1 = (10 &gt; 5); // true         <br>    boolean condition2 = (5 &lt; 10); // true          <br>    boolean result = condition1 &amp;&amp; condition2; // true &amp;&amp; true -&gt; true         <br>    System.out.println(&quot;Result of Logical AND: &quot; + result); // Output: true          <br>    boolean condition3 = (5 &gt; 10); // false         <br>    result = condition1 &amp;&amp; condition3; // true &amp;&amp; false -&gt; false         <br>    System.out.println(&quot;Result of Logical AND with one false condition: &quot; + result); // Output: false     <br>  } <br>}</pre><p><strong>2. Logical OR (</strong><strong>||):</strong></p><pre>public class LogicalOrExample {     <br>  public static void main(String[] args) {         <br>    boolean condition1 = (10 &gt; 5); // true         <br>    boolean condition2 = (5 &gt; 10); // false          <br>    boolean result = condition1 || condition2; // true || false -&gt; true         <br>    System.out.println(&quot;Result of Logical OR: &quot; + result); // Output: true          <br>    boolean condition3 = (10 &lt; 5); // false         <br>    result = condition2 || condition3; // false || false -&gt; false         <br>    System.out.println(&quot;Result of Logical OR with both false conditions: &quot; + result); // Output: false     <br>  } <br>}</pre><p><strong>3. Logical NOT (</strong><strong>!):</strong></p><pre>public class LogicalNotExample {     <br>  public static void main(String[] args) {         <br>    boolean condition = (10 &gt; 5); // true          <br>    boolean result = !condition; // !true -&gt; false         <br>    System.out.println(&quot;Result of Logical NOT: &quot; + result); // Output: false          <br>    condition = (5 &gt; 10); // false         <br>    result = !condition; // !false -&gt; true         <br>    System.out.println(&quot;Result of Logical NOT with false condition: &quot; + result); // Output: true     <br>  } <br>}</pre><p><strong>Compound Logical Expressions:</strong></p><p>Logical operators can be combined to form compound logical expressions, which are evaluated based on the order of operations. Parentheses can be used to group expressions and control the evaluation order.</p><pre>public class CompoundLogicalExample {<br>    public static void main(String[] args) {<br>        boolean condition1 = (10 &gt; 5); // true<br>        boolean condition2 = (5 &lt; 10); // true<br>        boolean condition3 = (5 == 5); // true<br>        boolean condition4 = (10 &lt; 5); // false<br>        boolean result = condition1 &amp;&amp; condition2 || condition4; // (true &amp;&amp; true) || false -&gt; true || false -&gt; true<br>        System.out.println(&quot;Result of Compound Logical Expression: &quot; + result); // Output: true<br>        result = (condition1 &amp;&amp; condition2) || (condition3 &amp;&amp; condition4); // (true &amp;&amp; true) || (true &amp;&amp; false) -&gt; true || false -&gt; true<br>        System.out.println(&quot;Result of Another Compound Logical Expression: &quot; + result); // Output: true<br>        result = !(condition1 &amp;&amp; condition4); // !(true &amp;&amp; false) -&gt; !(false) -&gt; true<br>        System.out.println(&quot;Result of Logical NOT with Compound Expression: &quot; + result); // Output: true<br>    }<br>}</pre><h4>4. Bitwise Operators</h4><p>Bitwise operators perform operations on the individual bits of integer operands. These operators are particularly useful for low-level programming, such as working with hardware, performing binary arithmetic, and implementing performance-critical code.</p><p><strong>Examples and Usage:</strong></p><p><strong>1.Bitwise AND (</strong><strong>&amp;):</strong>Performs a binary AND operation on each pair of corresponding bits of the operands. The result is 1 if both bits are 1, otherwise, it is 0.</p><pre>int a = 5;  // Binary: 101 <br>int b = 3;  // Binary: 011 <br>int result = a &amp; b;  // 101 &amp; 011 = 001 -&gt; 1 <br>System.out.println(&quot;Bitwise AND: &quot; + result);  // Output: 1</pre><p><strong>2.Bitwise OR (</strong><strong>|):</strong> Performs a binary OR operation on each pair of corresponding bits of the operands. The result is 1 if at least one of the bits is 1, otherwise, it is 0.</p><pre>int a = 5;  // Binary: 101 <br>int b = 3;  // Binary: 011 <br>int result = a | b;  // 101 | 011 = 111 -&gt; 7 <br>System.out.println(&quot;Bitwise OR: &quot; + result);  // Output: 7</pre><p><strong>3.Bitwise XOR (</strong><strong>^):</strong> Performs a binary XOR (exclusive OR) operation on each pair of corresponding bits of the operands. The result is 1 if one of the bits is 1 and the other is 0, otherwise, it is 0.</p><pre>int a = 5;  // Binary: 101 <br>int b = 3;  // Binary: 011 <br>int result = a ^ b;  // 101 ^ 011 = 110 -&gt; 6 <br>System.out.println(&quot;Bitwise XOR: &quot; + result);  // Output: 6</pre><p><strong>4.Bitwise Complement (</strong><strong>~):</strong> Inverts each bit of the operand. The result is the one’s complement of the operand.</p><pre>int a = 5;  // Binary: 101 <br>int result = ~a;  // ~101 = 11111111111111111111111111111010 -&gt; -6 <br>System.out.println(&quot;Bitwise Complement: &quot; + result);  // Output: -6</pre><p><strong>5.Left Shift (</strong><strong>&lt;&lt;):</strong> Shifts the bits of the operand to the left by the specified number of positions. Each left shift operation multiplies the number by 2.</p><pre>int a = 5;  // Binary: 101 <br>int result = a &lt;&lt; 1;  // 101 &lt;&lt; 1 = 1010 -&gt; 10 <br>System.out.println(&quot;Left Shift: &quot; + result);  // Output: 10</pre><p><strong>6.Right Shift (</strong><strong>&gt;&gt;):</strong> Shifts the bits of the operand to the right by the specified number of positions. Each right shift operation divides the number by 2.</p><pre>int a = 5;  // Binary: 101 <br>int result = a &gt;&gt; 1;  // 101 &gt;&gt; 1 = 10 -&gt; 2 <br>System.out.println(&quot;Right Shift: &quot; + result);  // Output: 2</pre><p><strong>7.Unsigned Right Shift (</strong><strong>&gt;&gt;&gt;):</strong> Shifts the bits of the operand to the right by the specified number of positions, filling the leftmost bits with zeros. This operator is used for unsigned binary numbers.</p><pre>int a = -5;  // Binary: 11111111111111111111111111111011 <br>int result = a &gt;&gt;&gt; 1;  // 11111111111111111111111111111011 &gt;&gt;&gt; 1 = 01111111111111111111111111111101 -&gt; 2147483645 <br>System.out.println(&quot;Unsigned Right Shift: &quot; + result);  // Output: 2147483645</pre><p>Bitwise operators are powerful tools for manipulating data at the bit level, providing fine-grained control over binary operations. Understanding and using these operators effectively can lead to optimized and efficient code, especially in performance-critical applications.</p><pre>public class BitwiseOperatorsExample {<br>    public static void main(String[] args) {<br>        int a = 5;  // Binary: 101<br>        int b = 3;  // Binary: 011<br>        int bitwiseAnd = a &amp; b;   // 101 &amp; 011 = 001 -&gt; 1<br>        int bitwiseOr = a | b;    // 101 | 011 = 111 -&gt; 7<br>        int bitwiseXor = a ^ b;   // 101 ^ 011 = 110 -&gt; 6<br>        int bitwiseComplement = ~a; // ~101 = 11111111111111111111111111111010 -&gt; -6<br>        int leftShift = a &lt;&lt; 1;   // 101 &lt;&lt; 1 = 1010 -&gt; 10<br>        int rightShift = a &gt;&gt; 1;  // 101 &gt;&gt; 1 = 10 -&gt; 2<br>        int unsignedRightShift = -5 &gt;&gt;&gt; 1; // 11111111111111111111111111111011 &gt;&gt;&gt; 1 = 01111111111111111111111111111101 -&gt; 2147483645<br>        System.out.println(&quot;Bitwise AND: &quot; + bitwiseAnd);<br>        System.out.println(&quot;Bitwise OR: &quot; + bitwiseOr);<br>        System.out.println(&quot;Bitwise XOR: &quot; + bitwiseXor);<br>        System.out.println(&quot;Bitwise Complement: &quot; + bitwiseComplement);<br>        System.out.println(&quot;Left Shift: &quot; + leftShift);<br>        System.out.println(&quot;Right Shift: &quot; + rightShift);<br>        System.out.println(&quot;Unsigned Right Shift: &quot; + unsignedRightShift);<br>    }<br>}</pre><h3>4.Examples and Exercises</h3><ol><li><strong>Example: Basic Arithmetic Operations</strong></li></ol><p>This example demonstrates the use of arithmetic operators to perform basic mathematical operations.</p><pre>public class ArithmeticExample {<br>  public static void main(String[] args) {<br>    int a = 10;<br>    int b = 5;<br>    System.out.println(&quot;Sum: &quot; + (a + b));           // Output: Sum: 15<br>    System.out.println(&quot;Difference: &quot; + (a - b));    // Output: Difference: 5<br>    System.out.println(&quot;Product: &quot; + (a * b));       // Output: Product: 50<br>    System.out.println(&quot;Quotient: &quot; + (a / b));      // Output: Quotient: 2<br>  }<br>}</pre><p><strong>2. Exercise: Variable Manipulation</strong></p><p>Practice declaring and updating variables.</p><ul><li>Declare a variable to store your favorite number.</li><li>Update the variable with a new value.</li><li>Print the updated value to the console.</li></ul><p>Example solution:</p><pre>public class VariableManipulation {<br>  public static void main(String[] args) {<br>    int favoriteNumber = 7;  // Declare and initialize the variable<br>    System.out.println(&quot;Favorite Number: &quot; + favoriteNumber);  // Output: Favorite Number: 7<br>    favoriteNumber = 42;  // Update the variable<br>    System.out.println(&quot;Updated Favorite Number: &quot; + favoriteNumber);  // Output: Updated Favorite Number: 42<br>  }<br>}</pre><p><strong>3. Exercise: Logical Comparison</strong></p><p>Work with comparison and logical operators to evaluate conditions.</p><ul><li>Declare two integer variables.</li><li>Use comparison operators to compare them and print the results.</li><li>Use logical operators to combine multiple conditions and print the results.</li></ul><p>Example solution:</p><pre>public class LogicalComparison {<br>  public static void main(String[] args) {<br>    int num1 = 10;<br>    int num2 = 5;<br>    // Comparison operators<br>    System.out.println(&quot;Is num1 equal to num2? &quot; + (num1 == num2));  // Output: false<br>    System.out.println(&quot;Is num1 not equal to num2? &quot; + (num1 != num2));  // Output: true<br>    System.out.println(&quot;Is num1 greater than num2? &quot; + (num1 &gt; num2));  // Output: true<br>    System.out.println(&quot;Is num1 less than num2? &quot; + (num1 &lt; num2));  // Output: false<br>    // Logical operators<br>    boolean condition1 = (num1 &gt; num2);  // true<br>    boolean condition2 = (num2 &lt; 10);    // true<br>    System.out.println(&quot;Condition1 AND Condition2: &quot; + (condition1 &amp;&amp; condition2));  // Output: true<br>    System.out.println(&quot;Condition1 OR Condition2: &quot; + (condition1 || condition2));   // Output: true<br>    System.out.println(&quot;NOT Condition1: &quot; + (!condition1));  // Output: false<br>  }<br>}<br></pre><p><strong>4. Exercise: Bitwise Operators</strong></p><p>Practice using bitwise operators.</p><ul><li>Declare two integer variables.</li><li>Use bitwise operators to perform AND, OR, XOR, and NOT operations and print the results.</li></ul><p><strong>Example Solution:</strong></p><pre>public class BitwiseOperators {<br>  public static void main(String[] args) {<br>    int num1 = 6;  // 0110 in binary<br>    int num2 = 3;  // 0011 in binary<br>    // Bitwise AND<br>    System.out.println(&quot;Bitwise AND: &quot; + (num1 &amp; num2));  // Output: 2 (0010 in binary)<br>    // Bitwise OR<br>    System.out.println(&quot;Bitwise OR: &quot; + (num1 | num2));   // Output: 7 (0111 in binary)<br>    // Bitwise XOR<br>    System.out.println(&quot;Bitwise XOR: &quot; + (num1 ^ num2));  // Output: 5 (0101 in binary)<br>    // Bitwise NOT<br>    System.out.println(&quot;Bitwise NOT (num1): &quot; + (~num1)); // Output: -7 (in binary: 1111...1001)<br>  }<br>}</pre><p>Understanding data types, variables, and operators is essential for any Java programmer. These basics allow you to store and manipulate data effectively. Practice these concepts with the examples and exercises provided, and you’ll be well on your way to mastering Java.</p><p>In the next article, we will explore control flow statements to add logic to your programs. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4920d6ef2422" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Programming with Java: A Beginner’s Guide]]></title>
            <link>https://medium.com/@maleesha0003/introduction-to-programming-with-java-a-beginners-guide-7f8dda361e15?source=rss-c329cac78660------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f8dda361e15</guid>
            <dc:creator><![CDATA[Hansani Maleesha]]></dc:creator>
            <pubDate>Mon, 08 Jul 2024 21:04:11 GMT</pubDate>
            <atom:updated>2024-07-09T07:58:21.468Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFco3QV0vgm740BB1AUIhA.jpeg" /></figure><p>In today’s technology-driven world, programming has become an essential skill. Whether you’re interested in developing mobile applications, creating websites, or analyzing data, learning to code can open up a multitude of opportunities.</p><p>In this article, we will take you through a step-by-step journey into the world of programming. We will start by understanding what programming is, then move on to an overview of different programming languages, set up a Java development environment, and finally, write and run your first program in Java. By the end of this guide, you’ll have a solid foundation to start your programming journey with Java.</p><p><strong>What is Programming?</strong></p><p>Programming is the process of creating a set of instructions that a computer can follow to perform specific tasks. These instructions, known as code, are written in programming languages. Programming allows us to create software, control hardware, and automate tasks, making it a cornerstone of modern technology.</p><p><strong>Overview of Different Programming Languages</strong></p><p>There are hundreds of programming languages, each with its strengths and weaknesses. Here are some popular ones:</p><ul><li><strong>Java:</strong> Known for its platform independence and extensive libraries, making it ideal for cross-platform applications.</li><li><strong>Python:</strong> A highly readable and versatile language, perfect for beginners and used in web development, data science, and AI.</li><li><strong>C++:</strong> Offers fine control over system resources, widely used in game development and systems programming.</li><li><strong>JavaScript:</strong> The backbone of web development, enabling dynamic and interactive web pages.</li></ul><p>Among all of these languages, why did we choose Java? Java is a robust, object-oriented language that can run on any platform with the Java Virtual Machine (JVM). It’s widely used in enterprise environments, Android app development, and large-scale systems.</p><p><strong>Setting Up Your Java Development Environment</strong></p><p>Before writing code, it’s essential to set up your Java development environment. In the first step, you must install the Java Development Kit (JDK) and an Integrated Development Environment (IDE). Here is a small guide to get started:</p><p><strong>1. Installing the Java Development Kit (JDK):</strong></p><ul><li>Visit the <a href="https://www.oracle.com/java/technologies/javase-jdk11-downloads.html">Oracle JDK download page</a>.</li><li>Download the appropriate installer for your operating system.</li><li>Follow the installation instructions provided by Oracle.</li></ul><p><strong>2. Setting Up an Integrated Development Environment (IDE):</strong></p><ul><li><strong>IntelliJ IDEA:</strong> Download from <a href="https://www.jetbrains.com/idea/download/"><em>JetBrains</em></a><em>.</em></li><li><strong>Eclipse:</strong> Download from <a href="https://www.eclipse.org/downloads/"><em>Eclipse.</em></a></li><li><strong>NetBeans:</strong> Download from <a href="https://netbeans.apache.org/download/index.html"><em>Apache NetBeans</em></a><em>.</em></li></ul><p>After downloading your IDE, follow the setup instructions to get it configured on your machine.</p><p><strong>3. Configuring Your Environment:</strong></p><ul><li>Set the JAVA_HOME environment variable to point to your JDK installation directory.</li><li>Add the JDK bin directory to your system PATH.</li><li>Verify the installation by opening a command prompt or terminal and running java -version and javac -version.</li></ul><p><strong>Writing Your First Java Program: “Hello, World!”</strong></p><p>Congratulations! You set up your computer for writing code with Java. Let’s start writing our first project.</p><p><strong>1. Open Your IDE and Create a New Project:</strong></p><ul><li>In IntelliJ IDEA, go to File &gt; New &gt; Project.</li><li>Select Java and click Next.</li><li>Name your project and click Finish.</li></ul><p><strong>2. Write the Program:</strong> Create a new Java class named HelloWorld and enter the following code:</p><p>java</p><pre>public class HelloWorld {<br>  public static void main(String[] args) {<br>    System.out.println(&quot;Hello, World!&quot;);<br>  }<br>}</pre><p><strong>3. Run the Program:</strong></p><ul><li>In IntelliJ IDEA, right-click on the HelloWorld.java file and select Run</li><li>You should see the output Hello, World! in the console.</li></ul><p><strong>4. Understanding the Code:</strong></p><ul><li>public class HelloWorld: This declares a public class named HelloWorld. In Java, every application must have at least one class definition that contains the main method.</li><li>public static void main(String[] args): This is the main method, the entry point of any Java application. The Java runtime calls this method to start the program.</li><li>System.out.println(“Hello, World!”): This line prints the string “Hello, World!” to the console.</li></ul><p>Congratulations! You’ve just written and executed your first Java program. This simple exercise introduces you to the basic structure of a Java program and how to set up your development environment. Java’s syntax and structure form the foundation for more complex applications, and by mastering these basics, you are well on your way to becoming a proficient Java programmer. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f8dda361e15" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>