Strings Not GarbageCollected
Strings are immutable, they are not garbage collectable! They are stored as char[] with start, end indexes. a substring() call just returns the same whole array with new indexes.
To avoid Strings use StringBuilder! Especially if you do a lot of string manipulation (concat, modify, substring, delete,...)
StringBuffer is the thread-safe version of StringBuilder
Wrappers of Primitive Types are Immutable! you can't change the content of a wrapped primitive.
Debug: System.out.println()
They will show in the console all the time, Either when you debug or not.
Will be ignored for normal execution (and won't slow down the program when you don't want to debug) unless explicitly specified that you are debugging - then they will be executed.
Assert(height > 0);
//passes if the statement is true, throws exception otherwise
Assert(height > 0) : "height= "+ height;
//statement after colon can be any java expression that results in a non-null value
java -ea MyProgram
static nested classes have access to private and static fields of the parent class.
Anonymous class is for example when as a parameter of a method you just implement an abstract class or interface.
protected is just like default, EXCEPT that subclasses outside the package inherit the protected thing
Enum class
public class Myclass{
BAND_TYPE1("my title 1."){
public String getMusic(){
}
BAND_TYPE4("another title here."){
public String getMusic(){
}
}
BAND_TYPEx("BandWithoutBody");
private String title;
Types(String someTitle){
}
public String getTitle(){
}
public String getMusic(){
return "This is a kind of static method, vs the specific type getMusic()";
}
}
public static void main(String[] args){
for(Types t: Types.values(){
System.out.print(t);
System.out.print(t.getTitle());
System.out.println(t.getInstrument());
}
-------------------------------------
BAND_TYPE1 my title 1. jazz
BAND_TYPE4 another title here. Classical
BAND_TYPEx BandWithoutBody This is a kind of static method, vs the specific type getMusic()
** The less two classes know about each other the more loosely coupled they are, they easier they are replaceable
Remote Proxy: is an object local to the client object that pretends to be a remote object. - stub
java.lang.reflect.
Proxy
provides static methods for creating dynamic proxy
classes and instances, and it is also the superclass of all
dynamic proxy classes created by those methods.
Link A
dynamic proxy class (simply referred to as a
proxy
class below) is a class that implements a list of interfaces
specified at runtime when the class is created, with behavior as
described below.
A
proxy interface is such an interface that is implemented
by a proxy class.
Each proxy instance has an associated
invocation handler
object, which implements the interface
InvocationHandler
.
A method invocation on a proxy instance through one of its proxy
interfaces will be dispatched to the
invoke
method of the instance's invocation handler, passing the proxy
instance, a
java.lang.reflect.Method
object identifying
the method that was invoked, and an array of type
Object
containing the arguments. The invocation handler processes the
encoded method invocation as appropriate and the result that it
returns will be returned as the result of the method invocation on
the proxy instance.