Introducing Visual J .NET


Introducing Visual J# .NET

Similar to the C# language, the Visual J# .NET language is often abbreviated down to just J# (pronounced "J sharp"). According to Microsoft s documentation, the J# language is specifically targeted at those Java programmers and J++ programmers looking for a .NET alternative language.

Note  

The newest version of VS .NET (v1.1) includes J# as a language choice. If you are using VS .NET v1.0, you can download the J# compiler separately. See http://msdn.microsoft.com/library/en-us/ dv_vjsharp/html/vjoriMicrosoftVisualJ.asp for more information and http://msdn.microsoft.com/downloads/sample.asp?url=/ MSDN-FILES/027/001/973/ msdncompositedoc.xml to download the J# add-on.

As you begin your exploration into the specifics of J#, it will be impossible not to see the reoccurring disclaimers posted by Microsoft. For example, in the ReadMe document that accompanies the J# product (VJSharpRME1033.htm), Microsoft clearly states the following points:

  • "Applications and services built with Visual J# will run only on the .NET Framework. Visual J# is not a tool for developing applications intended to run on a Java Virtual Machine."

  • "Microsoft Visual J# .NET Redistributable Package is the redistributable package for Visual J#. The Redistributable Package will only run applications and services developed with Visual J#; Java-language applications written with other Java-language development tools will not run with the Microsoft Visual J# .NET Redistributable Package."

  • "Visual J# and the Microsoft Visual J# .NET Redistributable Package have been independently developed by Microsoft, and are not endorsed or approved by Sun Microsystems, Inc."

  • "Visual J# can only be installed and used on a computer that has Microsoft Visual Studio .NET installed."

Obviously, as these points illustrate , Microsoft wants to avoid creating any confusion in the Java community. Kudos and accolades to Microsoft.

J# Looks Like C#

The first time I looked at the J# language, I needed to take a very close look at J# to notice the subtle differences between it and C#. I suppose I should have expected this. Recall that C# looks like Java and J# was built using Java language syntax .     How nice!

Perhaps I m going out on a limb and stretching the use of logic and reason. Nevertheless, if someone tells me that J# is made to have Java language syntax and I can see that J# looks like C#, I then conclude that C# apparently was also made to have Java language syntax. It s a stretch, but that s my opinion.

Therefore, before you even look at your first line of J# code, please understand this: By being familiar with each syntax feature discussed already (for C# and for Java), you have already become familiar with the J# syntax. In other words, with the basic syntax rules discussed so far, learning one language actually means learning three languages. [5] How nice! How very nice!

As it turns out, the J# syntax has a few unique characteristics, at least when you compare it with C#. The next section briefly covers those differences.

J# Does Differ from C#

Before I even mention the few differences between J# and C#, I need to mention this one point. The few syntax differences that set J# apart from C# actually serve to make J# that much closer to Java. Let s cover a few examples.

The first example is the fact that the default extension for a J# code file is ".jsl". OK, I ll stop messing around. Now, let s take a look at some of the more interesting differences.

One of the first things you will notice in a J# program is the keyword package . The package keyword is analogous to the C# keyword namespace . Why do you suppose J# uses the term "package" instead of "namespace"? The fact that Java uses the term "package" provides you with a very good hint.

J# has a syntax feature that allows a documentation comment (a block of com ments that can be extracted from the code). Sure, C# also has this type of syntax feature. However, the manner in which J# implements the feature is certainly different. In J#, the documentation comments are created by starting the comment block with a forward slash and two asterisks (/**). The documen tation comment block concludes with an asterisk and a forward slash (*/).

Note  

In Java terms, this documentation comment feature is referred to as Javadoc comments. Yes, Java also uses /** and */ to implement the Javadoc comments.

To provide a shortcut for namespace names coding, J# offers the import statement. This is comparable to the C# using statement. As you might have guessed, Java also uses the import statement.

