Whats a status code?
A status code is a part of the result of an http request that contains a 3-digit integer where the first digit of the Status-Code defines the class of response and the last two digits do not have any categorization role.
Why String class is immutable in Java?[Good]
String class is immutable because Java stores only a single copy of the string in a string pool in a special region in the JVM so memory is conserved. It does so to provide the following benefits: caching, security & synchronization.
Immutable: An immutable object is an object whose internal state remains constant after it has been entirely created
Caching – Only a single copy of the string is stored in a string pool in a special region in the JVM so memory is conserved. This process is called interning
Security – It is easier to work with immutable object when sensitive information is passed. Avoids SQL injection.
Synchronization – Immutable objects can be accessed by multiple threads since the value of the string doesn’t really change hence strings are thread-safe.
What is the difference between method overriding and method overloading?
Method overriding occurs when a method is inherited from a parent class but the programmer changes its behavior to something else
Method overloading occurs when two methods with the same name but different parameters in the same class perform different operations.
What is the difference between a Hashmap and Hashtable?
- HashMap is non synchronized. It is not-thread safe and can’t be shared between many threads without proper synchronization code whereas Hashtable is synchronized. It is thread-safe and can be shared with many threads.
- HashMap allows one null key and multiple null values whereas Hashtable doesn’t allow any null key or value.
- HashMap is generally preferred over HashTable if thread synchronization is not needed