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

Java se 8 Repeating Annotations

Repeating Annotations ( Java SE 8) In some cases we need to use Repeated Annotations as per the requirement @Retention(RetentionPolicy.RUNTIME) @interface CustomAnnotation { String city() ; int pin() default 123; } @CustomAnnotation(city = “Vijayawda”) @CustomAnnotation(city = “Chennai”) public static void testAnnotation() { System.out.println(“Custom annotation test”); } If you use repeated Annotations like this compiler will…

Continue reading

Static Import

Static Import The static import feature of Java 5 makes the programmer’s life a little bit simpler by accessing any static member of a class directly. No need of class name at all directly access by the name If you want to access any static member of a class often, by using this feature makes…

Continue reading