Migrating Java applications to .Net

How to convert existing Java or Visual J++ applications to J# or C#

1 2 Page 2
Page 2 of 2

The first set of issues is related to some manual changes required in database access. The conversion comment UPGRADE_TODO points out that JdbcOdbcDriver did not convert. The JDBC driver used in the original code is not necessary in ADO.Net. So, we remove the line of code that loads the JDBC driver.

The next conversion comment indicates that the Connection string should be in the ADO.Net format. So, we must change our Connection string to:

String conInfo_ = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=Northwind;User ID=sa;Password=;";

The next UPGRADE_TODO comment indicates that java.sql.Statement.close should be removed. So, we manually remove this line wherever it occurs in the SQLData class.

Automatic conversion uses the System.Collections.IEnumerator to iterate through a Hashtable. In fact, we find that trying to get System.Collections.IEnumerator from Hashtable.keys produces a runtime exception. So, we must manually correct the code to instead use System.Collections.IDictionaryEnumerator to iterate through Hashtable keys. Here is the changed code:

System.Collections.IDictionaryEnumerator dictEnum = 
while (dictEnum.MoveNext()){
      System.String countryId = (System.String)dictEnum.Key;
System.Collections.ArrayList companyList = 

The next set of issues relates to manual changes required in the user interface code. If we try to compile the CustomerDemo project at this point, we get a compiler error. On investigating this error further, we find that com.ms.wfc.ui.FontSize is not available in .Net. We used FontSize for setting the font style of the customer path control (a com.ms.wfc.ui.Label control) in the ViewCustomer Form in VJ++. We correct this problem by opening the ViewCustomer Form in the Windows Forms Designer and set the new font explicitly to the required style.

The default font used in the Windows Form in C# was Microsoft Sans Serif, 8.25pt instead of MS Shell Dlg, 11char as in VJ++. This automatic font switch caused the text to go beyond the size of the label controls in the ViewCustomer Form, so we must manually increase the labels' size so the text appears properly.

Now, we are ready to compile the converted CustomerDemo application and run it without any hiccups to see the same output as in Figure 1.

The move to .Net

Migration tools are available that facilitate the conversion of Java applications to Visual J# and Visual C#. Each method has its advantages: upgrading to J# is the quickest and easiest option, providing instant benefit to the Java application. Converting to C# is a slower option, but delivers maximum flexibility for the converted application. The choice of whether to use J# or C# depends on two major factors: migration time and framework.

When a Java application is upgraded to J#, the language stays as Java, and calls to JDK-level 1.1.4 APIs are preserved. When the same application converts to C#, the language converts to C#, and Java API calls convert to native .Net Framework calls. The quality of this conversion is very high (often upwards of 90 percent), but some modifications are required after the JLCA finishes. C# conversion takes longer than J# conversion. Applications converted to C# might experience improved performance, scalability, security, and versioning on the .Net platform. Applications upgraded to J# continue to use Java data types and Java libraries, although you can add new functionality with the .Net Framework.

If you choose to move to .Net, all of .Net's benefits are immediately available to your migrated applications, enabling developers to add new capabilities to existing applications.

Nitin Nanda is the associate project manager in the R&D Centre of Quark, based in Chandigarh, India. He is responsible for the front office suite of components for a customer relationship management (CRM) product engineered in COM/MTS/C++. He has coauthored Professional Java Data and Beginning Java Databases, both from Wrox Press. He worked for Cadence Design Systems prior to joining Quark. Sunil Kumar is an associate team lead in the R&D Centre of Quark, based in Chandigarh, India. He is responsible for design and development of the various components in a CRM product engineered in VJ++/ASP/COM+/SQL Server. He developed generic ERP software at RAMCO Systems prior to joining Quark.

Learn more about this topic

1 2 Page 2
Page 2 of 2