How to create immutable class in Java?

How to create immutable class in Java? Immutable class is a class which once created, its contents cannot be modified. Immutable objects are the objects whose state cannot be modified once it is created. Best example to explain the difference between mutable and immutable is String and StringBuffer. String is immutable class (Refer String is…

Continue reading

String is immutable or final in Java

String is immutable or final in Java? One of the Interviewers favourite question, How String plays an important role in every program, similarly in every interview questions on String will be there 🙂 😉 . Let’s check the reasons behind why String is immutable of final. Security: String is used in many places like in…

Continue reading

Enumeration or Enum

Enumeration or Enum Enum or Enumeration is a type like a class or interface that contains set of fixed constants. Syntax: enum EnumName{ Constant1, Constant2, Constant3
.} Example:   public enum directions{ NORTH, SOUTH, EAST, WEST } //Internally Enum will look like this public class Directions extends  java.lang.Enum { public static final Directions NORTH= new Directions (); public static…

Continue reading