Autoboxing:
The Java language inherited a major part of its language
semantics from C which allowed for primitive types to be
included into Java. Primitives are very helpful as they increase
speed, efficiency and bring them closer to real life numbers.
This facility comes at the expense of object orientation as
these primitives are not classes. The collections framework was
created with object orientation in mind; hence they work only
with objects. As a result of this programmers have to go through
the trouble of converting primitive types to their respective
wrapper objects so that they can be stored in collections. The
reverse process of converting from a wrapper to the primitive
needs to be done as real life computations are done on
primitives rather than on objects. This introduces a lot of
unnecessary conversions and checks that make programs huge.
The new changes propose a new Autoboxing technique that would
allow automatic conversion of primitives into their
corresponding wrapper types. The change reduces unnecessary
casts while converting primitives to their corresponding
wrappers.
Boxing allows int values to be converted into Integer objects,
the other primitive types included in boxing are byte, char,
short, long, float and double. The reverse process of unboxing
allows wrapper objects to be converted into their corresponding
primitive values.
Earlier to the proposal "for loops" , "while loops" and "do
while loops" only accepted primitive values within them making
it difficult for primitive wrapper objects to be used in the
loops. The autoboxing technique fixes the problems and allows
wrapper objects to be used in these loops. So a while statement
can now take a Boolean or a boolean expression and evaluate it,
while a "for loop" can take Integer arguments and int arguments.
In the same way, bit wise operations, arithmetic operations and
logical operations that could only be done previously on
primitive data types can now be done on wrapper objects.
Typesafe Enumerations:
The new JSR enhancement proposes to include a C style
enumeration to increase the power and performance of Java. The
enhancement is inspired from the Enum pattern described in the
book "Effective Java Programming Language Guide". The Enum
provides compile time type safety and performance comparable to
primitive constants. It provides a namespace for each enum type
so that class name prefix need not be included with each
constant name. Moreover the Enum provides flexibility to add,
remove or modify constants without recompiling Clients. It also
provides flexibility to add arbitrary fields to an Enum and
allows them to be used with the Collections framework.
An enum is a special type of class that has members that are
public enum constants. All enum classes are serializable,
comparable and non cloneable so that comparison and
serialization operations are automatically taken care of.
A sample of a enum would be:
public enum Months {January, February March, April, May, June, July,… }
The new Enumeration is proposed as a new class called Enum that
will be included into the java.lang package and all Enum
implementation classes will have to subclass themselves from
this Enum class. Additionally an EnumSet and EnumMap
implementations are being added to the java.util package to
enhance the power of the collections framework.
All Enum classes are implicitly final with a few rare
exceptions. Enum classes cannot be instantiated using the new
operator. Constructors are not allowed to chain to a super class
constructor, however an Enum class constructor may chain with
other enum constructors.
public enum Months {
January(1), February(2), March(3)
Months (int value){
this.value = value;
}
private final int value ;
public int value(){
return value;
}
}
The syntax of the switch statement is extended to include enum constants.
switch (Months){
case Months.January:
return 1;
case Months.March
return 3;
}
The proposed enhancement makes no changes to the JVM and is
implemented in the Java language by the inclusion of a few
libraries. It also works seamlessly with the other enhancements
like the static import and enhanced "for loop".
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|