SLC S22 Week1 || Getting Started with Java and Eclipse

mateenfatima -


Greetings to All


Hy guys, I wish you all will be great by the blessings and mercy of Almighty Allah. So today I am going to participate in the learning Challenge of the Steemit Season 22 Week 1.The first Challenge that I am going to start this week is about the introduction to java that course is designed by @kouba1. So let's start by exploring the home tasks and their answers.

Image taken from source

Task 1

Write a detailed explanation of the differences between JDK, JRE, and JVM by including their roles, functionalities, and interdependence. Add graphic illustrations which cover this points :

Introduction to java

Java is a popular programming language that operates through several essential components like JDK , JRE and JVM it helps us to understand How Java work as a programming platform so today we will dive deeper into these concepts.

1. Java Development Kit (JDK)

JDK is a development toolkit that is used to write compile and debug our Java codes and applications it is considered as the primary tool for Java developers. Its core functionality contains the Java compiler to convert source code into byte code include libraries and development tools for Java application creation and also provide the JRE.

Functionalities:
Key Components:

Illustration:

+-------------------+
|   Java Programs   |
+-------------------+
         |
+-------------------+
|        JDK        |
|-------------------|
| Compiler, JRE,    |
| Libraries         |
+-------------------+

Java runtime environment or in simple jre needed to execute Java applications it is basically designed for the end users who wants to run their Java programs.

2. Java Runtime Environment (JRE)
Functionalities:
Key Components:

Illustration:

+-------------------+
|   Bytecode       |
+-------------------+
         |
+-------------------+
|        JRE        |
|-------------------|
| JVM, Libraries    |
| Supporting Files  |
+-------------------+

The JVM is the Indian diet helps to run the Java byte code it acts as a assembly layer between the byte code and operating system to proceed.

3. Java Virtual Machine (JVM)
Functionalities:
Key Features:

Illustration:

+-------------------+
|   Machine Code    |
+-------------------+
         |
+-------------------+
|        JVM        |
|-------------------|
| Bytecode, Memory, |
| Thread Mgmt       |
+-------------------+

Summarizing...

Comprehensive Diagram:

+---------------------+
|       JDK          |
|---------------------|
| Compiler, Debugger  |
| Javadoc, JRE        |
+---------------------+
         |
+---------------------+
|       JRE          |
|---------------------|
| JVM, Libraries      |
| Supporting Files    |
+---------------------+
         |
+---------------------+
|       JVM          |
|---------------------|
| Bytecode Execution  |
| Garbage Collection  |
+---------------------+

By understanding these components developers will be able to use and define that how Java enables an efficient development and execution across the platform.

Task 2

Install and Set Up Your Java Development Environment and provide step-by-step screenshots of the installation process, Eclipse configuration.

These are the steps that I have followed to install and configure my javas Development environment here we'll see the details by using screenshots and elaborating the process.


Step 1: Download the JDK
  1. Firstly I go to Oracle JDKWebsite.

  2. Secondly I select the appropriate version of JDK for my operating system that was windows installer x64 and download it. The Screenshots you can see below.


Step 2: Install the JDK
  1. I select the run option to downloaded installer and follow the instructions in the wizard to install the JDK.

  1. Make a note of the installation directory (e.g., C:\Program Files\Java\jdk-).


Step 3: Set Environment Variables
  1. Then I open the system settings and navigate to the environment variables.

And add new system variable that was named as Java home and its value was the path to the installation directory then I click on ok to proceed.


Step 4: Verify Java Installation

To verify the installation I opened my command prompt and run the command of java--version and then javac--version to check out the variance installed in my PC.


Step 5: Download and Install Eclipse IDE

  1. Firstly I go to the Eclipse Downloads page.


After that I had selected the right option and the installer was downloaded in the installer I selected the Java developer open and launched to install it on my pc.

Download the Eclipse IDE for Java Developers.

Then I proceed to launch the installer after it was completely installed I set it up.


Step 6: Create and Run a Java Project
  1. Create a new Java project:
    • Go to FileNewJava Project.
    • Enter the project name as testing and click Finish.

Then I add the new class and and the compiler new class was added as shown in screenshots below.

Then write a simple "Hello, World!" program in a new class.

