Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
floating number:
- float
- double
Object References:
Array, Enum, Class, Interface
access modifier:
-default = strictly package itself
-protected = within the package and sub-classes
-private = within the clas
-public = all can access
Constructor:
<access modifier><Classname>(String a, String b){......}
return type:
-void (no need to return)
-int
post -> harap ng variable ( ++a) -> value will change after calling the variable
pre -> dulo ng variable (a++) -> value will change automatically.
conidition ? true:false;
Heap vs Stack:
person p1 = new variable_name();
heap => new variable_name();
stack => p1
string collector:
string a = 'hello' -> store the "hello" to string collector
string b = new string('Hello'); -> store to heap
constructor:
-> name is the same to the class name
-> can be run thru insatantiation e.g. person newPeron = new person();
-> no return e.g. persion(){...}
OOP:
- Encapsulation - getter and setter (getName, setName, isName, isEmpty)
- Inheritance
-> extends variable(PARENT)
-> implements
-> e.g. System.out(arr instanceof Object) = TRUE
-> one(1) parent/class only e.g. Public class A extends B (not) Public class
A extends B,C,D
-> use super for accessing other class' method. e.g.: super.print()
-> using THROWS => public void A() Throws Exception{ throw new Excepetion();}
- Polymorphism
- method overloading
-> Same method name but different number or type/data type of/in
parameter
e.g.: public void sum(int a, int b)
public void sum(int a, int b, int c) (correct)
private void sum(int a, int b) (wrong)
void sum() (correct)
void sum (int a, int b) (wrong)
-> if static (cannot be change)
-> e.g.: public static variable()
- abstraction
-> abstract method -> abstract class
-> if there's a abstract method inside the class, the class should have
abstract too else, error.
->
interface: (JAVA 8)
-> implements only, cant be use for new instance.
-> default void variable(){}
-> static void variable(){}
-> can extends multiple class e.g.: Public interface A extend B,C,D{}
-> instance variable should have value else, compile error. e.g. int y;
-> can have string/int return value. e.g. default string/int print(){}
functional interface:
-> can only have 1 abstract method. e.g. public void run();
-> can also have default and static method.
-> annotate @FunctionalInterface
-> only have 1 abstract method, else error
inner class:
-> filename should be the same as name of the public name inside of the code.
lambda:
-> no (public) and (void) on the class. e.g. run()->{}
-> arrow head is a must.
-> the method run() should be method on the interface.
-> if data type is already stated on the interface class. lambda expression
doesn't need to declare data type. e.g. int add(int x, int y)
-> lambda A a = (x, y)->{};
-> semicolon (;) is a must in lambda.
-> if one liner, no need to put curly braces, but semicolon is a must.
consumer:
-> no return value
-> accept parameter then it will just process but no return.
-> abstract method: e.g. void Accept(T t);
-> Consumer<Integer> i = (x)->SystemOut.print(x);
Predicate:
-> one parameter
-> return boolean
-> check the ... or more one comparing.
-> Preidcate<Integer> i = (x)-> x>10;
-> must return boolean e.g. abstract= public boolean test(T t);
Function:
-> one paramter
-> return Any Type
-> define generic type
R = return
T = Any type
(x)-> String.valueOf(x); ==== Convert int to string
Notes:
StringBuilder class don't have (concat) instead use (append)
questions:
1) interface, contains one abstract . but there is no abstract on this
example. public void print(T t);
2) ClassCastException. intger to string
3) override interface method
e.g.:
public interface A{
void print();
}
4) y = ++x * 4 / x-- + ++x;
5) LocalDate what is this?
6) method argument with identifier? cant be use for "for" loop
e.g.:
public static void main(String[] a) {