Powered by Blogger.

Sunday 12 June 2016

Enumerations, Autoboxing and Annotation(Metadata)

No comments :
Enumerations: An Enumeration defines a class type. By making enumerations into classes,The capabilities of the enumeration are greatly expanded.For example, in java, an enumeration can have constructor, methods, and instance variables.
Enumerations Fundamentals: An enumeration is created using the enum keyword.For Example:

The values() and valueOf() Methods:  
All enumerations automatically contain two predefined methods: values() and valuesOf().
Their general forms are show here:

The values() method returns an array that contains a list of the enumeration constants. The valueOf() method returns the enumeration constant whose value corresponds to the string passed in str. In both cases, enum-type is the type of the enumeration.
The following program demonstrates the values() and valuesOf() methods:
Type of Wrappers: The type wrappers are Double, Float, Long, Integer, Short, Byte, Character and Boolean. These classes offer a wide array of methods that allow you to fully integrate the primitive types into java's object hierarchy.
The Numeric Type Wrappers:These are Byte, Short, Integer, Long, Float and Double. All of the numeric type Wrappers inherit the abstract class Number. Number declares methods that return the value of an object in each of the different number formats.These Methods are shown here.

Example:
Autoboxing/Unboxing Autoboxing and unboxing take place whenever a conversion into an bject or from an object is required. This applies to expressions. within an expression, a numeric object is automatically unboxed. The outcome of the expression is reboxed, if necessary.
Example:
Output is :
Original value of iob:100 
After ++iob:101 
iob after expression:134 
i after expression:134 

Annotations(Metadata) : An annotation is created through a mechanism based on the interface. Let's begin with an example: Here is the declaration for an annotation called MyAnnotation