J2SE Platform 5.0: Language Changes
Generics
Generics are imparted to the Java programming language in year 2004 as part of J2SE 5.0. It provides ability of generic programming. They admit a type or method to operate on objects of several types while offering compile-time type safety. A common use of this characteristic is when using a Java Collection that can accommodate objects of any type to determine the particular type of object stored in it.
According to specifications of Java Language:
A type variable is an incompetent identifier. Type variables are brought in by generic interface declarations, generic class declarations, and generic constructor declarations and by generic method declarations.
A class is generic if it announces one or more type variables. These type variables are referred as the type parameters of the class. It specifies one or more type variables that act as parameters. A generic class declaration determines a set of parameterized types, one for each possible invocation of the type parameter section. All of these parameterized types contribute the same class at run time.
An interface is generic if it announces one or more type variables. These type variables are referred as the type parameters of the interface. It determines one or more type variables that act as parameters. A generic interface declaration determines a set of types, one for each possible invocation of the type parameter section. All parameterized types share the common interface at run time.
A method is generic if it announces one or more type variables. These type variables are referred as the formal type parameters of the method. The form of a type parameter list of a class or interface and formal type parameter list, both are identical.
A constructor is generic if it announces one or more type variables. These type variables are referred as the formal type parameters of the constructor. The form of the formal type parameter list is similar to a type parameter list of a generic class or interface
Autoboxing
Autoboxing is the term for aiming a reference type out of a value type just through type conversion. The compiler automatically supplies the extra source code which produces the object.
For instance, in versions of Java prior to J2SE 5.0, the following code did not compile:
Integer i = new Integer(9);
Integer l = 9; // error in versions prior to 5.0!
Integers are reference objects, on the surface not different from List, Object, and so forth. To convert an int to an Integer, one had to manually discover the Integer object. Later J2SE 5.0, the compiler will admit the last line and automatically translate it and thus an Integer object is generated to store the value 9.
Where a and b are Integers and will compile directly since they are unboxed. These integer values summed up and the result is autoboxed into a new Integer. The new integar is finally stored inside variable c. The equality operators cannot be used in this manner, as of the equality operators are already determined for equality of the references, for reference types. In order to test for equality of the value in a boxed type, one must manually unbox them and compare the primitives.
Unboxing is referred to getting the value which is affiliated to a given object, just through type conversion whether explicit or implicit. The compiler automatically supplies the extra source code which recalls the value out of that object. It can be done either by invoking some method on that object or by some other means.
Enums
The J2SE version 5.0 of the Java programming language incorporated enumerated types whose declaration syntax is very much similar to that of C's. For example:
enum Cardsuit { CLUBS, SPADES, HEARTS }; ...
Cardsuit trump ;
The Java type system, despite anything to the contrary, handles enumerations as a type separate from integers and intermingling of enum and integer values is not allowed. In fact, an enum type in Java is in reality a special compiler-generated class rather than an arithmetic type and enum values act as global pre generated representatives of that class. Enum types can have example methods and a constructor. All enum types extend in implicit manner, the Enum abstract class. An enum type cannot be represented directly.
Each enum value contains an integer, representing to the order in which they are announced in the source code, starting from 0. The user cannot set a custom integer for an enum value directly, merely one can set overloaded constructors which then assign arbitrary values to self-defined members of the enum class. Determining getters permits then access to those self-defined members.
The internal integer can be incurred from an enum value using the ordinal() method and the list of enum values of an enumeration type can be incurred in order using the values() method. It is in general demoralized for programmers to convert enums to integers and vice versa.
The Java standard library allows utility classes to use with enumerations. The EnumSet class implements a Set of enum values. It is implemented as a bit array, which establishes compact and as effective as expressed bit manipulation.. The EnumMap class implements a Map of enum values to object. It is carried out as an array with the integer value of the enum value assisting as the index.
Varargs
Varargs feature was introduced in J2SE 5.0. The last argument of the method can be announced as a variable arity parameter, where the method becomes a variable arity method or simply varargs method. This permits to pass a variable number of value of declared type to the method as parameters including no parameters. These values are accessible inside the method as an array.
The example of Varargs is as following
void printReport(String header, int... numbers) {
System.out.println(header);
for (int num : numbers) {
System.out.println(num);
}
}
// Calling varargs method
printReport("Report data", 74, 83, 25, 96);
Static Imports
Static import is a characteristic feature brought in the Java, which permits members I.e methoda and fields determined in a class as public static to be utilized in Java code without defining the class in which the field is specified. This characteristic feature was inscribed into the language in version 5.0.
It provides a mechanism to include constants into code without having to refer the class that primitively defined the field. It also assists to depreciate the practice of creating a fixed interface. An interface that only determines constants then writing a class implementing that interface, which is believed to be an incompatible use of interfaces.
Annotations
In the Java computer programming language, an annotation, is a special form of syntactical metadata that can be contributed to Java source code. Classes, variables, methods, packages and parameters may be annotated. Not like Javadoc tags, Java annotations can be contemplative in that they can be embedded in class files yielded by the compiler and may be held back by the Java Virtula Machine to be made recoverable and retrievable at run time.
Concurrency
The Java language and the Java Virtual Machine have been projected to support simultaneous programming where all execution takes place in the context of threads. Objects and resources can be retrieved by separate threads. Each individual thread has its own path of execution but can possibly access any object in the program. The programmer must ascertain read and write access to objects is properly synchronized between threads. Thread synchronization assures that objects are altered by only one thread at a time and those threads are kept from accessing partly updated objects during alteration by another thread. The Java language has inbuilt constructs to back up this coordination.
The major synchronization idea for Java Virtual Machine concurrency is the monitor. Every object in a Java Virtual Machine has a monitor linked with it. Such monitor based concurrence was earlier brought in with the Mesa programming language.
The Java Language Specification does not state how the Java Virtual Machine designer should go through the multithreading primitives determined, because there is so much fluctuation among the various operating systems and hardware on which the Java Virtual Machine is anticipated to run.
Java Assignment Help - Java Homework Help
Struggling with java programming language? Are you not finding solution for your java homework and assignments? Live java experts are working for students by solving their doubts & questions during their course studies and training program. We at Expertsmind.com offer java homework help, java assignment help and Java projects help anytime from anywhere for 24x7 hours. Computer science programming assignments help making life easy for students.
ExpertsMind.com - J2SE Platform 5 Assignment Help, J2SE Platform 5 Homework Help, J2SE Platform 5 Assignment Tutors, J2SE Platform 5 Solutions, J2SE Platform 5 Answers, Java Programming Assignment Tutors