String Pool

Almost in every program, String is being used. When we create a string, it is stored in String pool, as name indicates it is a pool of Strings stored in Java Heap Memory. We can create String in 2 ways By using new operator, String v1 = new String(“Test”); Directly assign the value using Double…

Continue reading

Generics

Generics Java Generics features were introduced from Java Se 5 onwards. Before Java 5, we can store any type of objects in collection i.e. non generic. With inclusion of Generics we need to store only specific type of objects only. Let’s look at the benefits of generics Compile time checking: Generics allows you to check…

Continue reading

Custom Annotation

Custom Annotation Similar to interface we can define Custom Annotations or user defined annotations simply by adding @interface in the declaration. For example: @interface CustomAnnotation{} Here, CustomAnnotationis the custom annotation name. While writing the custom annotations few points has to be considered. Method should not have any throws clauses, Similar to interface only declarations available…

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

Annotations Java se 5

Annotations in java Annotations in java, a form of metadata, provide data about a program.Java annotations do not directly affect the execution of your code. The main purposes of Java Annotations are Annotations provides information to compiler for detecting errors or suppress warnings etc.(Compiler Instructions) Annotations are used at build time and deployment time processing…

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

Autoboxing and Unboxing

Autoboxing and Unboxing The automatic conversion or encapsulation (boxing) of primitive data type (Ex byte, char, int, double, Boolean etc.) into its equivalent wrapper class objects (Ex Byte, Character, Integer, Double, Boolean etc.) is known as Autoboxing and reverse process is known as Unboxing i.e. automatic conversion of Wrapper class objects to its corresponding primitive…

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

VarArgs (Variable Arguments)

VarArgs Variable Arguments VarArgs feature introduced in Java se 5. Before introducing this feature if user don’t know how many arguments (similar data type) need to pass we will go for overloading concept or array. Consider this example before java se 5 public class VarargsTest { public static void multiSelect(String one, String two, String three){…

Continue reading