Java - Concepts

Updated: 2019-02-10

Call one constructor from another(multiple constructors exist)

  • use this


16-bit unsigned integers, representing Unicode code points in the Basic Multilingual Plane, encoded with UTF-16, and whose default value is the null code point ('\u0000')

0x0000 - 0xFFFF

Why String is Immutable(Final)

  • Security: Java class loading mechanism works on class names passed as parameters, Strings are made immutable to prevent malicious manipulations
  • Performance/Cache-able
  • Thread-safety: can be share between multiple threads


  • CLASSPATH cannot be a folder, need to include each jar /path/to/*.jar
  • use the first match

Java Memory Model

Java Memory Model

The Java memory model describes how threads in the Java programming language interact through memory. The Java memory model defines when changes to memory made by one thread become visible to another thread

Inter Process Communication (IPC)

pipes and sockets

ThreadLocal, BlockingQueue, Counting Semaphore and ConcurrentHashMap


Autoboxing and Unboxing:

Autoboxing: automatically convert from a primitive to a wrapper

The "wrapper" classes for the primitive data types allow you to make a non-primitive object on the heap to represent that primitive type. For example:


char c = 'x';


Character ch = new Character('x')
Character ch = 'x';

java -jar vs java -cp

Cannot use both!

  • java -jar: specify an executable jar, the classpath should be specified in Manifest
  • java -cp: specify classpath

Why no Operator overloading

Operator overloading always leads to abuse

The right way to print an array



do not use null values in a set or as a key in a map.

Set.isEmpty() does not check for null

if null is needed, use Collections.unmodifiableList() otherwise use Guava's ImmutableList

Runnable vs Callable

Runnable does not return any value, while Callable does.