J# uses the keywords extends and implements to inherit base classes and implement interfaces, respectively. This is comparable to the use of the colon (:) in C# syntax. Of course, Java uses the keywords extends and implements when implementing similar functionality. Do you see a pattern developing here?

I ll cover just a couple more J# versus C# observations. Then you ll finally see some J# code.

J# uses the @ Attribute directive to attach attributes to classes, methods , and so on. You will recall that C# uses a square bracket syntax (e.g., [STAThread]) to attach an attribute at the method level.

When you read and update properties in J#, you will attach the prefixes get_ and set_ to the names of properties, respectively. Although this is rather different than C#, it is somewhat intuitive. If you consider that COBOL .NET, VB .NET, and C# all support the use of Get/Set keywords when defining properties, it s perfectly understandable why J# implements the use of get_ and set_ when reading and updating properties. Not convinced yet? All right, you caught me. Yes, Java also uses the attached get and set prefixes when accessing properties.

Finally, let s take a look at the J# language.

Finally, J# Code

Using the J# language choice and the VS .NET Console Application project tem plate, I created a sample application (MyFirstJSharpApplication). I based my J# logic after the sample applications (COBOL .NET and VB .NET) originally built in Chapter 5 and Chapter 6. Please take moment to read the J# code logic in Listing B-3.

