SLC S22 Week1 || Getting Started with Java and Eclipse

in dynamicdevs-s22w1 •  yesterday 

Greetings guys, I welcome you to my blog. I'm delighted to join this week SLC by professor @kouba01 which is titled Getting Started with Java and Eclipse. I will be attempting the questions below and providing answers on them to the best of my knowledge based on the lecture delivered and a few research.

Red Modern Programming YouTube Thumbnail.png


Task1: (2points)

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.


The difference between JDK, JRE, and JVM can be seen based on the following headings; role, components purpose and interdependence. I will discuss each of them one after the other on the listed headings so let's get started with the first on the list.

Java Development Kit (JDK)

RoleComponentsPurposeInterdependence
JDK is a development kit for developing Java applications. This means that JDK provide the tools for writing, compiling and debugging Java codeIt contains JRE, Java Compiler(javac) and also development tool such as javadoc librariesJDK is used to develop Java programsJDK contains JRE and the JRE also depend on JVM in other to execute Java program

Java Runtime Environment (JRE)

RoleComponentsPurposeInterdependence
JRE is the runtime environment which allows Java program to be executedit contains JVM for Java bytecode execution, contains libraries classes and other files to aid execution of Java programUse to run already complied Java programJRE uses JVM to execute Java program.

Java Virtual Machine (JVM)

RoleComponentsPurposeInterdependence
JVM interprets Java bytecode and executes it as a machine codeIt contains class loader, bytecode verifier and execution engineJVM is used to run Java programJVM is also a part of the JRE and it main aim is to execute Java program

Add graphic illustrations

25.PNG

Java Program ----> JDK ----> JRE ----> JVM

Based on the above image above, you will notice that the JDK covers the JRE as well as the development tools. The JRE on the other hand covers the JVM as well as libraries needed for execution of program. JVM from the illustrations is the inner component we see from the graphic which serves as an interpreter and execute the Java bytecode.


Task2: (2points)
Install and Set Up Your Java Development Environment and provide step-by-step screenshots of the installation process, Eclipse configuration.


To properly set up my Java development environment I used the format given in the course to install JDK and Eclipse and here is the procedure I followed to achieve that target.

Firstly, I visited the site given by the professor in the course which is Oracle Official Website.

I selected windows and also x64 installer based on my system specifications. See screenshot below.

1.PNG

After download, I clicked to launch it and the below screenshot I clicked on the next option.

2.PNG

It requested for a file location and I clicked on next as seen in the screenshot below.

3.PNG

Now I had to wait for it to completely install as seen in the screenshot below. It is currently installing.

4.PNG

After successful installation it came out with a message that JDK is successful installed. Then I clicked on close. See screenshot below.

5.PNG

For the eclipse, we also had almost same procedure. I followed the link given by the professor which is Eclipse

After download I ran it as an administrator and then the screenshot below is what appeared.

6.PNG

I selected among the list of eclipse that shows up eclipse IDE for Java and DSL developers as seen from the screenshot.

7.PNG

Location where the application will be stored came up as well I didn't make any changes so I clicked on install as seen in the screenshot below.

8.PNG

I accepted the user agreement by clicking the accept now options as you can see in the screenshot below.

9.PNG

After a while it finished installing and the launch option came up and I clicked on it as seen in the screenshot below.

10.PNG


Task3: (1points)
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.

As requested in the first question above, I have created a file named Sum.java as you can see from the screenshot below. Now in the program written, we calculated and display the sum of the first 100 integers using the for loop.

The syntax use in this calculation as seen from the screenshot of the code reads

for (int i = 1; i <= 100; i++)

Now this initialised i=1 and i <= 100 and i++ means and increase. After running the code we got the value of the first 100 integers as 5050.

11.PNG

12.PNG

Also as requested, I have created another program named Sum2.java and the calculation of the first 100 integers was done on a separate function which is called the calculateSum.

Here what happened was that the function calculateSum takes an integer parameter 100 and uses it to calculate the the first 100 integers as it was done in the previous example.

See screenshot of the code and output below for more clarification.

13.PNG

14.PNG


Task4: (1point)
Translate, Complete, and Debug the Following Program Named Tax.java:


From the code given in the task you will notice that it is incomplete hence we need to complete it. Firstly I created a program named Tax.java as requested by the task. Seeing the code for each income bracket, you will notice that it has a different rate all assigned to it. This means that to have a total tax, then we will have to add T1, T2 and T3 together.

Just as given in the task,

T1: 20000 * 0.05 = 1000
T2: (40000 – 20000) * 0.10 = 2000
T3: (57000 – 40000) * 0.15 = 2550
Total Tax: T1 + T2 + T3 = 5550
Total Tax: 1000 + 2000 + 2550 = 5550

15.PNG

16.PNG


Task5: (2points)
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 to lowercase 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."


Here we use the function convertCharacter and we have character C as an input. So in this function we use the if else statement to check and convert character to lower case and uppercase and also to check for a non letter.

So what the program does is that is the character is lower case, it converts it to uppercase and if it is upper case it converts it to lower case. The source code and the output are seen below.

17.PNG

18.PNG


Task6: (2points)
Using a similar structure as in the previous exercises, write a program named ArrayOperations.java that performs operations on an integer array. The program should:

Take an array of integers as input.

Provide the following options for operations:

Find the Largest Element: Identify and display the largest element in the array.
Example Message:
"The largest element in the array is ..."
Calculate the Sum of All Elements: Compute and display the sum of all integers in the array.
Example Message:
"The sum of all elements in the array is ..."
Sort the Array in Ascending Order: Sort the elements and display the sorted array.
Example Message:
"The sorted array is: [ ... ]"
If the array is empty, display the following message:
"The array is empty. No operations can be performed."


Here in this part we have an array function and the program created is titled ArrayOperations. One of the main method used here is findLargestElement which returns the largest element in the array. Another method used is calculateSum which calculate the sum of the elements in the array. Lastly sortArray which is used to sort the array in a particular order. See screenshot of the code and output below.

19.PNG

20.PNG

21.PNG

22.PNG

Lastly I made the array empty and then test run the code again as you can see from the screenshot below. I discovered that the results came out as The array is empty. No operations can be performed for the different functions or method listed above. This means it checked the findLargestElement, calculateSum and the sortArray method.

23.PNG

24.PNG

Finally, I wish to invite a few of my friends such as @suboohi, @dove11 and @josepha to also share their participation in this contest.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Very good friend, you have presented well and clearly, starting from explaining the meaning of JDK, JRE and JVM, to practicing it well and perfectly. Good luck my friend.

Loading...