Follow these steps to upgrade Visual J++ 1.1 to support most JDK 1.1 features I don’t know how many times I’ve heard this story: You just finished writing your first inner class in Visual J++ 1.1 and it won’t build. Frustrated, you repeatedly check the syntax, looking for the error in your code that is keeping your class from building. Eventually, you discover that the problem isn’t your class, but Visual J++ itself. It’s actually based on the 1.0.2 version of JDK and doesn’t support new JDK 1.1 features! Putting credit where it’s due, Visual J++ 1.1 is a powerful development environment, albeit with an unfortunate choice of version number.Visual J++ has, by many accounts, taken the Java market by storm. Visual Basic or Visual C++ developers looking to find out what all the fuss over Java is about find the Developer Studio-based environment familiar and friendlier than JavaSoft’s command-line counterpart, the JDK. This article includes a brief demonstration of a few of the features of JDK 1.1 that make it a “must have,” and then presents a step-by-step approach to upgrading Visual J++ to support JDK 1.1 features.New features in JDK 1.1If you’re an enterprise Java developer, JDK 1.1 will make you salivate. It supports amazing features like remote method invocation (RMI) for calling methods of Java objects residing elsewhere on the network and Java database connectivity (JDBC) for accessing databases with SQL in a consistent way. An examination of features like these is far beyond the scope of this article. (See the resources section for the complete list of updates.)The GUI developer will also find JDK 1.1 tantalizing. For this article, I chose four features of JDK 1.1 to demonstrate. They include resource bundles, inner classes, the new event model, and serialization. Java11DemoClass (comprised of Java11DemoClass.java, ClosingListener.java, and ResourceStrings_en_US.java) is an applet wrapped so it can also be run as an application. When executed, a window comes up with three Buttons and a TextArea.Resource bundlesLet’s start by discussing resource bundles. Most Java examples use hard-coded Strings to define the text to appear in GUI components. Let’s say that we want to produce an applet that supports both French and English. To do this in JDK 1.0, you’d need to determine the locale of the applet and choose the appropriate string to display.In JDK 1.1, this functionality has been standardized and incorporated into core Java. Instead of hard-coding the text to appear in the buttons and TextArea, I implemented a class named ResourceStrings_en_US that extends ListResourceBundle, a Java 1.1 core class. This class is basically a lookup table of strings and objects. In the init() method of the applet, the locale where the applet is running is discovered, then a call to ResourceBundle.getBundle loads the appropriate ResourceStrings class with a matching locale suffix. The ResourceBundle‘s getString method looks up the correct localized string to display in the applet for each button. In the case of the TextArea, the ResourceBundle‘s getObject method looks up the proper object to display. The TextArea could easily be replaced with another GUI object in another locale by modifying the appropriate ResourceStrings class. Delegation-based event modelThe AWT classes change in 1.1 to a delegation-based event model. In 1.0, events could be handled only by subclasses of Component or Container. In the single inheritance world of Java, that’s an expensive restriction. In 1.1, we can register listener objects that are notified when an event of interest to them is generated. If you’re developing user interfaces with the 1.0 AWT and move to 1.1, you’ll find that many parts of the old event model are deprecated and JavaSoft will be phasing them out.Inner classesJDK 1.0 allowed classes to be defined only in the scope of a package. You can now define classes in other scopes. Inner classes are a handy feature for defining listeners. This example shows how classes now can be defined in the scope of another class and access its members. Without inner classes, a separate class would have to obtain access to all the members of the parent class that it needed.To demonstrate the new event model, listeners are registered for each of the buttons. To be notified of button events, an object must implement the ActionListener interface and be registered with addActionListener. In this example, the SimpleListener and SerializeListener are defined as inner classes. A single SimpleListener object is registered for both the “Push Me First!” and “No, Push Me!” buttons and its actionPerformed method is called when either is clicked. SerializationThe last feature to demonstrate is serialization or object persistence. In JDK 1.0, you’d have to write your own code to write your object to a stream and read it back in. In JDK 1.1, this functionality has been standardized and implemented as core Java. To serialize a class, you implement the Serializable interface and mark those data members transient that you don’t want saved.After we get the souped up Visual J++ development environment built, we’ll test it out with this application.IngredientsHere’s a list of what we’ll need and where you can find it. What we’ll needWhere to find it Visual J++ 1.1 CDWherever Microsoft developer products are sold Visual Studio Service Pack 3Order a CD or download at https://www.microsoft.com/vstudio/sp/ Internet Explorer 4.01Order a CD or download at https://www.microsoft.com/ie or Internet Explorer 3.02 with the Authenticode Updatehttps://www.microsoft.com/ie/security/authent2.htm SDK for Java 2.01https://www.microsoft.com/java/download/dl_sdk2x.htm Virtual Machine for Java (not needed by IE 4.01 users)https://www.microsoft.com/java/download/dl_sdk2x.htm SDK for Java Documentation (optional)https://www.microsoft.com/java/download/dl_sdk2x.htm Java Base Package Documentation (optional)https://www.microsoft.com/java/download/dl_sdk2x.htm rmi.zip RMI class file (optional)ftp://ftp.microsoft.com/developr/msdn/unsup-ed/rmi.zip JDK 1.1.5 (optional)https://www.javasoft.com/products/jdk/1.1/ Personal Web Server, part of the Windows NT Option Pack (optional)Order a CD or download at https://backoffice.microsoft.com/downtrial/optionpack.asp JRun 2.0.1 (optional)https://www.livesoftware.com/products/commercial/jrun/ JRunDebugger 1.0 (optional, 49)https://www.livesoftware.com/products/commercial/jrundebugger/ Let’s cookNow that you’ve taken a look at the list of ingredients, let’s get cooking!Step 1: Clean up your environmentThe ideal way to install a Visual J++ 1.1 development environment is on a clean machine. Failing that, uninstall any prior versions of Visual J++ or other Java development environments. Remove anything that looks Java specific from your PATH and remove the CLASSPATH environment variable from autoexec.bat. Reboot. The installation programs used in this article are very sensitive to a lack of disk space, so try to free a few hundred megabytes if you can.I also suggest that you back up your machine so that if anything goes wrong, you can get back to this state and try again. Step 2: Install Visual J++ 1.1This is the easy part! Follow the installation directions and note any warnings you may receive. They may be important while researching problems that occur later on.Step 3: Install Visual Studio Service Pack 3This service pack fixes various bugs in the Visual J++ IDE and other Visual Studio applications. The service pack is necessary for debugging while using Internet Explorer 4.0. Remember, service packs are cumulative, so installing the latest service pack brings you completely up to date. If you were a Visual C++ user in a previous life, you probably think that at this point you’re done and everything’s current (good service pack) or your development environment’s trashed (bad service pack). Actually, a lot of problems are fixed by this step, but we’re still not to JDK 1.1.Step 4: Install Internet Explorer 4.01 or Internet Explorer 3.02 with the Authenticode UpdateIn an upcoming step, we’ll be installing the Java SDK 2.01. It requires one of the browsers listed above. If you currently are running Internet Explorer 3.0 or 3.01, you can download the update from the URL listed in the “What We’ll Need” section.(For me, Internet Explorer 4.01 was a compelling upgrade and I chose to go that way instead. Some of my favorite features are FrontPage Express for simple Web page construction and editing, Outlook Express for Internet news and mail reading, the Active Desktop paradigm of a single explorer for browsing documents and the Internet and placing active content from Web pages on your desktop, Chat, NetMeeting, and Web Publishing Wizard. It also includes the latest version of the Java Virtual Machine that executes Java applets, which also is available in the Java SDK 2.0.)Before installing Internet Explorer 4.01, make sure that your operating system is fully updated with all the necessary Service Packs and updates. To apply them later, you may need to uninstall Internet Explorer first and reinstall it when complete. See Microsoft Knowledge base article Q174265 for details. While installing Internet Explorer 4.01, you need to consider whether you want to use Active Desktop or not. This optional component of Internet Explorer 4.01 changes how things look and work on your desktop, and many users will quickly turn it off when they see pie charts in their Explorer windows, a black desktop with a “remote control” for the Internet, and new icons and menus in the task bar. If you do decide to use Active Desktop, you’ll also need to remember to make the following changes in every project you plan to debug in Visual J++: From the Project menu, choose settings.Select the debug tab.In the Category box, select Browser.Add the -new switch to the path to the browser. For example: c:Program FilesInternet ExplorerIexplore.exe -newUsers of Exchange Client for access to corporate MS Mail or Exchange servers should go ahead and install Outlook Express anyway. When it is executed for the first time, don’t enable it as the default mail program and don’t configure any mail features. The program contains Internet newsreading functionality, so it’s worthwhile to have. To enable mailto links in Internet Explorer to pop up a mail program other than Outlook Express, you need to read the Microsoft Knowledge Base article Q154359.Step 5: Install Microsoft SDK for Java 2.01You bought Visual J++ to get everything you’d need to work with Java, right? So why do we need another Java product from Microsoft? Microsoft explains the difference in the Visual J++ support FAQ by saying “Visual J++ is a full-featured development tool. The SDK is a set of freely available resources for Java developers that will work with any Java development tool, including Visual J++.” To put it simply, Java SDK is Microsoft’s answer to JavaSoft’s JDK. Java SDK includes a virtual machine, command line tools, base Java and Microsoft classes, and HTML documentation.The Java SDK can be used to update Visual J++ 1.1 since it provides newer versions of the compiler, virtual machine, and classes that Visual J++ uses behind the scenes. Installation notes for the Microsoft SDK for Java Version 2.01 are below. My instructions leave out some of the Microsoft-specific enhancements like DirectX, DirectAnimation, and J/Direct, and you are free to leave them out of your installation if you don’t need them.Microsoft SDK for Java, Version 2.01 Install this file first. Make sure you let the installer place the SDK in the directory it chooses! The SDK includes many development tools like the latest version of Microsoft’s Java compiler (jvc) that supports JDK 1.1., the debugging version of the classes, and examples.Microsoft Virtual Machine for Java (not needed by IE 4.01 users) Users of Internet Explorer 3.02 with the Authenticode update or pre-release versions of Internet Explorer 4.0 should install this file second. The virtual machine is identical to that found in Internet Explorer 4.01, AFC, DirectX3 for Java, MSJDBC, and XML; Win32 API classes will be installed by default.SDK for Java documentation (optional) A complete set of HTML files describing the Microsoft SDK 2.01 libraries and components.Java Base Package Documentation (optional) A complete set of HTML files describing the base java.* packages.Step 6: Enable J++ to use the Java SDKJust installing the Java SDK does not automatically enable its functionality in Visual J++ 1.1. Yes, a few tweaks are needed:Copy JVC.EXE, JPS.DLL, and MSJVC.DLL from the BIN directory of the SDK installation to the SharedIDEBIN directory of the Visual J++ 1.1 installation. Step 7: Debug classes.zip installationMicrosoft’s installation notes for the Java SDK describe two versions of the system classes, one called “retail” and one called “developer” that includes debugging information and source code.Before installing the developer version, make sure you have about 60 megabytes of free disk space. Otherwise, the install may fail without reporting any errors.To install, run classd.exe from the SDK bin directory. A new classes.zip file is installed in the WindowsJavaclasses directory, the machine reboots, then the classes are installed into the Java Package Manager used by the virtual machine. To test the installation, run Visual J++ and open the simple.java in the Java SDK’s SamplesJDirectSimple folder. Check to make sure the case of the filename matches that of the class within. Select “Rebuild All” and answer “Yes” when asked if you would like to create a default workspace. Next, select “Execute Program.” When prompted for the name of the class to execute, type the class name and choose “Stand-alone interpreter” for the run-time environment. If everything has been set up properly, a Windows messagebox will appear.Step 8: Extract the debugging sourceIn order to use a Java debugger on the system classes, you will need to extract the debugging source. Bring up a DOS shell and execute the command javasrc classes.zip in the WindowsJavaclasses directory. This creates a directory tree in the directory where classes.zip resides that contains the source files for the Java class libraries.Step 9: Set up for RMI development and execution (optional)Internet Explorer 4.01 and the Java SDK do not ship with the Java remote method invocation (RMI) classes. This is apparently one of the reasons for the recent Sun litigation. If you plan to execute classes that use RMI, you will need to place the rmi.zip file in your WindowsJavaClasses directory. There is no debuggable source included, so there is nothing to extract.Step 10: Check the CLASSPATHThe CLASSPATH is used to search for the Java classes and debugging source files at execution time.Visual J++ and the Virtual Machine look for the CLASSPATH value in several places depending on where the application was launched.Normally, the CLASSPATH registry value for the key HKEY_LOCAL_MACHINESOFTWAREMicrosoftJava VMClasspath is checked. If an application has been executed from a DOS shell, the CLASSPATH environment variable also is used. Finally, if an application has been executed from Visual J++, directories specified in the Options dialog also are used. It is important to verify the settings of the CLASSPATH in these three places to prevent unexpected behavior. My registry setting currently reads C:WINDOWSjavaclassesclasses.zip;C:WINDOWSjavaclassesrmi.zip;C:WINDOWSjavaclasses;. Some third-party development tools may need the CLASSPATH set for proper execution from DOS shells. In order to set the proper CLASSPATH for DOS shells, you can add a line to autoexec.bat that reads SET CLASSPATH=C:WINDOWSjavaclassesclasses.zip;C:WINDOWSjavaclassesrmi.zip;C:WINDOWSjavaclasses;. To check the Visual J++ setting, select Options from the Tools menu, click the Directories tab, and in the Show Directories For drop-down list, select the class files option.Unless you know what you’re doing, you shouldn’t have any other entries in your CLASSPATH.Step 11: Set up special project settingsWe already mentioned the change to the project settings necessary for Active Desktop users. There are a couple of other changes that are helpful for those trying to create Pure Java programs.There is an option to jvc, the Microsoft Java compiler, to get it to treat extended keywords as simple identifiers and to disable other Microsoft extensions.This option can be set on a per-project basis by selecting Settings from the Project menu, going to the Java tab, selecting the project from the Settings For treeview, and adding /x to the Project Options text item. This procedure should be repeated for each configuration in the Settings For combo box (debug, release, etc.).While you’re modifying project settings you may want to turn up the Warning Level to Level 4 in the same dialog for stricter checking of your Java code.Step 12: Install JavaSoft’s JDK 1.1.5 (optional)JavaSoft’s JDK and Microsoft’s Java products are based on different sources and have different paths to their executables. Sad, but the concept of write-once run anywhere has been tarnished by the lack of bug-for-bug compatibility between the environments. I like to have the JDK installed so that I can use some of its tools that aren’t in Microsoft’s Java SDK and so that I can test my code in another popular environment.If you plan to develop enterprise applications with RMI, you will quickly find that you need DOS shell access to rmic, the RMI compiler included with JDK 1.1 but not included with Microsoft’s Java products.If you want to set up a complicated custom build in Visual J++ that uses rmic, you could probably add the JDK bin directory to your path and look at the Visual J++ help topic “About Using Custom Build Tools” to correctly build the _Skel.class and _Stub.class files. For my simple needs, I’ve been satisfied running rmic from the DOS shell command line.To get set up, install JDK 1.1.5, then set up a DOS batch file to set the PATH and CLASSPATH environment variables to the proper values for the environment you want to be working in. My batch file, javapath.bat, is supplied below.ECHO OFF REM File: JavaPath.bat REM Description: A batch file for setting the PATH and CLASSPATH REM variables for JDK 1.1.5 or Visual J++ and the Java SDK 2.0 REM Author: Cliff Morrison REM Date: 12/11/97 REM If you have a long path statement set up, you may get a message that REM says you're out of environment space. If so, add or modify a line REM in config.sys that reads: REM "SHELL=COMMAND.COM /E:1024 /P" REM increase the number following E until you have enough space SET PATHPREFIX=C:WINDOWS;C:WINDOWSCOMMAND;C:WINDOWSSYSTEM;C:PROGRAM FILESACCESSORIES; SET PATHSUFFIX=C:BIN;. REM Test for an argument for silent operation IF "%1"=="JDK" GOTO a IF "%1"=="jdk" GOTO a IF "%1"=="J++" GOTO b IF "%1"=="j++" GOTO b ECHO Would you like to set the PATH and CLASSPATH for ECHO (A) JDK 1.1.5 ECHO (B) Visual J++ 1.1 and the Java SDK 2.0 ECHO (C) Quit CHOICE /C:abc IF ERRORLEVEL 3 GOTO end IF ERRORLEVEL 2 GOTO b IF ERRORLEVEL 1 GOTO a :a PATH "%PATHPREFIX%C:PROGRAM FILESJDK1.1.5BIN;%PATHSUFFIX%" SET CLASSPATH=.;C:PROGRAM FILESJDK1.1.5classes;C:PROGRAM FILESJDK1.1.5LIBCLASSES.ZIP GOTO end :b PATH "%PATHPREFIX%C:PROGRAM FILESDEVSTUDIOSHAREDIDEBIN;C:SDK-JAVA.20BIN;%PATHSUFFIX%" SET CLASSPATH=.;C:WINDOWSJAVACLASSESCLASSES.ZIP;C:WINDOWSJAVACLASSESRMI.ZIP GOTO end :end SET PATHPREFIX= SET PATHSUFFIX= echo PATH: %PATH% echo CLASSPATH: %CLASSPATH% I put a line that reads javapath.bat j++ in my autoexec.bat to set up Visual J++ as my default environment. Then, when I want to use the JDK, I pop up a DOS shell and enter the command javapath jdk. Now I can pop between both environments at will.Step 13: Test your completed installationWith the installation completed, you should be able to build Java programs in Visual J++ and step into Java source code for system class methods. Now is a good time to take the example files from this article and build an application. To do this, create a workspace with the ClosingListener.java, Java11DemoClass.java, and ResourceStrings_en_US.java files. You will want to execute the Java11DemoClass. You should be able to build the project without errors. When you execute (as an application) and press the three buttons in clockwise order from the top left, you’ll see some output following the locale message.Step 14: Install Java servlet support (optional)Java Servlets are Java applications that run on the Web server. They’re the next step beyond CGI, allowing you to use object-oriented logic instead of C or scripting languages. Servlets stay in memory through multiple invocations and can maintain state. For a more thorough examination of servlets, see the resources section.In order for a server to execute a servlet, a Java virtual machine must be running on the Web server and the server must support the JavaSoft servlet API. Since we’re building a test environment, I chose to use Microsoft’s Personal Web Server for Windows 95 from the freeware Windows NT Option Pack. When installation was complete, I entered the Web URL formed from my TCP/IP address (http://xxx.xx.xx.xxx) to verify that it was installed properly. You can edit the default home page or build your own using FrontPage Express (included with the full version of Internet Explorer 4.0) or using Microsoft Word 97 with Web Page Authoring.Next, to add support for the servlet API, I installed Live Software’s JRun 2.0.1. Live Software makes this freeware add-on for ISAPI or NSAPI Web servers like Personal Web Server, IIS, WebSite Pro 2.1, and x86 Netscape Enterprise and FastTrack. It includes JavaSoft’s Java Runtime Environment 1.1.4, another reason to test your logic in both the Microsoft and JavaSoft virtual machines. Live Software makes JRun freely available in order to promote and facilitate their commercial servlets.With that complete, you have a Web server that runs servlets! Now what if you want to debug a servlet locally within Visual J++. Live Software offers a 49 product called JRunDebugger that mimics a servlet-enabled Web Server. To debug a servlet, you code a debugging stub Java application that invokes a JRunDebugger instance. The instance in turn executes the servlet code within the development environment.Concluding thoughtsIf at this point you’ve followed all the steps listed above, you have a working Java development environment and you learned a lot about Java and Visual J++ on the way. Some of what you learned was good, and some probably left you a little confounded. I think we can all agree that the overlap between Internet Explorer, Visual J++, and the Java SDK is confusing and that Microsoft should automate and integrate the installation and update process. Perhaps the competition between Microsoft and Sun will challenge Microsoft to build such a configuration. Or perhaps Visual J++ owners can encourage some improvement. Let Microsoft know what you liked or didn’t like about the update process and how they could improve it for you. You can send product suggestions to Microsoft by visiting https://register.microsoft.com/regwiz/regwiz.asp and clicking on the “Send a product suggestion to Microsoft Wish” link. Here’s hoping we won’t need another such article when Visual J++ 2.0 comes out…. Development ToolsTechnology IndustrySoftware DevelopmentJava