A Visual J# .NET Primer
by Brian Jepson10/15/2001
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# (J-Sharp) reached my ears, I had to check it out.
Hello, World Example
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:
|
NervousText Applet Example
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.
|
No Applet Support in .NET
One of the tools that comes with Visual J# is jbimp, the Java Binary to .NET Assembly Converter. It turns Java bytecode into MSIL (Microsoft Intermediate Language). Sounds like an innocent tool to help Visual J++ developers expose their .jars and .classes to .NET applications.
|
|
As of this writing, .NET doesn't support applets: I can't develop a .NET application and run it in my browser. But I am sure that such a thing will come to pass. A .NET applet would look more like an ActiveX control than a Java applet, since there is no VM per se (IL is JIT-compiled to native code and enjoys extensive runtime support from .NET).
Consider this:
- J# only supports JDK 1.1.4. This may seem like a major shortcoming, but see #2 and #3.
- Microsoft is already shipping versions of Windows without a Java VM. If you want to, you can install Microsoft's VM into IE. That Java VM is also limited to JDK 1.1.4 (the plot thickens).
- When someone writes a Java applet for general consumption, they want it to run on Internet Explorer and Netscape. Per #2, that applet is going to be targeted to JDK 1.1.4, since that is the latest Java version that supports both browsers!
So why does Microsoft need a Java VM for Internet Explorer anymore? They
can just add .NET runtime support to IE, and incorporate jbimp into IE. When IE downloads an applet, it can convert it to MSIL, pre-JIT it into native
code, and then cache it. There will be a penalty the first time an applet is ever loaded on a computer, but subsequent visits to the same applet will be very fast, even if those visits occur between reboots.
Again, for more Visual J# .NET, visit JUMP to .NETsite.
Brian Jepson is an O'Reilly editor, programmer, and co-author of Mac OS X Panther for Unix Geeks and Learning Unix for Mac OS X Panther. He's also a volunteer system administrator and all-around geek for AS220, a non-profit arts center in Providence, Rhode Island. AS220 gives Rhode Island artists uncensored and unjuried forums for their work. These forums include galleries, performance space, and publications. Brian sees to it that technology, especially free software, supports that mission. You can follow Brian's blog here.
Return to the .NET DevCenter.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 8 of 8.
-
oh no ;=)
2001-10-16 07:42:26 joepeer [Reply | View]
it seems to me like J# is exactly that kind of mess that i left behind me a few years ago, when i switched over to Java. cheez! what a piece of grap! and what if M$ decides to drop J# support, phew! come on -- back to that hell again!?
certainly no! :=))
joe
-
you're kidding!
2001-10-16 07:04:18 tjansto [Reply | View]
just goes to show that a vb programmer can be easily impressed. this review certainly doesn't measure up to the standards i have come to expect from your company. j#.not is silly, and no java programmer, who makes their living writing enterprise solutions on java would even consider this as java. i am glad they didn't refer to java in the name of the product, as it is not java, either in form or intent. "syntax does not a platform make", to paraphrase. -
you're kidding!
2001-10-16 10:37:06 Steve Anglin |
[Reply | View]
As the editor of ONJava.com, it's my obligation to at least point out Java features as well as Java derivatives, Java alternatives, etc. While J# is not even close to a viable option for writing enterprise applications, it's still out there for Java programmers who want to build 'simple' Java applications for Windows. -
you're kidding!
2001-10-17 05:13:55 tjansto [Reply | View]
i agree, and i apologize for the apparent sharpness of my response. but if that is the intent of the review, shouldn't the at be pointed out? as i said, o'reilly is a well respected source of information, but by not calling out that it is not viable for enterprise, (and i'm sure you and i are in disagreement about the legitimacy of it being used for 'simple' apps), folk may be encouraged to try to make it do things it can't because it doesn't adhere to the java platform, it reduces java to merely a language.
again, i apologize, i typed quicker than i should have. -
Enterprise or Not? (was you're kidding!)
2001-10-17 07:33:37 Brian Jepson |
[Reply | View]
I'm sorry that the article didn't go deeper, but it's just a first look at Visual J#. I pointed out that J# only supports JDK 1.1.4, and this should imply that J# is no replacement for Java 2.
As for whether it's ready for the enterprise, that's the question of the hour. Is .NET itself ready for the enterprise? I think the answer is yes, but lots of people disagree. We really won't know until the final version is released, and people start talking about their experiences building enterprise apps on .NET.
As for J# reducing Java to a language, I partially disagree. There are three key components to the Java platform: the JVM, the SDK, and the Java language. J# supports the language (albeit a mutated version of it) and an obsolete version of the SDK. And of course, it does not support the JVM. The net result is that J# itself is no replacement for Java 2.
But I think Microsoft's initial goal with J# is to support Visual J++ users, and nothing more than that. However, I think that Microsoft will take J# beyond that. Now that they have a clean-room implementation of Java 1.1.4 to start with, can Java 2 language and SDK compatibility be far off? There is nothing to stop them if they proceed in a clean-room fashion.
- Brian -
Enterprise or Not? (was you're kidding!)
2001-10-17 08:15:18 cfrye [Reply | View]
I agree with your "question of the hour". The point is not whether J# is Java 2 or not. The point is - is J# a viable entry point into the .NET platform for people who prefer a Java-like syntax.
If we want to compare anything with Java 2, we should compare Java 2 to .NET as a whole (more precisely the ".NET Framework").
P.S. Even as a self-described J2EE bigot, I am having difficulty maintaining that position in light of some initial experimentation I am doing with the .NET Framework. I am having a lot of trouble finding fault with the .NET Framework conceptually.









Back to the argument, any skilled Java developer who was wooed to .NET would code in C#. That's where most of MS's focus is going to be and it's so much like Java, one can't help being amazed at how obvious MS were with the similarities. I think to suggest that a skilled Java developer would be wooed by J# at all is silly. While the language might be similar, the architecture that you will work with is completely different.
I don't know what frustrates me more. These aseptic analyses of J#, or the fact that Sun does absolutely NOTHING to counter any of the misinformation that is being spread about Java. You have MS claiming that Web Services were their thing. .NET is everywhere... on the cover of Time magazine, every bleeding web site you look at can't seem to say enough about .NET and we're not even past beta with this yet. And all the while, stupid McNealy and his cronies sit and waste time pushing their overpriced hardware, throwing tantrums to try and get Java into XP, just basically being the spoilt little brats they've shown themselves to be. If they had any savvy, they'd be out there getting Java TECHNOLOGY (i.e. not just a language) into the publics face, touting its benefits, and pretending like .NET doesn't even exist. MS are successfully getting people to see Java as just a language, and Sun have themselves to blame for it. MS are just being what they're meant to be... a competitor, but they clearly outclass their adversaries.
"I'm as mad as hell and I'm NOT going to take it anymore!"
Oh well, back to my development in a fading technology. I already have the .NET evaluation CD's on my desk. Just trying to pluck up the courage to install them. It's only a matter of time. Thanks for nothing Scott.