Week 8 Blog

This week, we learnt about our first programming language: Java. It’s a high-level programming language and can run on different platforms. Java’s source codes are written on a plain text file (xxx.java), and then compiled into .class file, a file that contains bytecodes (an instruction set for a virtual, machine-independent processor) by Java compiler. In this language, normal letters and capital letters are different, so it is case sensitive and also strictly typed. JVM (Java virtual machine) is a combination of compiler and interpreter of java language. It can run on different platforms as well (platform dependent). There are two steps between Java language and machine language. First, compiler converts source codes into bytecodes, then interpreter converts bytecodes into machine language. 

Steps of Creating a Java Program

There are steps to create a java program. 

  1. Create a new project and a new class. Notice that the name of class should has no space.
  2. Add the project description and author information in the top lines of the source codes. 
  3. Identify data we know
  4. Identify data we need
  5. Declare variables’ names
  6. Initialize the value of identifiers
  7. Processing the data
  8. Output the  result

Primitive Data Types

Longer ones can contain shorter ones, but shorter ones cannot contain longer ones. For example, long can include char. In particular, boolean can only be contained by boolean. 

Java Operators and Arithmetic Operators Precedence 

  • Assignment operator (=): Value on the right of the operator is assigned to the variable on the left
  • Arithmetic Operators: simple mathematical calculations, including * / % + – 
  • Logical operators: change boolean values (true or false) and produce new boolean values. E.g.: && means AND, || means OR, ! means NOT. 
  • String Concatenation Operator (+): print the values of variable with simple English

In arithmetic operators, there are certain calculation orders that computers have to follow. 

Screen Shot 2018-11-07 at 19.14.15

Key Concepts

We also defined some key concepts of Java.

  • Java SE: Java standard edition, 
  • Java EE: Java enterprise edition, 
  • JDK: Java developing kit, tool to develop java programs
  • JRE: Java runtime environment, tool to run Java programs

Programs and Projects

Program 1: Hello World

pro1

Program 2: Area of a circle

pro2

Program 3: Product of numbers

pro3

Program 4: Arithmetic operator

pro4

Program 5: Test result

pro5

Program 6: Indicate a month

pro6

Project: What to eat for meal

Project1

Project2

Project3

Project4

The final project is a rather complex program. We used switch, if and loop to construct this program. It shows what should you eat after you input your hight and weight.

Conclusion

This is the first week that we literally started to write our own real program. Very exciting. Hope with this great beginning, I can create better and better programs in the future.