Java Notes

(1) Static Classes in Java

In Java, only nested classes can be declared as static classes. If we attempt to declare a top-level class as a static class, we will get an error. What are static classes? Static classes are nested classes that act like top-level classes, even if they appear somewhere in the middle or the bottom of the program hierarchy (within a class). Static classes do not need the reference of the outer class. They act like an outer class within themselves. Normal non-static nested classes, on the other hand, need reference of the outer class. In other words, static classes are independent of the outer class, while other inner classes are dependent on the outer class.

Reference: https://blog.udemy.com/java-static-class/

(2) LinkedHashMap

public class LinkedHashMap<K,V>
extends HashMap<K,V>
implements Map<K,V>

Hash table and linked list implementation of the Map interface, with predictable iteration order. This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order). Note that insertion order is not affected if a key is re-inserted into the map. (A key k is reinserted into a map m if m.put(k, v) is invoked when m.containsKey(k) would return true immediately prior to the invocation.)

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html

(3) extends and implements

extends is for extending a class.

implements is for implementing an interface

(4) final Keyword in Java

If you make any variable as final, you cannot change the value of final variable(It will be constant).

If you make any method as final, you cannot override it.

If you make any class as final, you cannot extend it.

(5) Class StringBuilder

A mutable sequence of characters. This class provides an API compatible with StringBuffer, but with no guarantee of synchronization. This class is designed for use as a drop-in replacement for StringBuffer in places where the string buffer was being used by a single thread (as is generally the case). Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations.

Reference: http://docs.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html