Interview_GC/StringBuilder/JVM/Overloading/Overriding/Abstract/Interface/Generic
β Garbage Collection?
Garbage collection
When Java is run on JVM, manage heap
Stop the world, major GC
π‘ https://soheeparklee.github.io/posts/JAVA_JVM/#%EF%B8%8F-garbage-collector-1
String Builder π String Buffer
Difference between stringbuilder and stringbuffer?
κ°μμ : mutation, APIs like append()
βοΈ μ°Έκ³ λ‘, string is immutable
λ€λ₯Έμ :
- String Builder: synchronization β, fast in single thread
- String Buffer: synchronization βοΈ, multithread
π‘ https://soheeparklee.github.io/posts/JAVA_library/#-string-class
β Memory in JAVA
How is JVM memory?
>
- method area: (class loaded) static, method, final
- heap: (runtime) instance, array
- JVM stack: (compile) local variable, parameter
- PC register: (thread created)
- native method stack: not java
π‘ https://soheeparklee.github.io/posts/JAVA_JVM/#-jvm-runtime-data-area-%EC%A0%80%EC%9E%A5
Overloading π Overriding
Overloading and Overriding?
βοΈ Overloading:
- method name π°
- parameter βοΈ
- return type βοΈ
- when need several
βοΈ Overriding:
- method name π°
- parameter π°
- return type π°
- need inheritence from parent
π‘ https://www.geeksforgeeks.org/difference-between-method-overloading-and-method-overriding-in-java/
Abstract class π Interface
both used for abstraction
βοΈ Abstract class
- extends
- cannot be instantiated directly, serves as
blueprint
for other classes - class can inherit from
only one
abstract class - method, properties can have any access modifier
- can have variables
- need to have minimum one abstract method
βοΈ Interface
- implements
- set of methods a class must implement
- class can inherit
multiple
abstract class - method, properties: public
- no variables
- inheriting class should override all interface methods
π‘ https://www.geeksforgeeks.org/difference-between-abstract-class-and-interface-in-java/
β Generic
- parameterized types
- allow type to be a parameter to method, class, interface
- have predefined type
- Inside <>, only
reference type
(class, interface, array) is possible. - To use
primitive types
, usewrapper
β Access Modifier
- public
- protected: inherited
- default: same class, same package
- private
https://soheeparklee.github.io/posts/JAVA_accessmodifier/
Vector π Arraylist?
Vector
Synchronized.
If one thread is working with vector, other thread cannot have vector
ArrayList
Unsynchronized
several thread can work on arraylist
β Serialization?
JSON β‘οΈ Java, visa versa