Sei sulla pagina 1di 4

WORA - Write Once, Run Anywhere

JSE - core libraries,


JSEE - web base
JME - Device programming platform (android dev)
JavaFX - Heavy Animation

Important details in exam:


JRE - Java Runtime Environment
JDK - Java Development Kit
JVM - Java Virtual Machine

Java can be (compiled & interpreted) mostly compiled


JDK -> JRE -> JVM

interpreter - line by line


compile -
javac A.java -> compile the code
java A -> run the .class program

data type: (hierarchy)


- boolean false
- char '\u0000'
- byte 0
- short 0
- int 0
- long (0L)
- float (0.0f)
- double (0.0d)

floating number:
- float
- double

integral Numbers: # No Decimal


- byte, short, int, long

Object References:
Array, Enum, Class, Interface

JAVA8 + -> Allows underscore ( _ ) -> use for readability (concatinate)


identifiers:
-> a
-> $
-> a1
not (1a) (@popo)

package<location> e.g. = com.ph.dxc......;


<access modifer> <clasname>{......}

access modifier:
-default = strictly package itself
-protected = within the package and sub-classes
-private = within the clas
-public = all can access

<access modifier><non clas modifier><datatypes or object erference><variable name>;

non access modifer:


- final => cannot be change, else error.
- static => one memory allocation only
e.g. final int i = 10;
i = 20; ### Compile error

Constructor:
<access modifier><Classname>(String a, String b){......}

<access modifier><non-access modifier><return type><method name>

return type:
-void (no need to return)
-int

local variable -> available on method and constructor


-> need to initialize or give it a value else error.
instance variable -> private int a;
-> public char b;
Class variable -> private static int a; (with static)
-> allocated on 1 memory location.

public static void main (String[], a[]){ }


- [] => can be anywhere
- can't call other method other than (static) method. same as on the instance
variable (private static int a;)

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

a.equals(b) => check the value itself


a == b => check the reference value

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) {

Integer arr[] = {1,2,3,4};


arr[1] = null;
for(Integer a : arr){
System.out.print(a);
}
}
7) NumberFomatException
8) super() in getting value of instance variable protected on other package

Potrebbero piacerti anche