Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

How to avoid potential pitfalls of Microsoft's non-standard SDK for Java

Find out exactly which methods, classes, and variables have been added to, or omitted from, the key Java class libraries in Microsoft's implementation of Java 1.1

Microsoft's Internet Explorer (IE) 4.0 has been out for a little over a week now, and the company now is shipping the 2.0 version of its Software Development Kit (SDK) for Java. According to Microsoft's Win32 Virtual Machine for Java Release Notes (see the Resources section below for links to this document and other information related to this article), the virtual machine (VM) for Java that ships with IE 4.0 is the same as the one in the new SDK. Using the Java class files that come with the SDK and comparing them to the Java class files that come with Sun's Java Development Kit (JDK) 1.1.4 release reveals exactly why Alan Baratz, president of Sun's JavaSoft division, said, "Microsoft deceptively altered key classes and inserted them into their SDK." (This was during the conference detailing Sun's October 7 announcement of Sun's suit against Microsoft alleging breach of contract. For more information on this lawsuit, see "Sun-Microsoft dispute gets ugly," in the October 1997 issue of JavaWorld.)

I have analyzed the classes and have run across seven areas that should be of great concern to developers if they want to develop solutions with Microsoft's SDK for Java that will work in other Java 1.1 certified environments. These areas of concern are:

  1. new classes (Hey, what's that class doing there?)
  2. new methods (And where did these methods and instance variables come from?)
  3. new variables (And where did these methods and instance variables come from?)
  4. modified interfaces (What about the interface changes?)
  5. the com.ms packages (Inside com.ms)
  6. missing methods (What's missing in the SDK)
  7. behavioral differences (And what's different)
These go far beyond the often-cited concern over Microsoft's lack of JNI and RMI support, as mentioned in my October 1997 JavaWorld article, "What does Sun's lawsuit against Microsoft mean for Java developers?"

Baratz used the word "deceptively" in Sun's announcement of the lawsuit because the (javadoc) documentation for the Java classes that comes with the SDK makes no mention of these changes. To find these differences, it is necessary to use either the ClassVue tool that comes with the SDK or manually examine the source code. Your best bet is to rely on ClassVue, as the source files provided with the SDK are not always the ones used for the generated classes. For those unfamiliar with ClassVue, the equivalent tool that comes with the JDK from Sun is javap, a class file internals examiner.

As much as I'd like to claim that what follows is an exhaustive list of changes to the SDK, it is possible that something was missed. With several items, there is a pattern -- so if you avoid similarly named things you should be okay. All of the problems identified here are in the java.lang, java.io, java.awt, java.util, and java.security packages/sub-packages.

So, what changed in each package?

  • java.awt: New classes, New methods, New variables
  • java.lang: New methods, New variables
  • java.io: Dropped methods
  • java.security: Modified interfaces
  • java.util: New methods, New variables


Hey, what's that class doing there?

The first set of changes in Microsoft's SDK for Java is new classes, methods, and variables that were added to the system packages. A system package, or core Java API, is anything that begins with java.* in its fully qualified class name. So, as far as new classes go, 16 new ones were added into java.awt. These are:

Microsoft's new Java classes for AWT peers


WButtonPeer WCheckboxMenuItemPeer WCheckboxPeer WChoicePeer


WLabelPeer WListPeer WMenuBarPeer WMenuItemPeer


WMenuPeer WPopupMenuPeer WScrollbarPeer WScrollPanePeer


WTextAreaPeer WTextComponentPeer WTextFieldPeer WUIPeer


With the exception of the last one, all the classes are peer classes for AWT components, where a peer is the platform-specific representation of a graphical component like a button or menu. Normally, these classes would go into a different package like sun.awt.windows or sun.awt.motif. Since you aren't supposed to use them anyway, they should be easy to avoid. The WUIPeer class also is a peer, but it supports a Microsoft-specific behavior. Stay away from that too. Additional package-private (also called friendly, for when no access specifier keyword is specified) classes were added, like __AwtUIBand and __UIMenuRoot. Because these are inaccessible outside of java.awt, you cannot directly use them.

And where did these methods and instance variables come from?

The most commonly added method is called getBaseName(). Thankfully, it too is package-private, although it should be just plain private. Other changes, like making ClassLoader's loadClassInternal() method private, instead of package private, are due to implementation differences and should have no effect on developers.

I don't mean to downplay the package-private changes that Microsoft made, but unless developers are extending the key Java class libraries themselves, they cannot access these changes. Since developers seeking cross-platform solutions know better than to inject their own changes into the key Java class libraries, this isn't an issue. (See Rule 3 of SunTest's "100% Pure Java Cookbook," referenced in the Resources section.)

The real problems appear with the public methods that Microsoft introduced:



Public methods added into key Java libraries


Class New Method(s)


java.awt.EventQueue _postEvent (AWTEvent)


java.awt.Font getNativeData()


java.awt.image.ColorModel finalize() [was protected]


java.awt.image.DirectColorModel getToolkitData()


java.awt.image.IndexColorModel getOpaque()
getToolkitData()


java.awt.SystemColor getWin32Index()


java.lang.Class getInterface(String)
getMethods(int[])
getMethodFromSignature(String,String)
getDeclaredMethodFromSignature(String,String)


java.lang.Runtime getNativeServices()


java.lang.SecurityManager checkFileDialog()
checkMultimedia()
checkRegistry(int,String)
checkSystemStreams(int)


java.lang.VerifyError getAuditDetails()
getAuditIdentifier()
getClassName()
getMethodName()
getPC()
getViolationCode()
getViolationDescription()


java.lang.reflect.Method getDescriptor()
getParameterCount()


java.util.Locale Locale(String, String, String, int, int)
getCodePage()
getDefaultLocaleList()
getLCID() [was private]
getLocaleFromLCID(int)


java.util.ResourceBundle getMenu (String)
getMenuBar(String)




You will need to avoid all of the above methods, unless you want your Java programs to run only with Microsoft's environment. In addition to these new methods, you have access to three new instance variables and lots of new Locales for internationalization:



Instance variables incorporated into Java API


Class New Variable
java.awt.Font pData
java.awt.SystemColor appWorkspace
java.lang.reflect.Member PUBLIC_DECLARED
java.util.Locale
AFRIKAANS
ALBANIAN
AUSTRALIA
BASQUE
BELGIAN
BELGIAN_FRENCH
BRAZILIAN
BULGARIAN
BYELORUS
CATALAN
CROATIAN
CZECH
DANISH
DUTCH
ESTONIAN
FINNISH
GERMAN_AUSTRIAN
GERMAN_SWISS
GREEK
HEBREW
HUNGARIAN
ICELANDIC
INDONESIAN
IRELAND
JAPANESE_VERTICAL
KOREAN_VERTICAL
LATVIAN
LITHUANIAN
MEXICAN
NEWZEALAND
NORWEGIAN
NORWEGIAN_NYNORSK
POLISH
PORTUGESE
ROMANIAN
RUSSIAN
SERBIAN
SIMPLIFIED_CHINESE_VERTICAL
SINGAPORE
SLOVAKIAN
SLOVENIAN
SOUTH_AFRICA
SPANISH
SPANISH_MODERN
SWEDISH
SWISS
THAI
TRADITIONAL_CHINESE_VERTICAL
TURKISH
UKRANIAN




PUBLIC_DECLARED is brand new to Member, and appWorkspace is brand new to SystemColor, while pData was private and is now public. As with everything else, avoid them. As far as the Locale objects go, Microsoft's environment seems to understand a few additional languages, that JavaSoft doesn't. While the intention is good, instead of using the new constants, you should create a Locale object yourself, with the necessary parameters, although not using the new Locales may require some extra work when formatting messages.

For each Locale added, there are two public classes added into the java.text.resource package. Because Sun's documentation specifically states that you should not directly call any API in text.resource, I do not view these additions as a problem.

What about the interface changes?

An interface defines a partial template that a class must follow. Microsoft seems to have modified the templates of some of the security interfaces:





Additional methods in Java security interfaces


Interface New Methods
java.security.interfaces.DSAPrivateKey getAlgorithm()
getEncoded()
getFormat()
getParams()
java.security.interfaces.DSAPublicKey getAlgorithm()
getEncoded()
getFormat()
getParams()


The way interfaces work, when you create a class that implements an interface, you define a method for each method declared in the interface. By increasing the number of methods in the interfaces, Microsoft is breaking every class that implements each original interface. If you need to create programs to work in both Microsoft and non-Microsoft environments, it is necessary to always implement the additional behavior, whenever you implement either interface in a class.

Inside com.ms

com.ms is a grouping of classes delivered with Microsoft's proposed Java implementation. All the classes within com.ms.* packages normally are inaccessible to people using Netscape Navigator/Communicator and Java 1.1 environments. If you choose to use something from a class in a com.ms.* package, more than likely you are moving outside the realm of portability. One example in which this may prove tricky for the uninformed is getting FontMetrics from the Toolkit class (via getFontMetrics()). While the method signature is the same "public FontMetrics getFontMetrics()," what you get back is an instance of com.ms.awt.FontMetricsX. If you treat it as a FontMetricsX object, your program will work only with the Microsoft virtual machine for Java; if you stick with FontMetrics, then you're portable.

1 | 2 | 3 | 4 |  Next >
Resources
  • Sun Microsystems, Inc. v. Microsoft Corp. http://home.dti.net/bdpc/java.htm
  • "Sun-Microsoft dispute gets ugly," JavaWorld, October 1997 http://www.javaworld.com/jw-10-1997/jw-10-sunsuit.html
  • "What does Sun's lawsuit against Microsoft mean for Java developers?", JavaWorld, October 1997 http://www.javaworld.com/jw-10-1997/jw-10-lawsuit.html
  • Microsoft's Win32 Virtual Machine for Java Release Notes http://microsoft.com/java/sdk/20/relnotes/vm.htm
  • Rule 3 of SunTest's "100% Pure Java Cookbook" http://www.suntest.com/100percent/cpd/doc/cbook/cookbook.html#8592
  • Microsoft's Application Foundation Classes http://microsoft.com/java/sdk/20/relnotes/afc.htm
  • Internet Explorer 4.0 http://microsoft.com/ie/ie40/
  • Microsoft's SDK for Java http://microsoft.com/java/sdk/20/relnotes/intro.htm
  • Microsoft does provide RMI (along with other unsupported tools, utilities, and libraries) -- via an FTP server ftp://ftp.microsoft.com/developr/msdn/unsup-ed/rmi.zip
  • Borland's JBuilder http://www.borland.com/jbuilder/
  • IBM's VisualAge for Java http://www.software.ibm.com/ad/vajava/
  • Symantec's Visual Cafe http://www.symantec.com/domain/cafe/deved/index.html
  • Should Microsoft be allowed to alter the key class libraries of Java? Take our latest poll http://nigeria.wpi.com/cgi-bin/gwpoll/gwpoll/ballot.html
  • A review of platform-neutral Java development tools in NC World, JavaWorld's sister publication http://www.ncworldmag.com/ncw-10-1997/ncw-10-jvtools.html
  • Nick Petreley's commentary about the Sun/MS lawsuit, also in NC World http://www.ncworldmag.com/ncw-10-1997/ncw-10-straypackets.html
  • Alex Chaffee's analysis of Java implementation differences http://www.stinky.com/java/