A First Look at Visual J# for .NET

by Brian Jepson


Microsoft's JUMP to .NET
promises tools to migrate Java
programs to C# as well as support for the Java SDK class library.
When news of Visual J# reached my ears, I had to check it out (update: The Visual J# Beta 1 page is now live).
The first thing I tried was Hello, World:




public class Hello {
public static void main() {
System.out.println("Hello, World");
}
}



The compiler that comes with Visual J# is jc.exe, and it
compiled the program with no complaints:



C:\FirstLook>jc Hello.java
Microsoft (R) Visual J# Compiler Version 1.00.3327
for Microsoft (R) .NET CLR version 1.0.2914
Copyright (C) Microsoft Corp 2000-2001. All rights reserved.

C:\FirstLook>Hello.exe
Hello, World


Curious to see what's going on under the hood, I examined Hello.exe using
ildasm:



  C:\FirstLook>ildasm /text Hello.exe


[...]


.method public hidebysig static void  main() cil managed

{

  .entrypoint

  // Code size       21 (0x15)

  .maxstack  8

  IL_0000:  ldsfld     class [BJLIB]java.io.PrintStream [BJLIB]java.lang.System::'out'

  IL_0005:  ldstr      "Hello, World"

  IL_000a:  call       class [BJLIB]java.lang.String [BJLIB]java.lang.String::fromConstantPoolString(string)

  IL_000f:  callvirt   instance void [BJLIB]java.io.PrintStream::println(class [BJLIB]java.lang.String)

  IL_0014:  ret

} // end of method Hello::main


[...]




Well, there's some Java types in there, no doubt about that. A peek at
\Program Files\Microsoft Visual J# .NET\Framework\sdk\bjlib.dll
shows there is a whole lot of Java-compatibility going on:



Screen shot.

Figure 1. Some familiar package names.


I figured I'd try compiling one more program, so I grabbed the NervousText
applet from the Java distribution and added some scaffolding so I could
compile it into an executable. For good measure, I called into the .NET
Framework Class Libraries to determine the operating system version:



public static void main() {



  System.OperatingSystem os = System.Environment.get_OSVersion();

  String title = "Nervous Text - " + os.ToString();



  Frame f = new Frame(title);

  NervousText n = new NervousText();

  n.init();

  n.start();

  f.add(n);

  f.pack();

  f.show();

}




It worked - freaky! Although the .NET Framework Class Libraries are similar in some ways to Java, this seems like quite a feat to me. At the very least, it was probably a ton of work; writing hundreds of wrapper classes doesn't seem like the most exciting chore to me. Still, this is weird, a bit useful, and sure to stir up some healthy controversy. For some insight into the work that went into this, see this link. The Microsoft India site has more details.




Screen shot.

Figure 2. Jumpin' Java!


What do you think of Visual J# and its potential impact on luring more Java developers to the Windows OS. How might this affect the use and development of C# as well? Share your thoughts.