Migrate the Java application to .NET
Microsoft Corporation In June 2002 Suitable for: Microsoft .NET Summary: Discover Microsoft .NET than Java's superior place, learn how to convert Java applications to .NET. Please download migratingjavaapplicationscsharpdemo.msi and migratingjavaApplicationsjsharpDemo.msi from MSDN Code Center. table of Contents
What is .NET? How to compare .Net and Java how to migrate the Java application to .NET exercise small knot what is .NET? Microsoft® .NET (read "DOT NET") is both software writing methods and a tool for developing software that implements these methods. Let's take some common business issues related to connectivity and interoperability to illustrate the cause of the .NET method: Most companies work with other companies, but their information system is isolated. There is no product supply chain that starts throughout the supplier; the contact between suppliers and buyers is often limited to fax or simple text file exchange. This usually regards this as an obstacle to increase productivity. Better communication can enable companies to achieve higher efficiency. When all vendors in the supply chain are connected to each other, each vendor can reduce inventory to the lowest level, and coordinate according to demand and more efficiently. Related to this is interoperability issues. When the company promises to connect each other, if their operating system is in different re-development status or in constant changing, they will face a difficult design and the planning of the connection. In addition, data security is also a complex problem, because through the enterprise firewall and its exchange of data are both partners and competitors. The .NET method can better enable this capability, which makes the system that can be securely connected to each other on any time, anywhere, and any device, becomes very simple. Core technology to achieve this is XML Web Service. This technology is both a method and a transport layer that transmits information between components of different machines, different networks and different operating systems. XML Web Service has been widely supported. Many companies have been connected to partner using XML Web Service. Microsoft is increasing support for XML Web Service on all products. From a developer's perspective, .NET makes it very simple to use Microsoft Visual Studio .NET, .NET Framework, and XML Web Service to write to each other. .NET Framework .net is not just XML Web Service. The core of .NET is .NET Framework, consisting of a public language runtime library and class library. These two components provide an execution engine and programming API for building .NET applications. Applications compiled for .NET are not directly compiled cost machine code, but is compiled into an intermediate language called Microsoft Intermediate Language (MSIL). When running an application for the first time, the public language runtime compiler compiles the MSIL code to the machine code before execution. The public language running library is not a simple JIT compiler, which is also responsible for providing memory recycling, exception handling, security services, runtime type security checks. Due to the role of the public language runtime, therefore sometimes the program "hosting" application will be called "hosting" program. .NET Framework is a set of classes that are used to build applications running on a public language run. These class libraries provide powerful support for various tasks including data access, security, file IO, XML operation, message transfer, class reflection, XML Web Service, ASP.NET, and Microsoft Windows services. Maybe .Net The most unique attribute is its multi-language support. Microsoft has released four business languages for .NET Framework: Visual C # ® .NET, Visual Basic® .NET, C hosted extensions and Visual J # .NET. Many other compatible languages are also under development, including Perl, Python, and COBOL. To help create a language compatible .NET Framework, Microsoft designed a public language norm (CLS).
Each language is used to run libase, and interoperability with components written in other languages, and must provide the functions described in CLS. If a language implements the required function, it is called compatible .NET. Each compatible .NET language supports the same data type, using the same .NET Framework class, compiled as the same MSIL, and use the same public language runtime management execution process. Therefore, there is no advantages and disadvantages between various compatible .NET language. Developers can freely select the best language for specific components and do not lose the ability and freedom of the platform. In addition, components written in language can be easily interoperable with components written in another language. For example, you can use C # to write a class that inherits from the base class written by Visual Basic. CLS has been submitted to ECMA to standardize, which encourages many language developers to create a contained .NET version for many languages. There are more than 20-compatible languages that are compatible with .NET in writing this article. Figure 1 shows a variety of .NET components over the operating system. The .NET Framework consists of four blue frames, which represent the ASP.NET, Windows Forms, ADO.NET, and XML, and sub-components, respectively. Figure 1: .NET Framework Architecture Visual Studio .NET In order to be able to perform .NET development, Microsoft re-writes its development tool and re-combined it into Visual Studio .NET. Visual Studio .NET supports development applications using one or more languages. Design, development, commissioning and deployment .NET components use the same integrated development environment (IDE). This development environment supports console applications, Windows applications, DLLs, web applications, development of XML Web Service, and handheld device applications. The development environment provides some unique high productivity features: intelligent awareness; visual designer for web forms, Windows forms, XML architecture and data; you can seamlessly use a language to be transferred to another The cross-language debugger of the code written in language; close integration with .NET Framework; continuous dynamic help of context-related help; display compiler errors and task lists of tasks; architecture design features, such as Visio integration And servers, Windows services, performance counters, and server-side application components for visual access databases. Microsoft Visual Studio .NET is a winning development tool. When writing this article, Visual Studio .NET has gained a number of awards, including 2002 SD Magazine Efficiency Awards and PC Magazine's 2001 Excellence (although the product is still in the beta phase). Compare .NET and Java in experienced Java developers, .NET may be similar to the Java platform, all provide a structured method for creating applications, both compiled as an intermediate code, is an application Program development provides a large API library. But in fact, the core of .NET has a set of targets with the Java platform. From the concept, Java is two things: Java platform (runtime and API) and Java language. The use of the Java platform is to support applications written in Java language and compiled as Java bytecodes. Although many attempts to compile other languages as Java bytecodes, most of these work are academic activities. Java's ideal goals have always been "using a language on a variety of platforms."
.NET is also two things: .NET Framework (Runtime and API) and a large supporting language. The use of .NET Framework is to support applications written in any language and compiled into MSIL. The goal of .NET is "a variety of languages sharing a platform." The advantages compared to Java compared to Java, there are many other advantages in addition to language freedom. Some of the most important advantages are summarized: Frameworks Since Java is a multi-platform, the framework class is limited to all platforms provided by all platforms. This affects the range and richness of the class: the scope of the class is limited to the most common class available in the computer and operating system. In addition, it also affects the richness of the class itself. Built-in Java classes are generally very simple, developers often build their own framework or have to look for third-party frameworks such as XML file syntax analysis. A third-party library must be used to use a third-party library or write its own syntax analysis prior to issue JDK 1.4. Writing your own grammar analysis usually requires more than 100 lines of code. .NET Framework is built on top of the Windows platform. There is also a public language run library for FreeBSD and the .NET Framework class library version. These classes include all frame classes on the platform. In addition, these classes are also richer than those that Java can provide. .NET provides a programming framework instead of a foundation for building a programming framework. The following C # example illustrates how to grant the XML file in .NET. Note that auxiliary class has been provided in .NET Framework. This makes the code very simple: XMLTextReader myXmlTextRextRextReader myXMLTextRextRextRextRextReader = New XMLTextReader ("texttovalidate.xml); XmlvalidatingReader myReader = New XmlValidatingReader (MyXMLTextReader);
MyReader.schemas.Add (myXmlschemacolection);
MyReader.validationEventHandler = New ValidationEventhandler (this.validationFailureHandler);
// read XML data.
While (MyReader.Read ()) {} .NET Framework's fidelity is higher than the Java platform. The .NET program can use all the features of Windows, not only the most popular features of Windows as Java.
"... The real bottom line is: .NET method means that Microsoft provides more than 90% of the developers that meet the standard tools, while the Java method still means searched from various sources. A solution. "
Bornstein, Niel. May 2002.
Pull Parsing in C # and Java,
Http://www.xml.com/pub/a/2002/05/22/Parsing.html?page=1 (English).
Written, everywhere, although Java's "one written, run everywhere" is very attractive, but most applications written now only for an operating system. There are two technical reasons for this situation: Since the Java framework is limited in the range and richness, developers often use a proprietary class to access the available functions of the target platform. Second, since the incompatibility between the various Java execution procedures continues to bring difficulties to the real cross-platform work, developers must test the code on all platforms you want. Therefore, some developers are half-joked to call Java as "a written, debug". Security .NET's security features are richer. In addition to encryption API, security cookie, and authentication, .NET is still a rich scalable mechanism that can assign different permissions based on code sources to different user clusters. For example, all code from Microsoft is considered safe. All specific resources such as code read / write temporary directory or screens from a particular URL can be allowed or prohibited. In addition, the application can be marked as a need for some authority (for example, you need access to the file system). If there is no such permissions, the application will not be loaded. Since the security check is done when loading, the developer does not have to write a security failure check logic throughout the application. This is to manage the code loaded from Internet or local machines through a new technology called "Code Access Security". Version control .NET Framework has a more powerful version control system than Java. In Java, if two versions of the same class are installed, the Java runtime will simply load the first class found on the class path regardless of which version is. And .NET has rich version support. By performing parallel, .NET can load and perform two or more different versions of the same class at the same time. Each app can choose your own binding mechanism: whether it is binding on a specific version of a class library, on the latest version of the library or is bound to a specific location. In addition, you can apply a rule in different machines to replace or further optimize version control. This version control method also applies to programming languages. For example, in a C # language, the method is not a virtual function by default, so developers must clearly declare that the method of alternative is. This means that the component cannot be accidentally interrupted in the base class. C # does not require developers to clearly declare which abnormalities will cause. If the abnormal list changes, the client code can still run normally. Performance .NET is better than Java is also in depth adjustment of application behavior and performance. The core application build module is designed for scalability and high throughput. For example, in the case where ADO.NET data access is disconnected, more functions can be completed in memory, and these functions require back and forth in the Java Database Connection (JDBC). In addition, .NET application architecture design goals are faster speed. For example, the performance of the ASP.NET web page is much more than Active Server Page (ASP), Java Server Page (JSP), and HTML embedded scripted languages. Compared with the Java platform, .NET is better in terms of single user situation or in multi-user cases. "Microsoft's .NET application performance is significantly better than Java applications. If there is 5,000 virtual users, when there is no cache, the former is more than 10 times faster than the latter; when there is a cache, the former is 1 times faster than the latter. the above."
Veritest. May 2002.
Veritest (r) Benchmark and Performance Testing Microsoft (R) .NET PET SHOP
http://www.gotdotnet.com/team/compare/Veritest.aspx (English). How to migrate Java applications to .NET There are two ways to migrate Java applications to .NET: upgrade them to Visual J # .NET or convert them to Visual C # .NET. As mentioned below, these two methods require different work, each has its own advantages. Since the full version of NDP can only be used on Microsoft Windows, both methods means migrating applications to Microsoft Windows. Although the NDP contains a command line compiler for Visual C # .NET, Visual Basic .NET and Visual J # .NET, we have assumed the developers to migrate the application to .NET using Visual Studio .NET. As mentioned earlier, Visual Studio .NET is the highest efficiency .NET application development tool. Upgrade to Visual J # .NET Visual J # .NET is implemented for the Java language of the .NET Framework, you can get from the Visual J # site (English) of MSDN. J # is developed independently in Microsoft, which compiles the Java language code as MSIL. Visual J # .net includes a Java language compiler, JDK 1.1.4 library and a tool for upgrading the compiled Java bytecode to MSIL (this tool can be used to upgrade the class library to can be used by the .NET application. format). In addition to JDK 1.1.4 libraries, like other compatible .NET language, Visual J # .NET can fully access .NET Framework, which contains designers developed for Windows Forms and Web Forms. Upgrading to Visual J # .NET is the simplest, fastest way to migrate the Java application to .NET Framework. Visual J # .NET has a familiar grammar and class library that developers, so developers can use the original knowledge about Java, and .NET Framework can quickly go up. Application upgrade to Visual J # .NET can immediately bring some benefits: upgrade speed is very fast, developers can start adding new features that the .NET Framework and Microsoft extensions have been extended to the Java language. Use Visual Studio .NET to open a Visual J 6.0 project to activate Visual J # .NET UPGRADE WIZARD (Visual J # .NET Upgrade Wizard). Convert to Visual C # .NET Java Language Conversion Assistant (Java Language Conversion Assistant) can be downloaded from Java Language Conversion Assistant Sites (English). Java Language Conversion Assistant (Java Language Conversion Assistant) converts Java applications to Visual C # .NET applications. Calling the Java API is converted to the corresponding C # code using the .NET Framework. Since this conversion is very complicated, it is not all the Java APIs to be converted. Java Language Conversion Assistant (Java Language Conversion Assistant) can convert 90% of JDK 1.1.4 calls, and the remaining 10% will be labeled in the code. Each question is linked to a topic, guiding which modifications should be made to complete the conversion.
Convert to C # applications get the biggest flexibility: Although transition to C # ratio upgraded to Visual J # .NET slow, because application conversion uses this machine .NET Framework API, this has brought more opportunities. After the modification is complete, the conversion code can be immediately used as Visual J # .NET to utilize the high performance, scalability, security, and version control capabilities of .NET Framework. Unlike Visual J # .NET, Java Language Conversion Assistant (Java Language Conversion Assistant) supports Visual J 6.0 loosening files and directory-based project transformations. Select File from the Visual Studio .NET menu, then select Open, then select Convert (Conversion) to activate the Java Language Conversion Assistant (Java Language Conversion Assistant). Selection between J # and C # decides which compatible .NET's language migration Java application is primarily a personal selection problem. As mentioned earlier, Visual J # .NET and Visual C # .NET compiles to the same MSIL, both languages access the same .NET Framework, providing relatively consistent features. To help you choose, the three main determinants should be considered when choosing to upgrade to Visual J # .NET or convert to Visual C # .NET: Migration Time When the Java application is upgraded to Visual J # .NET, Still Java, the call to the JDK 1.1.4 API is the original. When the same application is converted to C #, the language is converted to C #, the Java API call is converted to the native .NET Framework call. This conversion is very high (often reaching more than 90%), but some modifications are still needed after the Java Language Conversion Assistant (Java Language Conversion Assistant). If the shortened migration time is very important, then Visual J # .NET may be the best choice. Applications that are converted to C # can immediately utilize new .NET Framework than Java platforms higher performance, scalability, and version control capabilities. For applications upgraded to Visual J # .NET, although you can add new features with .NET Framework, it still uses Java data types and Java libraries. If it is very necessary to make the application's architecture utilize the advantages of .NET Framework, then C # may be the best choice. Language For many people, the most important consideration is just a language preference: no matter whether you use Java or use C # development applications. This is mainly a personal choice problem. Visual J # .NET and C # are from C , similar grammar and functionality. For those who have put into java and want to continue using Java, Visual J # .NET may be the best choice. For developers who want to turn to the "native" .NET language of the "native" .NET specifically designed to develop .NET applications, C # may be the best choice. In order to understand the two options, what happens when the application is migrated to .NET. Technical mapping is different from the results obtained by the two migration methods. The following two tables illustrate changes in the composition of the Java project being migrated to .NET. Table 1: Java migrated to .NET components
Java technology upgrades to Visual J # .NET to C # Java Language Java Language C # Language Vectors Does Windows Forms Control JavaBeanjavabeanc # class (BeanInfo and ClassInfo does not convert) ActiveX control does not convert ActiveX control AWT framework AWT Frame WINDOWS Forms WFC Form WFC Forms Windows Forms After compiled libraries, libraries do not convert resource files RESX file RESX file table 2: Migration of a single package
Package upgrade to Visual J # .NET converted to C # com.ms.awtjava.awtJava.awtSystem.Windows.Formscom.ms.comcom.ms.comSystem.Runtime.InteropServicescom.ms.dllcom.ms.dllSystem.Runtime.InteropServicesSystem. ComponentModelcom.ms.dxmedia not upgrade DirectAnimationcom.ms.fx not upgrade System.Windows.Formscom.ms.iocom.ms.vjsharp.ioSystem.IOcom.ms.langcom.ms.langSystemMicrosoft.Win32.RegistryKeycom.ms.objectcom.ms. vjsharp.objectSystemcom.ms.ui not upgrade System.Windows.Formscom.ms.utilcom.ms.utilSystemSystem.CollectionsSystem.Diagnosticscom.ms.wfc.appcom.ms.wfc.appSystem.Windows.Forms System.Globalization.CultureInfo Microsoft.Win32System .Environment.SpecialFolderSystem.Threading System.DateTimecom.ms.wfc.corecom.ms.wfc.coreSystemSystem.ComponentModel System.Windows.Forms.Design System.ComponentModel.Design System.Resources com.ms.wfc.datacom.ms.wfc. dataADODB System.Runtime.InteropServices RDS System.Globalization SystemSystem.ComponentModel MSDASC System.Resourcescom.ms.wfc.data.adodbcom.ms.wfc.data.adodbADODBcom.ms.wfc.data.uicom.ms.wfc.data .uisystem.windows.forms system.datasystem.com.ms.wfc.iocom.ms.wfc.iosystem.iosystem.globalizationcom.ms.wfc.ole32com.ms.wfc.ole32 com.ms.wfc.uicom.ms.wfc.uisystem .Windows.Forms com.ms.wfc.utilcom.ms.wfc.utilSystemSystem.Diagnostics System.Collections System.Runtime.InteropServices System.Resources System.Globalizationcom.ms.wfc.win32 com.ms.win32com.ms.wfc.win32 com.ms.win32 conversion call java.iojava.ioSystem.IOjava.langjava.langSystemSystem.Threadingjava.lang.reflectjava.lang.reflectSystem.ReflectionSystemjava.mathjava.mathSystem.Decimaljava.netjava.netSystem.Net SystemSystem.IOjava.securityjava to PInvoke. Security does not convert java.sqljava.sqlsystem.data.oledbsystem.datetimejava.textjava.textsystemsystem.globalization system.
Components written in different languages Resourcesjava.text.resourcesjava.text.resourcesSystem.Resourcesjava.utiljava.utilSystemSystem.Collections System.Globalization System.Resources System.Configuration compatible with the .NET hybrid migration can easily interoperate with each other, so it can Mixed migration from Java. In a hybrid migration, you upgrade a component of the application to Visual J # .NET to convert another component to C #. The actual examples include: Upgrading the intermediate layer components into Visual J # .NET, and access it from the client that is converted to the C #. You can use the Visual J # .NET binary converter to convert libraries to any format that can be used by .NET language. Targets that do not use automatic migration feature Visual J # .NET and Java Language Conversion Assistant (Java Language Conversion Assistant) are also java languages, JDK 1.1.4 libraries, and Microsoft libraries that come with Visual J 6.0. Some applications also use new Java versions of J2EE, J2SE. These applications often need additional additional modifications when migrating to .NET. These modifications are usually very simple: after migration, most of the application (business logic and JDK 1.1.4) will be perfectly migrated. In the migrated code, the unsupported technique will remain unchanged. You must use similar .NET technology to replace unmoved Java technology to complete the migration. Since .NET provides a larger class than Java, you can often make some major improvements when conducting technical replacement. The migration of the SWING form package is a good example. Migrate Swing Java contains two competitive form packages: Abstract Windowing Toolkit (AWT) and SWING. JDK 1.1.4 provides AWT. Visual J # .NET supports AWT, you can convert AWT to a Windows Form through the Java Language Conversion Assistant (Java Language Conversion Assistant). JDK 1.1.4 can use an additional Swing library, which is part of the J2SE and J2EE libraries. The Swing Form Layout cannot be automatically migrated to .NET. During the migration process, the Javax.swing class in the code remains unchanged, you must replace it with a Windows Form class. To do this, perform the following steps for each Swing form in the migrated application:
Add a new Windows Form to the Migrated App to add a control to the form to obtain the same layout as the original Swing form to copy event logic code from the migrated swing form to a new Windows form. The event handler removes the migrated Swing Form in the application. 2: Strike Swing Forms Windows Forms in Visual Studio provide a richer environment than AWT or Swing, and almost all aspects include Java platforms. The supercoming of the functions that can be found. For example, the Windows form makes the control form layout easier. Layout manager in Java often brings difficulties. Getting the desired form layout needs to understand the layout manager, and even the most basic layout needs to write many code. Windows Forms simplifies form management by providing absolute positioning for all controls. In addition, Windows Forms can easily adjust the form size by relying on and anchors. Referring to the specified control should always occupy a specific area of the screen. Anchor the one or more corners of the form control "nail". Adjust the form to use these "staple" to determine the location of the control. Use back and anchoring usually eliminate complex form size adjustment code. Migrating Swing Forms to .NET is not only very simple, but also improves applications with .NET Framework more abundant classes. Migrating Java Server Page Java Server Page (JSP) and servlet are technologies that create web pages that support Java. JSP provides a script embedded HTML architecture similar to the ASP. The servlet provides a mechanism for the JSP page for the compilation of the HTML code. Both technologies use Java code, providing event-based programming for web pages. JSP and servlets can be migrated to ASP.NET, which has a lot of benefits: ASP.NET is a more powerful technology, which is more than JSP, PHP (PHP hypertext pre-processor), ASP and other interpreted scripts embedded HTML The architecture has higher scalability and performance. However, JSP has not been migrated to the ASP.NET automatic system when writing this article. Microsoft has announced the introduction of JSP to C # ASP.NET (Java Language Conversion Assistant) extension in the second half of 2002. At the same time, it is also considering the conversion of JSP to Visual J # .NET ASP.NET in the future. Walkthrough This section is upgraded from Visual J 6.0 to Visual J # .NET and the conversion from Java to C #. The purpose of the two exercises is to introduce migration technology. Obviously, both migrations are far more than the content introduced here. Alternatively, these two application examples can be migrated using any migration technology. How to upgrade the Visual J 6.0 project to Visual J # .NET This section will take step by step to the Visual J 6.0 application to upgrade the process of Visual J # .NET and .NET. The application to upgrade is the MDiWordPad project. This is an MSDN example included with Visual J 6.0, which can be downloaded as part of the Visual J 6.0 product sample. The functionality of this application is similar to WordPad. It provides features that open and edit multiple text files. It also provides a simple formatting function. These features are provided through the menu or toolbar. Figure 3 is a Visual J version of the MDiWordPad application.
Figure 3: Application written with J MDiWordPad should use Visual J # .NET UPGRADE WIZARD (Visual J # .NET Upgrade Wizard) to Visual J # .NET. Please upgrade as follows: In Visual Studio .NET, select File from the menu, select Open, then select Project. Find the location of the mdiwordpad.vjp project file and click Open. Visual Studio .NET detects that the file you want to open is the Visual J 6.0 project and open Visual J # .NET UPGRADE WIZARD (Visual J # .NET Upgrade Wizard). After reading the introduction text, click Next to enter the second page of the wizard. This page requires the type information of the project you are upgrading. The MDIWORDPAD example is a Windows application, so the default is correct. If you want to upgrade a project is a console application or class library, you should select an option. After confirming that the Windows application is selected, click Next to enter the next page of the Upgrade Wizard. Figure 4: Visual J # .NET UPGRADE WIZARD (Visual J # .NET Upgrade Wizard) Tips Select Project Target Types
For applications that use Active X controls or other COM references, you can explicitly add references to these components on this page. Adding these references can help the Upgrade Wizard find the additional types used in the project. Although even if you don't specify them here, the upgrade wizard can also find and add these references to the project, but now add them to speed up the upgrade speed. MDIWORDPAD does not use any external components, so click Next without doing any changes. Now, the Upgrade Wizard begins to assess the project and upgrade the project file and reference to Visual J # .NET. A status bar and change text will be displayed, prompting the wizard of the current progress. After the end of the process, the Upgrade Wizard will automatically enter the last page. In the last page of the wizard, you can use a checkbox to select whether to view project upgrade reports. Click Finish to display the upgrade report. The upgrade report lists information about applications and upgrade processes. If a problem or loss is found in the project conversion, they will be listed here. This report also includes information about the file added to the new solution to the new solution. Double-click on the file MDiWordPad.java in the Solution Explorer to open it in the Code Editor (Code Editor). By browsing the file, you will find that the source code looks exactly the same. In fact, upgrade a project to Visual J # .NET does not require any form of source code modification, which is required to modify just solutions, projects, and resource files. The content of the source code file itself remains unchanged. Press F5 to run the upgrade application. The application's performance has not changed, you can verify this by editing some text. The application's operation is exactly the same as the upgrade, but it is now running on .NET. Figure 5: Upgrade version of MDiWordPad, running on Visual Studio .NET, using .NET to upgrade the application to Visual J # .NET is a very simple process. The Upgrade Wizard helps you provide the information you need to upgrade and there is no change in the source code of the project after the upgrade. Upgrade to .NET is an extremely fast and simple process via Visual J # .NET. Net is an extremely fast and simple process. Since both have similar language and class libraries, upgrade to Visual J # .NET is the fastest way to migrate J projects to .NET. How to convert Java projects to C # This section converts a step-by-step process to the process of the Visual J 6.0 application to C # and .NET. The application to be converted is a simple end-user purchaser called Island Book Sales. The application demonstrates all aspects of the conversion (AWT to Windows Forms, JDBC to ADO.NET, Java to C #). It also demonstrates some issues that need to be solved after conversion. Island Book Sales has two forms. The first form shows the list of books available for sale. The book provided is included in an Access database, you can read the database using JDBC. Users can choose the item to purchase and put it in the shopping cart. The user's shopping cart is displayed in the second form. The form enables users to cancel or purchase items in the shopping cart. Figure 6 is an application in operation. Note: You must register the database bookstore.mdb as ODBC DSN to run the BookStore application.
Figure 6: Island Book Sales Application The following is the steps required to convert an application to C # and .NET:
On the File menu in Visual Studio, click Open, and then click Convert. This will launch the Conversion dialog. After selecting the Java Language Conversion Assistant, click OK, start the Java Language Conversion Assistant (Java Language Conversion Assistant). Although the original application is written in Visual J , this example is considered a directory-based conversion. Select a directory-based conversion option in the second page of the wizard, then click Next. In the third page of the Java Language Conversion Assistant (Java Language Conversion Assistant), select the directory containing the application source code, and then click Next. The page 4 of the wizard requires you to enter some information about the application. Type "BookStore" as a project name. Other two options use the default value, and then click Next. Figure 7: Providing information about your project Now, Java Language Conversion Assistant (Java Language Conversion Assistant) Ask where to write the converted project file. Select the directory you want to use and click Next, let the Java Language Conversion Assistant (Java Language Conversion Assistant) created a directory when necessary. Click Next again to start the conversion. The transfer end is over the wizard. Click the Close button to close the wizard. Press SHIFT F7 to open the form designer. Note that the form and its components can be seen in the designer. Java Language Conversion Assistant (Java Language Conversion Assistant) converts AWT components to Windows Forms. You can use the Windows Form Designer to view the converted form. Figure 8: The AWT frame is converted to a Windows Form
Select Task List from the View menu. You will see several upgrade instructions in the converted file. These issues must be resolved first. (If you now generate and run the application, you will find that the application can appear but no data.) Double-click the first annotation in the task list, which will move the cursor through the retrievedata () method. The first error. This method is responsible for querying the database and returning information about available titles to the application. Browse this method code will find that the JDBC call is converted to ADO.NET calls. This code must be run correctly after you have necessary modifications. In Retrievedata, the first annotation UPGRADE_TODO said that the format of the Class.Forname parameter has changed. This note is used below the JDBC driver in the original code, but does not have to do this for ADO.net. Please delete this conversion instructions and the following lines below. The next conversion comment tells you that the connection string format in ADO.NET changes. If you already know the new connection string format, enter it into the declaration of the variable URL. You can also write strings using tools in Visual Studio .NET without having to remember the format of the connection string. Press SHIFT F7 to open the form in the designer. From the Toolbox's DATA (Data) tab, drag an OLEDBCONNECTION object onto the form. In the Properties window, click the drop-down list of the Connectionstring property and select New Connection. This will display the Data Link Properties dialog to help you specify a database connection. The database that saves the information provided is an Access database. When reading data from an ADO.NET Access database, you can use the Microsoft Jet 4.0 OLE DB provider. In the Data Link Properties dialog box, click the Provider tab to select the data provider, then click Next. Find the .mdb file of the sample database, then click OK. The CONNECTIONSTRING attribute of DataAdapter now contains the correct sample database connection string. Copy this string and paste the declaration of the URL variable of the RETRIEVEDATA method. Add a @ symbol before the string to tell C # should be explained by literally. After the modification, the declaration or URL should be as follows: String Url = @ "provider = microsoft.jet.Oledb.4.0; data source = .. / .. / db.mdb;"; now, this upgrade problem has been resolved, you This conversion comment can be deleted. The following two upgrade comments do not affect this application, you can ignore or delete them. Press F5 to run the app. The app will be loaded, you can see that its working status is the same as the original application. We convert this two-story app from Java into C # in easiest way. Although the application is small, the method described above is applicable to all conversion items. Small junctions Java to Visual J # .NET and Java to C # migration tools can simply effectively migrate the Java application to .NET.