Java Elementary Programming Instructions - Engl393

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Java Elementary Programming Manual

Loc Trieu

Department of Information Systems

University of Maryland, Baltimore county

Christopher Justice

ENGL393 Section: 03

13 April 2024
Table of Contents

1. Introduction______________________________________________3

1.1 Materials needed…………………………………………………….3

1.2 Software Download…………………………………………………4

2. Basic Vocabulary__________________________________________4

2.1 How to Build a Simple Program…………………...………………..4

2.2 Identifiers and Naming Conventions..………………………………5

3. If-Else Statements_________________________________________6

3.1 Relational Operators and If-Else Statements………………………..6

4. Looping Structures________________________________________7

4.1 While Loops…………………………………………………………7

4.2 For Loops……………………………………………………………8

5. Conclusion Statement______________________________________8

6. Glossary_________________________________________________9

2
1.0 Introduction

Java object oriented programming is a powerful tool in developing software. To


summarize the definition of software, software is the instruction set created by programmers that
tell a computer what to do. Software is all around us, even in devices that people might not think
would need it. Of course, one could expect to see software used in a computer, but software can
also be used in places like airplanes, cars, cellphones and even refrigerators. The concept of the
Internet of Things (IoT) explains how common appliances and technology are gradually being
given IP addresses, and being integrated into the internet. As technology advances, and IoT
grows, more software is required to integrate such appliances into the interconnected world of
technology. Because of this, there is an increased need for people to develop software
programming skills, so that we can keep up with the revolution. With Java object oriented
programming, they provide tools necessary to develop all the software required to complement
the growth in technology.
For this guide we will be going over the elementary functions and controls of the Java
programming language. First we will be going over naming conventions, identifiers, named
constants and naming conventions. This portion of the Java programming language is used
mainly to name variables and declare them as specific types. With this we can create an object of
a certain idea and manipulate this ‘object’ how we want. In this section we will also go over why
it is important to follow a standard for how your code should look. Though the code will run the
same, the readability and the naming convention is a key part of what makes a programmer a
good programmer.
Next we will be discussing if-else statements. These functions are another useful tool in
the Java programming language that allows the programmer to set parameters for which
selections of code to run, based on certain data given. This is essential in the programming
language because oftentimes there are times when the user wants a code to be run if given a
specific data, but for another set of data, using the same code wouldn't make sense or provide the
results needed.
The next logical progression would be to learn looping structures. With looping structures
the programmer can repeat a block of code as many times as they want. So if a programmer
needed to execute a code one hundred times, instead of typing the same block of code one
hundred times, they can have one block of code loop one hundred times. This improves the
readability of the code, as it would require less lines of code to run, and as previously mentioned,
readability of code is important in developing software.
Though there is more to learn when it comes to Java programming, by learning and
reviewing this guide, a programmer would be able to learn the basic programming vocabulary.
With this knowledge, the programmer will have all basic building blocks to be able to write any
code, and develop any software.

1.1 Materials Needed

- Laptop/Desktop or PC
- Working Internet Connection

3
1.2 Software Download - IntelliJ

1.) Click the link to go to JetBrains.com


https://www.jetbrains.com/idea/download/?section=mac

Figure 1.2.1.(a) Image of the Download button Figure 1.2.1(b) Image of the download options

2.) Click the .dmg tab and select “Intel” if the computer runs on windows, and click “Apple
Silicon”.
3.) Proceed to Download.
4.) Go to Downloads and click on the “ideaIC-2023.3.3.dmg” folder to run the software.
5.) Once you have the Software open, click “new project” to start coding.

2.0 Basic Vocabulary

2.1 How to Build a Basic Program


Every Java Program must have a main method. This is where the main functions of the code are
written, and performed.
1.) Start by typing the following within the “public class” brackets in your code,

Note that the rest of the code in this guide will be written within the main method
brackets.
2.) Next, we are going to write a simple program.

4
3.) Run the program and the following should show up in the terminal.

Figure 2.1.1 Terminal with the printed statement.

4.) That is all there is to it. In the following sections we will be building onto this, making
even more complex code.

2.2 Identifiers and Naming Conventions


Identifiers are used to make variables to be used in the code later on. This makes it so that such
variables can be changed. There are specific naming conventions of which we have to name
these variables. It is as such simply to improve readability for future co-workers to read your
code. It is not a requirement but a standard.
1.) Start by creating variables.

