- Java store number with fractional parts as floating point numbers
- store in 4 parts
- sign(+/-)
- mantissa(value)
- radix(10)
- exponent(n for radix ^ n)
- store in 4 parts
- Variable name must start with letter of _
- do not use other symbol (?/!….)
- use upperCase letter or _ to show separate
- no not use java words(new, int….)
- const in c++ = final in java
- commant
- // single line comment
- /* \n */ all comment until matching
- /** \n */ javadoc
- convert between type
- use typeA a = (typeB) b (same value and conver to b type)
- A a = new B() create a B type value
- use typeA a = (typeB) b (same value and conver to b type)
- value type
- integer
- byte
- short
- int
- long
- float
- float
- double
- other
- boolean
- char
- all before as pre-build primitive types
- all other type called reference type
- created from classes
- start with UpperCase letter
- actually pointer to a memory
- refers to object
- ex. String = char[n]
- test equality of Stringuse String.equals(“String 2”)
- integer
- public static void main(String [] args)
- public means can be accessed by other
- static means it is used but not an object
- void means no return
- call a method in class, use class.method() syntax;
- mathematical methods
- Math.sqrt(x)
- Math.pow(x,y)
- Math.sin(x)
- Math.cos(x)
- Math.tan(x)
- Math.toRadians(x): degree to Radians
- Math.toDegrees(x): radians to Degree
- Math.exp(x): e^x
- Math.log(x): ln(x) for x>0
- method type
- static means the method is not used on an object
- when call it, just use the name
- the function should not use any data declared inside class except class itself
- instance(non-static) must use the object
- when call it, need objectName.method();
- the function can directly use data declared inside class except class itself
- accessor
- return a value without changing it
- normally return type is dame to data it returned
- mutator
- change the value of data but not return it
- usually use void type
- may take parameter
- static means the method is not used on an object
- Internalising data
- 0 to number(int, float, double…)
- false to boolean
- null to any other
- can be overridden
- Constructor
- if no constructor been written, java will create a constructor by itself
- a class can have multiple constructor with different parameter, compiler will choose based on actual code
- can not been called to a constructed object
- can call when constructing a new object
- can not have return type void, also means just a method that return nothing
- String = null can not use String.length() and cause null pointer exception
- overloading is okay for any method
- primitive copy is copy value of var to another which in different location
- only for primitive var(int, char…)
- because take less space than object variable
- only for primitive var(int, char…)
- object variable use reference, which two variable share same reference
- an object with null reference means no reference
- may cause running time error
- this reference refers to current object been used
- mostly used in method declaration inside class
- can use in constructor when parameter have same name to data object
- Garbage collection
- dellocate an object when it have no reference to it
- keep track to all object with reference
- may slow down running program and use more memory
- avoid mistake by wrong or do not dellocate memory
- Java doc
- @param parameter
- @return return data
- @procon procondition
- @postcon postcondition