New to Nutbox?

SLC S22 Week1 || Getting Started with Java and Eclipse

1 comment

mateenfatima
68
15 hours agoSteemit11 min read


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.png

Image taken from source

image.png

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 :
  • JDK: Development tools, includes JRE and compiler.
  • JRE: Execution environment for Java programs.
  • JVM: Virtual Machine responsible for running Java bytecode.

image.png

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:
  • Contain the Java compiler that is used to convert source code into the byte code
  • Includes libraries and development tools for Java application creation.
  • Provides the JRE to run Java applications.
Key Components:
  • Java Compiler

  • Debugging Tools

  • Documentation Generator (javadoc)

  • Java Runtime Environment (JRE)

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:
  • it Includes the JVM to execute bytecode.

  • Also Provide standard libraries and class files.

  • Does not include tools for writing or compiling code.

Key Components:
  • Java Virtual Machine (JVM)

  • Core Libraries

  • Supporting Files


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:
  • It converts Java bytecode into machine code
  • It managed memory through the garbage collection.
  • It ensures platform independence ("Write Once, Run Anywhere").
Key Features:
  • Bytecode Interpreter
  • Just-In-Time (JIT) Compiler for optimization
  • Memory and Thread Management

Illustration:

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

Summarizing...
  • JDK :
    It includes the tools for developing Java applications and Jre for executing them.
  • JRE:
    includes the JVM to execute bytecode and support libraries.
  • JVM:
    It ensures the probability and execution of Java programs on different platforms.

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.

image.png

Task 2

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

image.png

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.

1.png


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.

2.png

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

3.png

  • After Selecting the directory the process of installation started and it takes some minutes to proceed out. this is a screen shot attached you can see below.

4.png


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

Screenshot 2024-12-22 103719.png

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.

Screenshot 2024-12-22 103744.png

Screenshot 2024-12-22 114739.png


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.

Screenshot 2024-12-22 110652.png

Screenshot 2024-12-22 110843.png


Step 5: Download and Install Eclipse IDE

  1. Firstly I go to the Eclipse Downloads page.

image.png
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.

Screenshot 2024-12-22 085858.png

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.

Screenshot 2024-12-22 100133.png

Screenshot 2024-12-22 100406.png

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

10.png

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

Screenshot 2024-12-22 115745.png

Run the program and verify the output in the console.

Screenshot 2024-12-22 115956.png

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.

image.png

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.

image.png

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

Screenshot 2024-12-22 121726.png
About the screenshots of the output are attached.


Program with Calculation in a Separate Function

  • Explanation:
    This version of the program separates the logic for calculating the sum into
    calculateSum() method. The main() method calls this function and prints the result.

Firstly I write the code in Sum2.Java

Output:

The sum of the first 100 integers is: 5050

Screenshot 2024-12-22 121954.png


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

image.png

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));
 }

}

image.png

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
  • The calculateTax Method checks the income against different brackets and applies the appropriate tax rate for each segment of the total tax will be calculated by summing up the tax for each bracket

Screenshot 2024-12-22 123527.png

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.

Screenshot 2024-12-22 124032.png

image.png

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.".

image.png

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.

image.png

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.

image.png

  • Example Workflow
  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

image.png

image.png

image.png

image.png

Task 4

Performing Array Operations

image.png

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.

image.png

image.png

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.

  • Output

image.png

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

image.png

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

Comments

Sort byBest