Printer Friendly
The Free Library
14,632,679 articles and books
Member login
User name  
Password 
 
Join us Forgot password?

Migrating Java applications to Net.


Two paths are available for migrating Java applications A Java program that is run stand alone. The Java Virtual Machine in the client or server is interpreting the instructions. Contrast with Java applet. See servlet.  to .Net: upgrade them to Visual J# .Net, or convert them to Visual J# .Net. Upgrading Java applications to J# is the quickest and easiest way to port Java applications to the .Net Framework. Java developers are instantly productive on Visual 3# Net because they are already familiar with the syntax and set of class libraries. Java applications can convert to C# using the Microsoft Java Language Conversion Assistant (ILCA ILCA International Lactation Consultant Association
ILCA International Labor Communications Association
ILCA International Laser Class Association
ILCA Illinois Landscape Contractors Association
ILCA International Livestock Center for Africa
). Code that calls Java APIs There are three types of Java Programming Language Application Programming Interfaces (APIs) :
  • the official core Java API, contained in the JDK or JRE, of one of the editions of the Java Platform.
 can convert to comparable C# code that uses the .Net Framework. The JLCA (Java Language Conversion Assistant) Software from Microsoft that converts Java programs to C#. JLCA is used with Visual Studio .NET. See C#.  converts 90 percent of JDK-level 1.1.4 calls and emits issues in code for the other 10 percent. Each issue is linked to a topic with guidelines guidelines,
n.pl a set of standards, criteria, or specifications to be used or followed in the performance of certain tasks.
 for modifications needed to finish the conversion. Though converting to C# is slower than upgrading to J#, it offers more opportunities because converted applications use native Net Framework APIS.

Download the source code that accompanies this article from http://www.javaworld.com/javaworld/jw-01-2003/migration/jw_0103-migration.zip

Sample Visual 3++ application

