3.2 The J language


3.2 The J# language

Announced only late in 2001, J# is the official successor of Visual J++. Like J++, J# follows Java's syntax and rules. But unlike Java, applications written using J# can run only on the CLR, and not on a JVM. A J# compiler does not compile .java source files to .class byte codes.

Being a true blue .NET language as well, J# is like C# in many ways:

  • Like C#, J# source codes are compiled into IL assemblies, which are then JIT-compiled into native Windows machine codes by the CLR during runtime.

  • J# codes can consume .NET BCLs (instead of Java's core API classes).

  • Being a .NET language, you can integrate .NET functionality such as ADO .NET, web services, Windows forms, and ASP .NET into a J# module.

  • J# interoperates with other .NET languages -for example, your J# class can inherit from another class written in C# and vice versa.

Visual J#.NET includes Jbimp.exe . Jbimp is a tool which can convert prewritten Java .class byte codes into IL assemblies directly.

If you have a Javabean in the form of a .class file which you wish to convert into C# codes, you can do either of the following:

  • use the Jbimp tool to convert the .class file into a .NET assembly;

  • use a Java decompiler to convert the .class file back into a .java file, then use JLCA to convert the .java source codes into C# source codes.

One huge caveat “ the use of Jbimp is limited to only JDK 1.1.4 (or earlier) Java byte codes, such as those created using J++'s jvc.exe tool.

For J++ developers, there is a migration path for porting a J++ program into J#. Most J++ applications can be ported over quite easily. J# supports legacy J++ features such as J/Direct, Java COM integration, delegates, conditional compilation, and some of the J++ @ directives. [5]

[5] If you are a pure Java developer who has never touched J++ before, you will be scratching your head over these J++ features. J/Direct is an API provided by Microsoft which allows Java code to call Windows operating system services and methods in third party COM components. Unlike JNI, J/Direct does not require a wrapper to bridge the communication between Java and native DLLs. J/Direct was first supported with the Microsoft Virtual Machine that shipped with Microsoft Internet Explorer 4.0. There are other Microsoft technologies to enable communication between Java codes and COM components such as using a CCW for Java objects in COM, and JCW, for COM objects in Java. For more information, see www.microsoft.com/java/resource/jdirectworkshop.htm

J# has a big limitation “ it supports only Java 1.1.4 API classes. This means that if you have a Java source that uses Swing (or any other post-1.1.4 API class), you cannot simply open that .java file in VS .NET and compile it as a J# source file into IL codes directly. It is for this reason that it is extremely difficult to port pure Java applications which make use of any classes after JDK 1.1.4. [6] For .java files which make use of only 1.1.4 and earlier core Java classes, porting is as simple as opening that file in VS .NET and compiling it as a J# source.

[6] Java 1.1.4 is ancient by any standard (it is not even Java 2!). Visual J++ 6.0 was also 'stuck' at this stage and stopped evolving due to the court case between Sun and Microsoft. I was quite disappointed with this limitation.

Compared to C#, Java “ and hence J# “ has a poorer language feature set. For example, J# lacks features such as operator overloading and support for C# properties, events, and delegates. Otherwise, both C# and J# can utilize .NET BCL, and you can write programs in either language with the same functionalities provided by the BCL.

3.2.1 Why learn C# instead of J#?

If you discount project requirements and specific client instructions, choosing to pick up either C# or J# for developers with a Java foundation is probably a personal choice.

If you are a pure (non-J++) Java programmer, I would recommend that you spend a little more time picking up C# instead of J#, even if you have never programmed in C/C++ before. For such cases, I estimate that the learning time needed to pick up C# will be a just little longer than learning J#. Personally, I think the additional language features provided by C# is worth that extra learning time.

On the other hand, if you are (or have been) a J++ developer, then the migration path from J++ to J# would be significantly shorter. I would still recommend C# as a more powerful language than J# if you are really serious about .NET. [7]

[7] I suppose many people will disagree with this recommendation. But, as I have mentioned, it's more a personal preference. What I am attempting to do here is point out the trade-offs of learning C# and J# so that an informed decision can be made.

The advantages of C# over J# are listed below.

  • C# boasts a richer set of language features. [8]

    [8] Note that both J# and C# (and any other .NET language) has access to the same set of .NET BCLs. This implies that what you can do with .NET languages is quite uniform (if you are writing safe codes; you cannot write unsafe codes with J#). However C# has more language features that make programming easier, more efficient, and more elegant.

  • C# is not the only language for .NET, but it has been widely regarded as the de facto language.

  • C# will be more widely used than J# for programming on .NET. As such, I am expecting C# developers to have easier access to technical support, more discussion forums, and definitely more published literature.

  • C# is regulated by a standards body but J# is not (yet). [9]

    [9] There has not been any official announcement from Microsoft as to whether J# will be submitted to ECMA for standardization. VB .NET isn't, and probably will not be.

  • You can write unsafe codes with C# but not with J#. [10]

    [10] This may be a minor point depending on whether your project requires you to write unsafe codes. Most application project teams will never use this feature (even as a C# developer, you should not use unsafe codes unless absolutely necessary).

  • The learning effort needed for a Java programmer to learn C# may not be very much more significant than that needed to learn J# ( especially since you have this book).

The advantages of J# over C# are fewer.

  • As a Java developer, learning J# is the fastest way to pick up a .NET programming language. J# uses Java syntax and grammar rules which you should already be familiar with.

  • Being a fully fledged .NET language, J# code uses the same .NET BCL and hence it is fair to say that a J# program can do almost anything a C# program can, except for special features such as writing unsafe codes. By choosing J# over C#, your program should be able to achieve the same functionality set.

One of the first things a developer starting on .NET has to do is to pick one .NET language from the many available. Assuming no other influencing factors (such as client preference), Figure 3.1 shows my recommended migration path.

Figure 3.1. Recommended migration paths to .NET when selecting a language.

graphics/03fig01.gif



From Java to C#. A Developers Guide
From Java to C#: A Developers Guide
ISBN: 0321136225
EAN: 2147483647
Year: 2003
Pages: 221
Authors: Heng Ngee Mok

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net