Welcome!
This is the last week of October brought us surprise. We finally began to learn Java stuff. It is an exciting week because we have first contacted with programming. This week Mr. Pete mainly introduced java to us. We get a basic knowledge of Java: rules in Java and we created quite a lot of Java programs.
Intro to Java
Java is a high-level programming language and a cross platform. Java program should be written strictly. All source code is first written in plain text files ending with the .java extension. These files are then compiled into .class files by the java compiler.
General Steps of Creating a Java Program
In order to create a Java program, we need first to know the general steps of creating a Java program. First, we should create a new class and create a new name. It is necessary to mention that class name should not have space. After opening the class, we delete all the yellow part. On the top part (green background), we should write the description for this program which is convenient for people to know what the program is about.
Through computational thinking, we will know what problem is. Then we identify what data do we already know. We will identify other data we will need. After finding the unknown data, we declare variable names for those unknown data.
Next, we initialize the value of any possible identifiers (eg. int numA = 1).
Later, we perform our calculations, like doing the mathematical things(writing the equations to calculate the result).
Eventually, we output or print the result (System.out.println();)

These are the abstract steps for creating a new Java program.
Java’s Primitive Data Types
There are eight primitive data types: byte, short, int, long, float, double, boolean, char. Different primitive data types have various meanings.
“byte” is an 8-bit signed two’s complement integer. The minimum value of byte data is -128 and the maximum value of a byte data is 127. The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. Byte is so useful that can help people to save memory.
“short” is a 16-bit signed two’s complement integer. It has a minimum value of -32,768 and a maximum value of 32,767. People can use a short to save memory in large arrays, in situations where the memory savings actually matters.
“int” is a 32-bit signed two’s complement integer. We use “int” a lot during Java programming.
“long” is a 64-bit two’s complement integer. The signed long has a minimum value of -2^63and a maximum value of 2^63-1. Use this data type when you need a range of values wider than those provided by int.
“float” is a single-precision 32-bit IEEE 754 floating point. This is not the main topic in IB program. So we did not discuss a lot during the class.
“double” is a double-precision 64-bit IEEE 754 floating point. Double could represent an extremely large range of number. For decimal values, this data type is generally the default choice. However this data type should never be used for precise values, such as currency.
“boolean” has only two possible values which are true and false.
“char” is a single 16-bit Unicode character which means that it could represent characters, like Chinese characters, English characters.

Java operators and arithmetic operators precedence
Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups :Arithmetic Operators, Relational Operators, Bitwise Operators, Logical Operators, Assignment Operators, Misc Operators. We mainly focused on arithmetic operators which are really useful in basic Java programming.
Let’s assume that integer variable A holds 10 and variable B holds 20.
| Operator | Description | Example |
| + (Addition) | Adds values on either side of the operator | A + B = 30 |
| – (Subtraction) | Subtracts right-hand operand from left-hand operand | B – A is 10 |
| * (Multiplication) | Multiplies values on either side of the operator | A * B is 200 |
| / (Division) | Divides left-hand operand by right-hand operand | B / A is 2 |
| %(Modulus) | Divides left-hand operand by right-hand operand and returns remainder. | B % A will give 0 |
| ++ (Increment ) | Increases the values of operand by 1 | A++ gives 11 |
| – – (Decrement ) | Decreases the value of operand by 1 | B – – gives 19 |
When people calculate the arithmetic sentences. “()”comes first, then it should be “*” “/”. After doing multiplication and division, it should do addition and subtraction “+” “-“. Finally it comes to “=” to get the final result.
Screenshots of java exercises (code and output)
This is the first program we wrote which was an application to show “Hello world! My name is …”Actually it is really simple but I am really excited because this is the first program I have written in this semester. We know that we MUST write “public static void main(String[] args)” before every program. Maybe because it is difficult to understand for first programmer. So Mr. Pete did not explain what did it mean.


This is the second program which could calculate the area of a circle with particular radius.




This is the first long program we wrote which has arithmetic function. In this program, users could input their individual values. In order to make it come true, we entered “import java.util.Scanner;” on the top of the program. You could see it from the picture shown below.



We use “if” clause to judge the parity of a value and then print out the result.







Conclusion
We learnt a lot during this week. I am so exciting that I eventually began to learn Java program. We created a LARGE amount of programs during the first week. The feeling is amazing. Besides how to create a java program, we also learnt about the basic knowledge of Java program and the basic rules for Java programming. I am looking forward to the next week.