As a demonstration, we have developed a sample Visual J++ (VJ++) application named CustomerDemo to port to .Net. The CustomerDemo application is modeled after a typical Java business application and uses some Java SDK (Software Developer's Kit) See developer's toolkit and Windows SDK.

SDK - Software Developers Kit (or "Software Development Kit").
 APIs as well as Microsoft Java packages A Java package is a mechanism for organizing Java classes into namespaces. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time. . CustomerDemo employs standard Java Database Connectivity (database, programming) Java Database Connectivity - (JDBC) Part of the Java Development Kit which defines an application programming interface for Java for standard SQL access to databases from Java programs.

http://java.sun.com/products/jdk/1.1/docs/guide/jdbc/index.html.
 (JDBC (Java DataBase Connectivity) A programming interface that lets Java applications access a database via the SQL language. Since Java interpreters (Java Virtual Machines) are available for all major client platforms, this allows a platform-independent database ) APIs to access the SQL server An earlier relational DBMS from Sybase and from Microsoft. Sybase introduced SQL Server in 1988 for various Unix versions. In that same year, with help from IBM, Sybase created an OS/2 version that Microsoft licensed and branded as Microsoft SQL Server.  to retrieve customer data. This data then transforms into hierarchical and flat views using the Java Collections API (Application Programming Interface) A language and message format used by an application program to communicate with the operating system or some other control program such as a database management system (DBMS) or communications protocol. . The views are constructed by employing Microsoft Windows See Windows.

(operating system) Microsoft Windows - Microsoft's proprietary window system and user interface software released in 1985 to run on top of MS-DOS. Widely criticised for being too slow (hence "Windoze", "Microsloth Windows") on the machines available then.
 Foundation Classes (WFC WFC Wi-Fi Connection (Nintendo gaming service)
WFC Wide-Field Camera
WFC World Financial Center (New York)
WFC Workforce Center
WFC World Federation of Chiropractic
WFC World Food Council
). The following CustomerDemo parts will be detailed:

* User interface

* Database access

* Common Java APIs used

User interface

CustomerDemo is a Windows application A program that is written to run under Microsoft's Windows operating system. Such applications typically run under all 32-bit versions of Windows, but earlier applications might also run under the 16-bit versions (Windows 3.x) as well. See Windows.  that has a Windows Form, ViewCustomer, shown in Figure 1: ViewCustomer is a com. ms. wfc. ui. Form hosting a typical set of Windows controls such as Panel, TreeView, Splitter, Edit, and Labels. It shows customers in a left-pane, hierarchical view. Countries are shown at the first level and customers at the leaf level. Clicking on each customer retrieves the detailed record of that customer data. These details include Contact and Address, shown in respective edit controls in the right pane A rectangular area within an on-screen window that contains information for the user. A window may have many panes. See menu pane. .

Commercial applications generally have resources like icons and bitrnaps stored in resource files. So, we also have an icon resource embedded Inserted into. See embedded system.  in ViewCustomer Form and stored in the associated resource file ViewCustomer.resource.

Database access

We have provided the SQLData class that retrieves customer data from the Northwind database (sample database that comes with MS SQL server See Microsoft SQL Server. ). SQLData accesses the database server by employing standard JDBC APIS. It connects to the database using the following code:

dbCon- = DriverManager.getConnection (conInfo_," "," ") ;

Country and customer data is retrieved using the following code:

stmt = dbCon_.createStatement () ;

rs = stmt. executeQuery (sq1Query) ;

while (rs.next () ) {

String countryId = rs.getString ("Country") ;

String companyName = rs.getString ("CompanyName") ;

//Package data into a Hashtable

Common Java APIs used

The CustomerDemo application uses common Java classes from java. util and java. lang packages. For example, it uses java. util. Hashtable to store the relationship between customers and countries. The java. util. Hashtable key is country name, and values are customers stored in a java. util. Vector. We use java. util. Enumerator e·nu·mer·ate  
tr.v. e·nu·mer·at·ed, e·nu·mer·at·ing, e·nu·mer·ates
1. To count off or name one by one; list: A spokesperson enumerated the strikers' demands.

2.
 to iterate it·er·ate  
tr.v. it·er·at·ed, it·er·at·ing, it·er·ates
To say or perform again; repeat. See Synonyms at repeat.



[Latin iter
 the country keys and then get the associated list of customers. The relevant code is below:

Enumeration 1. (mathematics) enumeration - A bijection with the natural numbers; a counted set.

Compare well-ordered.
2. (programming) enumeration - enumerated type.
 countryEnum = htCountryCompanyMap.keys () ;

while (countryEnum.hasMoreElements () ) {

String countryId = (String) countryEnum.nextElement () ;

Vector companyList = (Vector) htCountryCompanyMap.get (countryId) ;

The SQLData class uses the java. lang. String and java. lang. StringBuffer classes to manipulate SQL SQL
 in full Structured Query Language.

Computer programming language used for retrieving records or parts of records in databases and performing various calculations before displaying the results.
 queries. java. lang. Exception handles exceptions.

Migration to the Net Framework

As previously mentioned, two good approaches are available to migrate existing Java applications to .Net:

* Upgrade to J#

* Convert to C#

Each migration path generates a different result. Table 1 shows what happens to the composition of Java projects when they migrate to Net.

Upgrade to J#

Visual J# .Net consists of a Java language compiler compiler

Computer software that translates (compiles) source code written in a high-level language (e.g., C++) into a set of machine-language instructions that can be understood by a digital computer's CPU.
, JDK-level 1.1.4 class libraries, and a tool to upgrade compiled Java byte code See bytecode.  to Microsoft Intermediate Language (MSIL (MicroSoft Intermediate Language) See CLI. ), which is useful for upgrading libraries to a form that can be used from .Net applications. In addition to JDK-level 1.1.4 class libraries, like other .Net compliant languages, J# has full access to the .Net Framework and includes designers for Windows Form and Web Form development. J# offers familiar Java language syntax to build applications and services on .Net. We will now upgrade the Visual 3++ CustomerDemo application to J#.

We cover the following upgrade steps:

* Visual J# Upgrade Wizard

* Upgraded J# code

* Upgrade issues

Visual J# Upgrade Wizard

The Visual J# Upgrade Wizard Is included in the Visual J# installation with Visual Studio .Net A suite of programming languages and development tools from Microsoft that supports the .NET environment. Upon its introduction in 2001, it included Visual C# and .NET versions of Visual Basic and Visual C++. See .NET. . The Visual J# Upgrade Wizard can be invoked by opening the VJ++ project file (. vjp) in Visual Studio. We open CustomerDemo.vjp in Visual Studio to start the Visual J# Upgrade Wizard. The Upgrade Wizard asks for the type of application we want to convert as shown in Figure 2:

We choose Windows Application and continue. We get an upgraded J# application named CustomerDemo_Net.vsproj containing the upgraded project files.

As we see in this wizard, the migration path exists for Java applications developed using JDK-level 1.1.4 class libraries. Java applications developed using JDK-level 1.1.4 class libraries can first be made part of a temporary VJ++ project. Subsequently, we can start the Upgrade Wizard from the temporary VJ++ project file and select either Console Application A console application is a computer program designed to be used via a text-only computer interface, such as a text terminal, the command line interface of some operating systems (Unix, DOS, etc.  or Class Library.

Java applications that use higher JDK (Java Development Kit) A Java software development environment from Sun. It includes the JVM, compiler, debugger and other tools for developing Java applets and applications. Each new version of the JDK adds features and enhancements to the language.  versions can also use the Upgrade Wizard to migrate the greater part of the application (business logic, JDK-level 1.1.4 classes, and most of the JDK 1.2 java.util package) automatically. The remaining Java technology can be replaced with comparable .Net APIS. Java applications using Swing should be migrated manually to Windows Forms Windows Forms is the name given to the graphical user interface application programming interface (API) included as a part of Microsoft's .NET Framework, providing access to the native Microsoft Windows interface elements by wrapping the existing Windows API in managed code. . By copying the event-handling code in Swing Forms to the relevant Windows event handlers A software routine that provides the processing for various events such as mouse movement, a mouse click, a keystroke or a spoken word. See event, event driven and event management system. , most of the code can be reused.

The Upgrade Wizard also produces an upgrade report,_UpgradeReport.htm, listing relevant information and any problematic migration issues.

Upgraded J# code

J# provides a set of independently developed class libraries In .Net that offer the functionality of most JDK- level 1.1.4 class libraries and many classes in the JDK 1.2 java.util package. Therefore, the java. sql, java.util, java. lang, and com.ms.wfc packages used in our Java application upgrade to the same names in J#. Consequently, upgraded J# project CustomerDemo_Net. vsproj contains SQLData. java and Viewcustomer. java, and they look exactly like the former Java code shown in the example code snippets above. The ViewCustomer. resource file automatically converts to ViewCustomer. resX, a Net-compatible resource file. Now we just build the upgraded J# code, run It, and see the same output as in Figure 1.

Upgrade issues

The original VJ++ form derived from com.ms.wfc. ui. Form migrates to the corresponding com.ms.wfc. ui. Form in J#. This imposes a limitation with using Windows Forms Designer for the upgraded form In Visual Studio because Windows Forms Designer cannot design forms derived from com.ms wfc. ui. Form. So, any change In the upgraded form's user interface layout must be done manually. Alternatively, a backward approach can also work for altering upgraded, but very complex, user interfaces to meet the new requirements. We can use original VJ++ application code and the VJ++ editor to alter a form's layout. The changed form can be upgraded separately and then included in the migrated application again.

Convert to C#

C# is a native .Net language designed specifically for developing new generation .Net applications. Java applications can be migrated to C# to take advantage of the .Net Framework. In this section, we examine the process of converting the VJ++ CustomerDemo application to C#. We cover the following topics in this section:

* Java Language Conversion Assistant

* Converted C# code

* Conversion issues and manual steps

Java Language Conversion Assistant

Visual Studio provides the Java Language Conversion Assistant (JLCA) to convert Java applications to C#. We launch JLCA from the File->Convert menu in Visual Studio. We choose VJ++ 6.0 Project as the conversion option shown in Figure 3: We then select CustomerDemo. vjp as the source VJ++ project to convert to C#. We also choose CustomerDemo.NET as the newly converted C# project's name. We then go through the JLCA wizard's remaining steps to complete the C# conversion. We get a converted C# project CustomerDemo.csproj at the end of the conversion.

We can also convert a set of Java classes by choosing the second option in Figure 3.

Converted C# code

JLCA converts the VJ++ project and gives us a converted CustomerDemo.csproj. The project's Java classes and other files like resources in the CustomerDemo application convert to:

The JDK and Microsoft packages and classes used in CustomerDemo convert to:

The application's main () method converts to Main ():

[STAThread]

public static void Main (System.String[] args) {

System.Windows.Forms.Application.Run (new ViewCustomer() );

}

The converted code in the data access class SQLData. java now uses ADO. Net (ActiveX Data Objects (database, Microsoft, programming) ActiveX Data Objects - (ADO) Microsoft's library for accessing data sources through OLE DB. Typically it is used to query or modify data stored in a relational database.

http://msdn.microsoft.com/library/en-us/ado270/htm/adostartpage1.asp.
) instead of JDBC. The connectToDB () method establishes connection to the database using System.Data.OleDb.OleDbConnection ():

dbCon_ = new System.Data.OleDb.OleDbConnection (conString) ;

dbCon_.Open() ;

The code for getting the record from the database is converted and uses

System. Data. oledb. OleDbCommand in place of j ava. sql. Statement, and System. Data. oledb. OleDbDataReader in place of java. sql - ResultSet. The OleDbDataReader is accessed with the [ ] operator to get data from a column, which is similar to any normal array access. JLCA also introduces a new SupportClass to provide wrapper A data structure or software that contains ("wraps around") other data or software, so that the contained elements can exist in the newer system. The term is often used with component software, where a wrapper is placed around a legacy routine to make it behave like an object.  methods for controlling database transactions, which can be removed If not required. The converted code is below:
               System.Data.OleDb.OleDbCommand stmt =

               SupportClass.TransactionManager.manager.
               CreateStatement (dbCon_) ;

               stmt.CommandText = sqlQuery;

               System.Data.OleDb.OleDbDataReader rs = stmt.
               ExecuteReader () ;

               while (rs.Read () ) {

               System.String countryId =
                    System.Convert.ToString (rs [ ("Country") ] ) ;

               Syste.String companyId =
                    System.Convert.ToString (rs [ ("CompanyName") ] ) ;


Interestingly, JLCA converts the original getCountryCompany () method to a property CountryCompany of the SQLData class in C#. Countrycompany property's code is shown below.

public virtual System. Collections.Hashtable CountryCompany {

get {

The code to iterate java. util. Hashtable converts to System. Collections. Hashtable. Hashtable is accessed with the [] operator now. However, the converted code for iterating ITerating.com is a Wiki-based software guide, where everyone can find, compare and give reviews to thousands of software products. Founded in October of 2005, and based in New York, ITerating.  Hashtable does have a problem that we will manually correct in the next section. The converted code for Hashtable is:

System.Collections.IEnumerator countryEnum = (System.Collections.IEnumerator)

htCountryCompanyMap.Keys;

while (countryEnum.MoveNext () )

{

System.String countryId = (System.String) countryEnum.Current;

System.Collections.ArrayList companyList = (System.Collections.ArrayList)

htCountryCompanyMap [countryId];

The ViewCustomer user interface easily converts to C#. ViewCustomer Form now derives from System. Windows. Forms. The controls like TreeView, Edit, Label, and TextBox contained in ViewCustomer automatically convert. Also note that the Windows Forms Designer in C# can open ViewCustomer Form and make changes unlike the upgraded form in J#.

Conversion issues and manual steps

JLCA automatically converts much of the Java code into C# code. However, it still leaves certain issues that must be manually resolved before the converted CustomerDemo. csproj project can be compiled and run in .Net. A conversion report produced by JCLA JCLA Japan Chemical Laboratory Accreditation
JCLA Just Chilling Like Always (chat) 
 listing all these issues:

Let's go Let's Go may refer to: Television
  • Let's Go (Philippine TV series), a teen Philippine sitcom on ABS-CBN
  • Let's Go (New Zealand TV series), a New Zealand television music show
  • Let's Go
 through these issues and see how we can resolve them.

The first set of issues is related to some manual changes required in database access. The conversion comment UPGRADE _TODO TODO Technical Order Distribution Office  points out that JdbcodbcDriver did not convert. The IDBC IDBC Internal Device Buffer Code ( IBM mainframe terminals and printers character set)
IDBC Interior Design British Columbia
 driver used in the original code is not necessary in ADO.Net. So, we remove the line of code that loads the IDBC 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 catalog, descriptive list, on cards or in a book, of the contents of a library. Assurbanipal's library at Nineveh was cataloged on shelves of slate. The first known subject catalog was compiled by Callimachus at the Alexandrian Library in the 3d cent. B.C. =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 =

htCountryCompanyMap.GetEnumerator ();

while (dictEnum.MoveNext () ) {

System.String countryId = (System.String) dictEnum.Key;

System.Collections.ArrayList companyList =

(System.Collections.ArrayList) dictEnum.Value;

...

}

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. wf c. ui. Fontsize is not available in .Net. We used FontSize for setting the font style A typeface variation (normal, bold, italic, bold italic).  of the customer path control (a com.ins - wf c. 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 The typeface and type size used if none other is specified.  used in the Windows Form in C# was Microsoft Sans Serif Short horizontal lines added to the tops and bottoms of traditional typefaces, such as Times Roman. Contrast with sans-serif.

, 8.25pt Instead of MS Shell Dig, 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 Hiccups Definition

Hiccups are the result of an involuntary, spasmodic contraction of the diaphragm followed by the closing of the throat.
Description
 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 conversion. Applications converted to C# might experience improved performance, scalability, security, and versioning on the Net platform. Applications upgraded to 3# 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.

www.javaworld.com
Table 1. Migration path

Java technology             Upgrade to J#     Upgrade to C#

Java language               Java language     C# language

Applet                      Not converted     Windows Form control

JavaBean                    JavaBean          C# class

Abstract Windowing Toolkit  AWT frame         Windows Form
(AWT) frame

WFC Form                    WFC Form          Windows Form

Compiled library            Compiled library  Not converted

Resource file               ResX file         ResX file

Table 2. Class-level VJ++ to C# conversion Java

Java                      C#

ViewCustomer.java         ViewCustomer.cs
SQLData.java              SQLData.cs
ViewCustomer.resources    ViewCustomer.resX
                          New class Introduced:
                          SupportcClass.cs

Table 3. API-level VJ++ to C*#conversion

Java                        C#

java.sql                    System.Data.Oledb
java.util                   System.Collections
com.ms.wfc.ui.Forms         System.Windows.Forms
java.lang.String            System.String
java.lang.StringBuffer      System.Text.StringBuilder
java.lang.Exception         System.Exception
COPYRIGHT 2004 A.P. Publications Ltd.
No portion of this article can be reproduced without the express written permission from the copyright holder.
Copyright 2004, Gale Group. All rights reserved. Gale Group is a Thomson Corporation Company.

 Reader Opinion

Title:

Comment:



 

Article Details
Printer friendly Cite/link Email Feedback
Title Annotation:Java Progress - Migrating Java to .Net
Author:Kumar, Sunil
Publication:Software World
Date:Jul 1, 2004
Words:2600
Previous Article:Comparing .NET with J2EE.(Java Progress - .NET and J2EE)
Next Article:Key concepts in Software acquisition.(Tech Note)(Brief Article)
Topics:



Related Articles
COMPAQ CLAIMS NEW ALPHA SERVERS OUT PERFORM THOSE BY SUN, IBM, HP.(Product Announcement)
SYMANTEC DEBUTS VISUALCAFE WITH POINTBASE 100% PURE JAVA.(Company Business and Marketing)
JAVA TRADEMARK WHIPS UP WEB TROUBLE.(BUSINESS)
DT/Studio to help SMEs. (Database News).
Sun Microsystems partners with AMD to provide native support for Java technology on 64-bit AMD Opteron processor for Linux and Windows: high...
O'Reilly Publishers.(Database in Depth: Relational Theory for Practitioners)(Killer Game Programming in Java)(Access Hacks: Tips and Tools for...
JNBridge Releases Version 3.0 of JNBridgePro; Java-.NET Interoperability Solution Includes New .NET Framework 2.0 and J2SE 5.0 Features.
The present and future for past languages--COBOL.(DATABASE INTELLIGENCE)
JNBridge Releases Java and .NET GUI Control Embedding Capability.
Unify Unveils Composer for Migration of Lotus Notes Applications to Java and .NET.

Terms of use | Copyright © 2009 Farlex, Inc. | Feedback | For webmasters | Submit articles