HOWTO: Sending Text to the Visual J++ Output Window

ID: Q195175


The information in this article applies to:


SUMMARY

There are several ways to send debug text strings to the Visual J++ Output window for diagnosing runtime problems. These methods will work only when you launch your application from the Visual J++ environment. Applications launched standalone will not be able to access the Output window.


MORE INFORMATION

The first way to send text strings to the Visual J++ Output window is by using the print and println methods of the com.ms.debug.Debugger.out package. When you call these methods from a Java application that is spawned from JVIEW or WJVIEW in either debug or release builds, the text string will appear in the Visual J++ Output window.

Here is a simple sample that demonstrates using the println method:


public class Class1 {
   public static void main (String[] args) {
      com.ms.debug.Debugger.out.println("Hello World");
   }
} 
When this class is built and run from within Visual J++, you will see the string "Hello World" appear in the Visual J++ Output window. Notice that the string is output whether you build your application in Debug or Retail mode.

Another way to send text strings to the Visual J++ Output window is by using the Windows Foundation Classes (WFC) methods in the com.ms.wfc.util.Debug package. This package is different from the com.ms.debug.Debugger package in that the methods are conditionally compiled so that they exist only in Debug builds of your application. When you build your application for Retail release, the calls to output diagnostic strings through the WFC Debug package will not be compiled into your code, saving size and possibly execution speed.

Here is a WFC button click message handler that will output a text string to the Visual J++ Output window:

private void button1_click(Object source, Event e) {
   com.ms.wfc.util.Debug.println("Hello World");
} 
Notice that if you build your form in Debug mode (selectable in the Project Properties dialog box), the text string will appear in the Visual J++ Output window when you click button1. If you then build your application in Retail mode and execute from Visual J++, the text will no longer appear in the Output window. In fact, the method call will no longer exist in your code.

One thing to be aware of with the com.ms.wfc.util.Debug package is that it will pass output only to the Visual J++ Output window if you are executing under WJVIEW, as is done in most WFC Project templates. If you are executing your application with JVIEW--either by using the Console Application project template or by selecting the Launch as a Console Application check box in the Project Properties Launch tab, your output will go to the MS-DOS CONSOLE window by default. For additional information, please see the following article in the Microsoft Knowledge Base:
Q194187 Redirecting WFC Debug Output to the VJ6 Output Window
This article demonstrates how to redirect this output from the Console window to the Visual J++ Output window so that you can utilize the benefits of Conditional Compilation in your Java Console applications as well.

One further point is that all Console output from an application run under WJVIEW is rerouted to the Visual J++ Output window. This means that for applications that are run from the Visual J++ IDE and use WJVIEW to launch the Virtual Machine, System.out.println() method calls will also appear in the Visual J++ Output window for both Retail and Debug builds.

The following two tables show where output for the calls discussed in this article will appear, depending upon whether they are run under JVIEW or WJVIEW, and whether they are built in DEBUG or RETAIL modes.

Java Method Call WJVIEW Retail Build WJVIEW Debug Build
System.out.println VJ Output Window VJ Output Window
com.ms.debug.Debugger.out.println VJ Output Window VJ Output Window
com.ms.wfc.util.Debug.println no Output VJ Output Window

Java Method Call JView Retail Build JView Debug Build
System.out.println MS-DOS Console MS-DOS Console
com.ms.debug.Debugger.out.println VJ Output Window VJ Output Window
com.ms.wfc.util.Debug.println no Output MS-DOS Console


© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Steve Horne, Microsoft Corporation

Additional query words:


Keywords          : kbVJ600 kbSDKJava310 kbSDKJava320 
Version           : WINDOWS:3.1,6.0
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: July 9, 1999