Store all my notes for java interviews
- Boolean .equals(obj1, obj2)
- Default: (shallow comparison) checks if two object references points to the same object
- Override: (deep comparison) compares relevant data members
- public int hashCode()
- Distinct objects have different hashCodes
- Returns hash code values as an integer
- Must be overridden if .equals is overridden
- Used in Hashtable, HashMap, HashSet etc. as the key
- If collisions occur, data is stored in a bucket. Then .equals is applied to find the correct object.
- If .equals returns true, then hashCode must be same.
- If .equals returns false, then hashCode may be different or same.
- If hashCode are equal, do not imply .equals is true
- key-value data store
- Good for small and static data like HTML code fragments, strings
- Not good for dynamic data
- Multi-threaded, LRU for old data
- 250 bytes key names
- key-value data store, data structure store
- Single-threaded: can scale horizontally
- Control 6 data eviction policies
- 512 MB keys and values
- 5 data structures
- lists, sets, sorted sets, hyperloglogs, bitmaps, geospatial indexes
- Redis Hash to store objects fields and values instead of serialized object
- Serving layer for data calculated by spark
[Redis vs Memcached] (http://www.infoworld.com/article/3063161/application-development/why-redis-beats-memcached-for-caching.html)
- AUTO_INCREMENT column must be defined as part of an index
create table box( my_id int(16) auto_increment, toys varchar(4000), PRIMARY KEY (my_id) ) ALTER TABLE box AUTO_INCREMENT=1001; insert into box (toys) values("foobar");
Proxy server, load balancer, and HTTP cache. Round-robin, Least-connected, IP-Hash, weighted load-balancing Has one master process and several worker processes. Server health checks
- Add synchronized to a method
- Use atomic data types such as AtomicInteger
- Locking mechanisms
Each thread in a process has access to the same memory. Processes loads and saves registers for each thread.
Semaphores support wait and signal operations. Mutexes support lock and unlock methods. Each object in Java has its own mutex. Synchronized methods lock the mutex and unlock when methods completes.
- Mutual exclusion: Only one process can use the resource at a time.
- Hold and Wait: A process holds a resource and keeps it while waiting for other resources
- No preemption: Resource only released voluntarily by its process
- Circular wait: A process waits for a resource held by another process. And the second process is waiting for the resource held by the first process.
- Removing mutual exclusion means no process has exclusive access to a resource
- Process requests all resources before starting up
- Release all resources held by a process.
- Disabling interrupts in critical sections. Requires hierarchy to determine ordering of resources.
The ability of one method to have different behavior depending on the type of object it is being called on.