Java Interview questions
Java Interview questions
Difference between Stack memory and heap memory, why do we need two memories?
String pool – separate memory in heap, (all similar values are not recreated in pool) – makes our
memory optimized.
Public Static Factory Method (getInstance()): In this method instance is created if(instance == null)
instance = new Singleton();
Return instance;
Immutablity:
‘a’ + ‘b’ => if two char is added gives sum of ascii values 195, if a char+ string gives a string (string
concatination)
stringBuilder: data type where strings can be modified without creating a new string.
Comparison of strings: (==) comparator checks if reference variables are pointing to same object.
return (s+s).contains(goal);
Collections Framework:
Array drawbacks – fixed size, Homogeneous data, arrays can hold primitives and objects
Collection has default capacity of 10 elements, if it exceeds a default capacity a bigger ArrayList is
created internally.,
Collection is representing a group of objects as a single entity (like add, remove, isEmpty)
Spring : It is a Java framework , spring boot : extension of spring, provides different starter template
(contains all dependencies),