Articles : Java Language Enhancements :

Static Import:

Java provides a number of static utility methods like parseInt(), abs, sqrt etc that can be used to do mathematical and other logical operations. These methods are provided as static methods so that an explicit instantiation is not required to use them. Additionally programmers use constants as static final variables so that they can be used across the whole applications without instantiation. The way these variables are accessed can be made easy by omitting the class name as the class name identifier is many times redundant.

The new static import proposes a similar addition called static imports where the import statement is modified to import static methods and fields just like classes are imported. This makes it easy for mathematical and other standard operations provided in Java to be accessed directly without the class name. It also makes it easier to import constants and use them directly in the code with out the class modifiers. If the above mentioned enum is also included in the Java spec then enums can be directly accessed without the enum name.

The proposed declaration would look like this

	import static java.lang.Math ;
	import static mypackage.ProjectConstants; 
	import static Seasons;
	
      int a= Math,max(Seasons.January ,Integer.parseInt("5") ); 
      can be replaced by 
      int a = max (January, parseInt("5"));

The method max is part of the Math package and January and March are declared in an Enum class defined in the Enum section of this article.

The keyword static is redundant here as the compiler would obviously know that the imported file has constants or static methods. It has been included into the declaration so that it is clear to the programmer that the imported file is a constant rather than an application class file.

The static import only works for static methods and variables and cannot be used to import instance variables of classes.

To avoid name clashes two static import declarations with the same name would throw a compilation error. However if two static import declarations point to the same class, then one of them is ignored as duplicate.

Variable-Arity Methods (Varargs):

The JSR proposes to introduce variable length argument list methods to the Java language. The affect of this can be felt in applications that use a lot of internalization in their code. Presently Java allows a fixed length argument list which is used in methods like java.text.MessagingFormat.format() to format messages. The new proposal introduces a variable length argument list that can be used to pass in multiple values for internalization purposes.

Conclusion:

The JSR 201 has proposed a wide range of enhancements to the Java language to make it more effective than it already is. They are taking special care to make sure that these changes do not affect existing programs and doing their best to make them backward compatible. The changes do not affect how the JVM behaves and are mostly taken care of by changes to the compiler and in some cases by additional library support. Sun has carefully steered away from adding keywords like it did when it introduced assertions in the Java language. The new specification is in the public review stage where input from programmers like you are solicited. Many discussions boards are already discussing these changes. It would probably be a good idea to start off a thread here at JavaBoutique 's Forums and discuss the implications these enhancements have on the Java language. This could go a long way in contributing the input of programmers to help shape the future of Java.

More Information:

The JSR 201 home page is http://jcp.org/en/ jsr/detail?id=201. The J2SE 1.5 is in the beta 1 stage as of now and most of these enhancements are already included into the specification.


Benoy Jose is a web developer with over six years of experience in J2EE and Microsoft technologies. He is a Sun Cetified programmer and enjoys writing technical and non-technical articles for various magazines.


Print Article

How to Add Java Applets to Your Site

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.