An object is considered immutable if its state cannot change after it is constructed. Since they cannot change state, they cannot be corrupted by thread interference or observed in an inconsistent state making them useful in concurrent applications.
Switch statement in Java is for decision making. Unlike
if-then-else statements, the
switch statement can have a number of possible execution paths.
Lately, I have been thinking why shouldn't I complie set of questions that I generally include in interviews for mid-senior level Java Developers. Though I am a big fan of algorithm questions in interviews for developer, I believe including these questions either in screening or half of time in second round interview would give chance to hear about candidate's understanding on core concepts of Java 8+. I like these these questions since they include core concepts in Java that developers use in day to day jobs.
There are three types of selection or decision making statements in Java. First one is
if statement which either performs (selects) an action, if a condition is true, or skips it, if the condition is false. Second is
else statement which performs an action if a condition is true and performs a different action if the condition is false. Third one is
switch statement which performs one of many different actions, depending on the value of an expression.
Objects dynamically created using new operator are deallocated automatically. The technique that accomplishes this is called garbage collection. It works like this: when no references to an object exist, that object is assumed to be no longer needed, and the memory occupied by the object can be reclaimed.