Listing B-3: The MyFirstJSharpApplication Sample Application
start example
 // The package statement is similar to the namespace statement  package MyFirstJSharpApplication; // The import statement provides a short cut for namespace coding // notice the asterisk (below) used as a wildcard. import System.*; /**       * This is my first J# Application. Coding in J# is easy.       * The use of the slash and two asterisks ("/**") denotes        * the use of J#'s Javadoc like Documentation feature.        * You will also see Javadoc comments using Tags       * (e.g @param, @return, @see, @version, and @author).       * You can display Javadoc comment blocks by       * navigating to the VS.NET Main Toolbar,        * clicking Tools and then clicking       * the "Build Comment Web Pages" menu option.        * After building the Comment Web Page you can save the page        * as part of the applications documentation.       * @author Chris Richardson       */ public class Class1  {       public Class1()       {}           /**             * The main entry point for the application.            * @attribute System.STAThread() */       public static void main(String[] args)       {            // Use two slash symbols ("//") for a single line comment            /* Optionally, you can create a multi line comment block             * by using a single slash followed by an asterisk ("/*").            * The end the comment block, use an asterisk followed by a slash            */            Console.WriteLine("Hello, .NET World.");            Console.WriteLine("I cannot believe how simple J# is!");                //Execute Procedures            DefineDataTypesSample();            LogicSample();                Console.WriteLine("Press Enter to Exit.");            Console.ReadLine();            }       static void DefineDataTypesSample()       {                //Declare Data Items using generic Object Types            // code was added to cast the objects to J# Data Types            short MyFirstNumberJsharp;            int MySecondNumberJsharp;            double MyThirdNumberJsharp;                //Declare Data Items using Native .NET Data Types            System.Int16 MyFirstNumberNative;            System.Int32 MySecondNumberNative;            System.Double MyThirdNumberNative;                //Place a numeric literal in Data Item            Int16 myShortvalue = (Int16) 32767;            Int32 myIntvalue = (Int32) 32767;            System.Double myDoublevalue = (System.Double) 32767;                MyFirstNumberJsharp = (short) myShortvalue;            MySecondNumberJsharp = (int) myIntvalue;            MyThirdNumberJsharp = (double) myDoublevalue;                MyFirstNumberNative = (System.Int16)32767;            MySecondNumberNative = (System.Int32)32767;            MyThirdNumberNative = (System.Double)32767;                //Write out contents of each variable            Console.WriteLine("MyFirstNumberJsharp= " +                  MyFirstNumberJsharp);            Console.WriteLine("MySecondNumberJsharp= " +                  MySecondNumberJsharp);            Console.WriteLine("MyThirdNumberJsharp= " +                  MyThirdNumberJsharp);            Console.WriteLine("MyFirstNumberNative= {0}",                  MyFirstNumberNative);            Console.WriteLine("MySecondNumberNative= {0}",                  MySecondNumberNative);            Console.WriteLine("MyThirdNumberNative= {0}",                  MyThirdNumberNative);       }       static void LogicSample()       {            //*** Declare Data Items using .NET Data Types            System.String MYString;            System.Int32 MYInteger;            boolean MYBoolean = false;            System.DateTime systemDate;                //*** Declare Data Items with J# Data Types            int MyIndex = 0;            int MySecondIndex;            int MyAccum = 0;            boolean MyFlag = false;            java.lang.String MyFixedLengthString;       //*** Demonstrate creation of String Array       java.lang.String[] MonthValues =             {                          "January", "February", "March",                     "April", "May", "June",                    "July", "August", "September",                     "October", "November", "December"};           //*** Demonstrate Intrinsic Function accessing System Date       //    notice that "get_" is attached to the Now method/property       systemDate = DateTime.get_Now();           Console.WriteLine("Today is {0}" ,             systemDate.ToShortDateString());      //*** Demonstrate Booleans, Constants, and Conditional/Computational Logic           do        {             MyIndex += 1;             if (MyIndex > 12)             {                    MYBoolean = true;                    MyFlag = MYBoolean;              }        } while (!(MyFlag));           if (MyFlag)        {             MYString = "The Boolean is now set to TRUE";             MyFixedLengthString = MYString;             Console.WriteLine(MyFixedLengthString);        }           //*** Demonstrate usage of Conditional and Computational Logic       for (MySecondIndex = 1; MySecondIndex <= MyIndex; MySecondIndex++)       {            MyAccum = MySecondIndex += 1;       }       MYInteger = (Int32) MyAccum;      //*** Demonstrate Intrinsic Functions, Conditional/Computational Logic        MyIndex = 1;        MyFixedLengthString = String.Empty;        for (int x = 0; x <= 11; x++)        {           switch (x)           {                 case 11:                 case 0:                 case 1:                       Console.WriteLine                       (java.lang.String.Concat(MonthValues[x],                                " is ","Winter"));                       break;                 case 2:                 case 3:                 case 4:                       Console.WriteLine                       (java.lang.String.Concat(MonthValues[x],                             " is ","Spring"));                       break;                 case 5:                 case 6:                 case 7:                       Console.WriteLine                        (java.lang.String.Concat(MonthValues[x],                             " is ","Summer"));                       break;                 case 8:                 case 9:                 case 10:                    Console.WriteLine                       (java.lang.String.Concat(MonthValues[x],                                " is ","Autumn"));                       break;                 default:                       Console.WriteLine                                 ("A logic exception");                       break;           }        }     }  } 
end example
 

As you can tell from looking at the J# sample application in Listing B-3, each of the Java and C# observations noted earlier are realized. I would like to mention two noteworthy differences between this J# sample and the C# sample (Listing B-2).

  • In the DefineDataTypesSample method, the data types required explicit type casting. This coding characteristic is more prevalent with J#.

  • The switch statement shown in the LogicSample method was changed to use ordinal values as dictated by the J# compiler.

As you explore the J# language, you will notice a scarcity of available docu mentation. Several references are included in the "To Learn More" section at the end of this appendix to help get you started. Between these references and my own Java textbook , I was able to work through each J# coding issue somewhat painlessly.

[5] Combine that with VB .NET and COBOL .NET and you have five languages presented in this book. Now, would that be quintlingual or quadlingual + 1?




COBOL and Visual Basic on .NET
COBOL and Visual Basic on .NET: A Guide for the Reformed Mainframe Programmer
ISBN: 1590590481
EAN: 2147483647
Year: 2003
Pages: 204

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