Run the program and verify the output in the console.

By completing these steps I have a fully functional Java development environment that was ready for writing and done in Java programs so lets proceed with the next tasks.

By completing these steps, you will have a fully functional Java development environment ready for writing and running Java programs.

Task 3

Write a program that calculates and displays the sum of the first 100 integers. Define the main method in a class named Sum to handle the entire calculation.
Save this program in a file named Sum.java, compile it, and execute it.Create a new program named Sum2.java, where the calculation of the sum of the first 100 integers is performed in a separate function called calculateSum. This function should then be called from the main method.

In this task we will write two paragraphs to calculate the sum of 100 integers using the Java.

Program with Calculation in the main Method

Explanation:

In this program we will use for loop to calculate the sum of integers from 1 to 100. the result will be stored in the variable sum and after the loop completes it printed it on the console.

Firstly I save the code in Sum.java file and run the code by clicking on the run button

This will show the following output

Output:

The sum of the first 100 integers is: 5050


About the screenshots of the output are attached.


Program with Calculation in a Separate Function

Firstly I write the code in Sum2.Java

Output:

The sum of the first 100 integers is: 5050


So we have calculated the sums by using groups and functions in Java.

Task 4

Translate, Complete, and Debug the Following Program Named Tax.java:

public class Tax {
public static double calculateTax(double income) {
// result = value of the tax calculated based on the income
}

   public static void main(String[] args) {
      System.out.print("Tax: ");
       System.out.println(calculateTax(57000));
 }

}

Here is the complete, translated, and debugged version of the program Tax.java to calculate tax based on the given income brackets:

Explanation of the Tax Calculation:
  1. Bracket T1 (≤ 20,000):

    • Tax: 20000 * 0.05 = 1000
  2. Bracket T2 (20,001 to 40,000):

    • Tax: (40000 – 20000) * 0.10 = 2000
  3. Bracket T3 (40,001 to 60,000):

    • Tax: (57000 – 40000) * 0.15 = 2550
  4. Total Tax:

    • Total tax = 1000 + 2000 + 2550 = 5550

This will output the calculated tax for an income of 57,000 as:

Tax: 5550.0

Output:

Tax: 5550.0

Screenshots you can see below.

Task 5

Using the same program structure as in the previous exercise, write a program named Conversion.java that takes a character c as a parameter and:If the character is lowercase, convert it to uppercase and display the following message:"The uppercase equivalent of c is ..."If the character is uppercase, convert it tolowercase and display the following message:"The lowercase equivalent of c is ..."If the character is not a letter, display the following message:"c is not a letter.".

Now we would talk that how programs works it actually takes string of Chracter as input and processes each character It convert lower case letters to upper case and upper case letters to lowercase and also identify a non letter Chracters.
The program uses a scanner object to capture user input in the form of corrector or also input a string the program can handle multiple characters making it flexible for various scenarios scenarios.

To process each character a loop is used this loop iterates through the string and extract the corrector at a time to proceed.
The program will display the result of each character analysis and convergent immediately and provide the real time feedback for the input string.

  1. Input: User enters a string such as Hello123.
  2. Processing:
    • The program processes each character:
      • H → Convert to lowercase → h
      • e → Convert to uppercase → E
      • l → Convert to uppercase → L
      • l → Convert to uppercase → L
      • o → Convert to uppercase → O
      • 1 → Not a letter
      • 2 → Not a letter
      • 3 → Not a letter

Task 4

Performing Array Operations

So in this question we will explore about array operations here the program I have designed that will ask user to input the array size and elements it displays a menu with options to perform different operations based on the user choice. It will find the display largest element compute the sum of the elements and sort the array and displays it if user select exit the program will terminate.

The code you can see in the screen shot the program Itrates through the array To complete each element identify and sorting secondly it will perform the task of calculating the sum of elements where loop is used to add elements of the array to a running total the final sum will be displayed on the screen.

Finally, it will sort the array using bubble sort algorithm and arrange the array in ascending order user can select what operation he wants to perform.

So here is the completion of my entry. Feel free to tell me if I have any mistake

So that was all from my side about the topic and I hope that you all will like to read the post and support the content

I would like to invite

to participate in the contest

Thanks for Reading
Regards @mateenfatima