int - Integer value, consists of only whole numbers


double - Any number value, including decimals
Boolean - true or false values
String - Any collection of character

2.) After the variables, type in the following print statement.

3.) Then, run the program and the following should show in the terminal.

5
Figure 2.2.1 Java Terminal

For naming conventions, the “a” , “b”, “c”, “d” can be named anything the user wants, but no
matter what they have to start as a lowercase or in camel case. This is done so that in the future,
when looking back at a code, anyone looking would know that the variable is a named variable
that was made up, and not instead something within the language.
Examples include:
- “a”
- “name”
- “age”
- “nameAndAge”

3.0 If-Else Statements

3.1 Relational Operators and If-Else Statements


If-else statements are a sophisticated tool which increases the usability and the functions the code
can handle. If-else statements are written so that based on a specific parameter, a certain code
would be run corresponding to the parameter. This parameter is called a relational operator.
1.) Type the following code to set up an if-else statement

2.) Recall that “b” in our previous example is 4.5


3.) After running the program the terminal should display the following.

Figure 3.1.1 Java Terminal

The relational operator in this example would be “b < 5” and it is true. Because the condition is
met, only the block of code within is executed. If the condition is not met, the program goes on
to the else statement.

6
Keep in mind that there are many comparators that we can use:
- “a < 5” A is less than 5
- “a > 5” A is greater than 5
- “a == 5” A is equal to 5
- “a >= 5” A is greater than or equal to 5
- “a <= 5” A is less than or equal to 5

4.0 Looping Structures

4.1 While Loops


Looping structures are essential for limiting redundancy, and increasing readability. They allow a
code to be used multiple times without the need for the code to be typed multiple times. While
Loops are a looping structure that requires an initializer. The initializer is a random variable that
is set outside the loop, but is updated within the loop at each iteration of the loop.
1.) Starting from a fresh new code, type the following in the main method.

2.) Run the program and the following should display in the terminal.

Figure 4.1.1 Java Terminal

In this example, “int a = 0;” is the initializer. The condition for the while loop is “a < 5”. The
iterator is “a++”. The logic of the code is as follows, “a” at first is zero, then the program gets to
the while loop. Since zero is less than five, the code in the loop executes. The program prints
“hello “ once, then with “a++”, ‘a’ gets iterated to become 1, then the program loops back to the
beginning of the while loop. Since one is less than five, the code inside the while loop iterates
again. This keeps going until ‘a’ becomes five. Once ‘a’ becomes five, ‘a’ is not less than five, so
the program continues past the loop.

7
4.2 For Loops
For loops are a more structured way of doing while loops. The parameters are the same, and the
logic is the same.
1.) Type the following into a new main method

2.) Run the program and the following should show in the terminal

Figure 4.2.1 Java Terminal

Notice that there is also an initializer, a relational operator and an iterator, but instead, are all in
the for loop header. For loops work exactly the same as while loops, but there structure provide
different specific situations that are applicable to higher levels of java programming.

Figure 4.2.2 Diagram Comparison between For Loops and While Loops

5.0 Conclusion Statement

This concludes the introductory Java Object Oriented Programming Guide. This is the most basic
guide that teaches every structure needed to build software. As you progress into higher levels of
Java, you will see that every new concept is just a deviation of these main components. By
understanding the basic building blocks, this will provide good fundamentals for Java
Programming.

8
6.0 Glossary

Camel Case
- A naming convention style. When a series of words are used as a variable, the first word
is lowercase, and every proceeding word starts with an uppercase. I.e leoLikesRice

For Loops
- Looping structure where the iterator, relational operator, and iterator are in the header

If-Else Statements
- Code structure where a series of relational operators are stated, and whichever
conditions are met, the proceeding code is the code that is run.

Initializers
- Key component in looping structures. Sets the starting point of a looping statement.

Internet of Things IoT


- Describes how all electronics are being connected to the internet as time goes on

Iterators
- Key component of looping structures that count the number of loops

Relational Operators
- Used in many key Java methods and structures. Allows for the comparison of values so
that the programmer can manipulate the code and to act a certain way based off the
comparisons

While Loops
- Looping structure that allows for whatever block of code inside to repeat itself. Necessary
components are an iterator, initializer, and relational operator.

You might also like