CHANNELS
HOME
TOP STORIES
COLUMNS
OPINIONS
ZEICHICK'S TAKE
EMBEDDED NEWS
TEST & QA REPORT
ECLIPSESOURCE
SPECIAL REPORTS
SD TIMES 100
JOB BOARD
EVENTS CALENDAR
RESOURCE CENTER
WEBINAR CENTER
ADVANCED SEARCH
RSS
ON THE WEB
SITE MAP
ADVERTISE
EDITORIAL
PRIVACY POLICY
CONTACT US
REPORT A BUG
PRINT EDITION
SUBSCRIBE NOW!
CURRENT ISSUE
BACK ISSUES
SUBSCRIBER SERVICES
BZ MEDIA
ABOUT US
NEWS
BZ RESEARCH
SYSMANNEWS
ST&P MAGAZINE
STPCON
ECLIPSEWORLD
ADVERTISER LINKS
activePDF
Alexsys
Altova
Amyuni Technologies
Automated QA
Axosoft
Business Objects
Codejock Software
ComponentOne
Coverity
Data Dynamics
Developer Express
dtSearch
Dundas
Dynamsoft
Hewlett-Packard
IBM
Imagix
Infragistics
InstallAware Software
InterSystems
iWay
Kovair
LEAD Technologies
McObject
Microsoft
MKS
No Magic
nsoftware
Parasoft
Pegasus Imaging Corp
Perforce
Prezza Technologies
Programmer's Paradise
Programming Research
Rally Software Dev
Red Gate Software
ScaleOut
Seapine
Serena
Software FX
Sparx Systems
Swell Software
Syncfusion
TechExcel
Telerik
UrbanCode
WANdisco
Xceed Software
LOADING...
LOADING...
AS OF 8/21/2008 6:58PM EST
More Thoughts on Tiger
By
Allen Holub
July 1, 2004 —
A month or so ago I talked about my disappointment in some of the features of Sun's Tiger (J2SE 1.5) release ("Missed Opportunities," May 1). This month I want to talk about a couple more problems that I see in the new version.
As before, bear in mind that there's a lot of good stuff in Java 1.5. It seems appropriate to devote column space to the features that might give you grief, however, since you're less likely to hear about it from the official documentation.
STATIC IMPORTS
Let's start with static imports. Given this code:
package com.holub.test;
public class Constants
{ public static final String HELLO = "hello";
public static String global = " goodbye ";
public static String noNoNo()
{ return "NoNoNo!";
}
}
you can do this:
import static com.holub.test.Constants.*;
public class Foo
{ //...
public static void main(String[] args)
{ System.out.println( HELLO + global + noNoNo() );
}
}
There's no class-name prefix in front of the HELLO or global references or the call to noNoNO();
Importing a global constant like HELLO is relatively (though not completely) harmless. (The problem is that the static final reference might point to an object that can change state. A static final is not a constant. The lack of a true constant in Java has been a problem from day one.)
Nonetheless, I might be happy with static imports if they were restricted to static final fields. Unfortunately, they aren't. You can also use static import to access what amounts to global variables and functions. I've deliberately used the word "function" rather than "method" in the last sentence. The function noNoNO() is not really a method of a class of objects-it is not called to handle a message passed to some object; noNoNO() is a procedural function, pure and simple.
Yes, Virginia, you can now write a C program in Java. (In fact, if you're really a hard-core C programmer, they've added System.out.printf(), which works just like the C function with the same name.) The language is just too complex to justify its use in non-OO applications. Introducing global variables and global functions is a giant step backward.
GENERICS
The other big addition to Java is generics, which look a lot like C++ templates but are really quite different. People who know templates will be confused by generics, and people who don't know templates will not benefit at all from using the C++ syntax.
A C++ template is a "metaclass." Think of it as a macro whose arguments are type names, which expands to a class definition with the template arguments replacing placeholders in the template definition.
A Java generic is a means of telling the compiler to supply an implicit cast to method arguments or return values. You can use the two mechanisms to accomplish similar ends, but the differences are nontrivial.
Unfortunately, to use generics effectively, you have to master lots of complex and subtle details. I'm not sure that I welcome the introduction of a very-hard-to-get language feature into what used to be a simple object-oriented language. Fortunately, generics have very few uses in practice. The main application is the Collection classes (supplied in J2SE 1.5). Instead of inserting and removing generic Objects, you can specify a type.
The following code defines a LinkedList of Strings. There's no cast needed on the removeFirst() call because the compiler knows that the list has nothing but String objects in it, so supplies the cast.
LinkedList<String> c = new LinkedList<String>();
//...
c.addFirst("Hello");
String s = c.removeFirst();
People have been writing Java for years without generics, and nobody's really noticed that they were missing, other than a few die-hard C++ programmers. I programmed in C++ for eight years before moving to Java, used templates heavily in C++, and didn't miss them at all when I moved to Java.
One of the advantages of Java over C++ was that it didn't have the extra complexity of things liketemplates, which only gurus understood. This will be the case with generics as well. The loss of simplicity is unfortunate.
EMAIL THIS ARTICLE
SEND FEEDBACK
MORE COLUMNS
 
SUBSCRIBE TODAY!
E-Newsletters:
News on Mon/Thurs.
Test & QA Report
EclipseSource
SUBMIT
 
JOB BOARD
PDF & PRINT EDITION
* Requires Resource Account! 
LOGIN
or
SIGN UP
*
Download Current Issue!
ISSUE 8/15/2008 PDF
*
Need Back Issues?
DOWNLOAD HERE
Receive The Print Edition?
SUBSCRIBE HERE
 
EVENTS CALENDAR
Business of Software 2008
9/3/2008 to 9/4/2008
Boston
Red Gate Software
VSLive New York
9/7/2008 to 9/10/2008
New York City
1105 Media
Interop New York
9/15/2008 to 9/19/2008
New York
TechWeb
VMworld 2008
9/15/2008 to 9/18/2008
Las Vegas
VMware
Mobile Business Expo
9/16/2008 to 9/19/2008
New York City
TechWeb
REGISTER
MORE EVENTS
GET NOTIFIED!
About all of the latest Resources
SD TIMES 100
6th Annual SD Times 100
It's time once again to
recognize the organizations
or individuals that have
demonstrated leadership in
their markets.