Java — Object Oriented Programing

Concepts of OOP — PART 1

Some important things to note

- Case Sensitive, ex. HelloWorldApp and helloworldapp are different
- Class name need to be the same as file name, ex. in HelloWorldApp.java

  • public class HelloWorldApp {
     public static void main(String[] args) {
     }}

Basic action to take

  • Get a value from the memory
  • Store a value in memory
  • Compute a value from other values
  • Read a value from the input device
  • Write a value to an output device
  • Control Structure

Identifiers

  • Java identifiers are case-sensitive — this means that upper and lower case letters are considered to be different
  • Many Java programmers use the following conventions — 
    - Classes : start with upper case, then start each word with an upper case letter
    - ex : StringBuffer, ArrayIndexOutOfBoundsException
    - Methods and variables: start with lower case, then start each word with an upper case letter
    - ex : compareTo, lastIndexOf, mousePressed

Variables

  • Precision: byte < short < int < long < float < double
  • Primitive Types : 
    - Simple types whose values are stored directly in the memory location associated with a variable
    - byte, short, int, long, float, double, char, boolean
  • Reference Types :
    -
    Types whose values are reference to objects that are stored elsewhere in memory
    - ex: String s = new String(“􏰢Hello There􏰝”);
    >>> s → “Hello world”
不同的物件會有不同的 reference,舉例來說:
StringBuffer s1, s2, s3;
s1 = new StringBuffer (“Hello”);
s2 = s1;
s1.append(“ the Java master!”);
s3 = new StringBuffer(“Hello the Java master!”);
System.out.println(s1 == s2); // true
System.out.println(s2 == s3); // false
System.out.println(s1 == s3); // false

Operators and Expressions

  • Precedence and Associativity
    - Precedence indicates the order in which operators (􏰤􏰏􏰠運算子) are
    applied
    - Associativity indicates the order in which operands (運算元􏰤􏰏􏰟) are accessed given operators of the same precedence
||, &&, |, &, +, -, *, /, 有不一樣的優先權
System.out.println(true || true && false ); // true
System.out.println(true | true && false); // false
System.out.println((true | true) && false); // false
System.out.println(true | (true && false)); // true
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.