Skip to main content

Posts

Showing posts with the label JAVA ANNOTATIONS

Java : String Class speciality, Best practices & Memory management

What is String A Java String contains an immutable sequence of Unicode characters. Unlike C/C++, where string is simply an array of char, A Java String is an object of the class java.lang. Java String is, however, special. Unlike an ordinary class: String is associated with string literal in the form of double-quoted texts such as "Hello, world!". You can assign a string literal directly into a String variable, instead of calling the constructor to create a String instance. The '+' operator is overloaded to concatenate two String operands. '+' does not work on any other objects such as Point and Circle. String is immutable. That is, its content cannot be modified once it is created. For example, the method toUpperCase() constructs and returns a new String instead of modifying the its existing content. What is special in Java to handle characters: The String class represents character strings. All string literals in Java programs, such as "abc...

Java : Marker Interfaces - Importance and Usages

Marker Interface It is an empty interface (no field or methods). Examples of marker interface are Serializable, Clonnable & Remote interface. All these interfaces are empty interfaces.  public interface Serializable { // nothing here } Marker interfaces can be replaced with annotations in many places.  Examples of Marker Interface which are used in real-time applications : Cloneable interface : @Clonnable Cloneable interface is present in java.lang package. There is a method clone() in Object class. A class that implements the Cloneable interface indicates that it is legal for clone() method to make a field-for-field copy of instances of that class. This interface tells the JVM that object of the implementing class can be cloned so please prepare the object in such a way that it can support the cloning feature. Serializable interface : @Serializable Serializable interface is present in java.io package. It is used to make an object eligible for saving its state into a fi...