Assalamualaikum my fellows I hope you will be fine by the grace of Allah. Today I am going to participate in the steemit learning challenge season 22 week 1 by @kouba01 under the umbrella of steemit team. It is about Getting Started with Java and Eclipse. Let us start exploring this week's teaching course.
The architecture of Java is made up of three main components: JDK (Java Development Kit), JRE (Java Runtime Environment) and JVM (Java Virtual Machine). Each serves a different purpose, yet they are interdependent, and they work together in order to develop and run Java applications.
The JDK is the tool used by developers to write, compile, and debug Java programs. It acts as a comprehensive development environment that contains everything necessary for developing Java applications. Key components of the JDK include a compiler for converting Java source code into bytecode, tools for debugging and profiling, and additional utilities for packaging applications. Importantly, the JDK also includes the JRE, which enables developers to test and execute their applications. Without the JDK, creating and building Java applications would not be possible.
The JRE is designed to provide an environment in which Java applications can run. It includes the JVM, core libraries, and native code that interfaces with the underlying operating system. The JRE guarantees that all dependencies like Java class libraries and APIs are available for the proper functioning of applications. Although it enables the execution of Java applications, it does not include tools like the compiler, which are needed for development. This makes the JRE suitable for end-users who simply need to run Java applications but are not involved in their creation.
The JVM is the center of Java's "write once, run anywhere" promise. It is a virtual machine responsible for executing the Java bytecode, which is the platform-independent code generated by the JDK's compiler.
The JVM consists of several key components: the class loader, which loads classes into memory; the bytecode verifier, which checks for compliance with Java's security and language rules; and the execution engine, which translates bytecode into machine-specific instructions using either an interpreter or a Just-In-Time (JIT) compiler. The JVM offers an abstraction layer between the Java program and the hardware, so that the same bytecode can run on any system that is equipped with a compatible JVM.
These components work together seamlessly to enable both the development and execution of Java applications. The JVM executes Java bytecode, while the JRE provides the libraries and environment needed for the JVM to operate. The JDK, in turn, includes the JRE and adds tools for developers, making it the most comprehensive package.
JVM is the runtime executor, JRE is the execution-support environment, and JDK is the toolkit for writing and running Java programs. It ensures flexibility and efficiency by providing a modular structure for the adoption of Java programs on any platform.
This is the graphical illustration of the JDK, JRE, and JVM where the JDK is the parent and it is holding other components as child in it to complete the development environment.
Let us start setting up the java development environment.
JDK Download
The main page looks like as shown above in the picture.
JDK Installation
As I am a window user now I have to configure the environment variables for the JDK because if I do not set its environment variables I cannot access it in the CMD. So it is necessary task.
Eclipse Download
First Program
This is the simple addition program to add the first 100 integers. The entire calculation is handled in the main method.
A sum
variable to store the sum of the numbers.
A loop to find out the sum of the first 100 integers.
sum = sum + i
is storing the and updating sum value with each iteration of the loop.
Second Program
A separate function calculateSum
to perform all the calculations is written in this program with the same working as in the previous program. I have just put it in the separate function.
Then I have called this function in the main method and it is returning the same output as in the previous program.
Tax.java
I have created a method to calculate the tax with the name calculateTax
and I have passed income
as a parameter to this method.
I have defined the tax
variable as double
because it can be a floating value. So for the precision it is in the double type.
Then there are conditional statements according to the given conditions in the question. Each condition is validating and checking the specific limit of the income and implementing tax to that specific amount of limit.
In the main method I have passed income = 57000;
to calculate tax for this amount of income.
After giving this amount of income the program has calculated the correct amount of tax as expected which is 5550.
Here is the java program which can convert the characters from the lowercase to uppercase and similarly uppercase to lowercase and it also checks if the given character is a letter or not.
I have created a class Conversion
and there is a convert Character
function in which there are the rules to convert the uppercase letter to the lowercase and similarly for the lowercase to uppercase.
Character.isLowerCase(c)
checks if a given character is a lowercase or not.
Character.isUpperCase(c)
checks if a given character is a uppercase or not.
If the given chracter is neither an uppercase nor a lowercase then it returns not a letter.
If we check the output of the program we can observe that it has converted lowercase d to uppercase D and uppercase Q to lowercase q. And when there is a number then it has printed the message it is not a letter.
Here is a complete java program which will perform all the required operations as asked in the question such as finding the largest number of the array, sum of all the numbers of the array and the sorted array.
I have created a class ArrayOperations
. In the class there are four functions to find out the largest element, sum and sorted array and the main function to handle the program.
The first function is checking all the numbers in the array and it is returning the largest number.
The second function is traversing the array and it is finding the sum of all the numbers in the array.
The third function is taking the array and it is using the built in method to sort the arrays. It is sorting the array to the ascending order.
This is the output of the program. I have double tested the program by giving the array filled with numbers and one array without numbers to check the behaviour of the program. The largest element in the array is 123 which is correct and the sum of the array is also 364 which this program has returned correctly. At the end if we see the order of the array it is also in the ascending order.
I invite @wilmer1988, @josepha, @wuddi to join this learning challenge.