站内搜索: 请输入搜索关键词
当前页面: 图书首页 > NET For Java Developers Migrating To C#

NET For Java Developers Migrating To C#

[ directory ] Previous Section Next Section

3.1 Programming Platforms (.NET and Java)

With the advent of C# and Java, programmers discovered a new term: programming platform. Programming platforms are now becoming as relevant as the languages in which you program.

The bottom line in providing platforms such as Java and .NET is to make it easier for the programmer to develop enterprise applications. Enterprise applications tend to be complex because they encompass several components (or subsystems) running on various operating systems under various runtime conditions. An enterprise application that is written from the ground up will directly interact with external code through the following:

  • Components or subsystems (such as databases and graphics)

  • Operating systems (such as Linux and Windows)

  • Runtime conditions (such as hardware, available memory, processors, and server nodes)

If you program from the ground up, your application will directly interact with any of these three sources of external code. Any changes made in the external code would require you to rewrite your application. To avoid having to change your application when external code changes, you need a piece of software that sits between the external code and your application and handles the changes made to the external code. Programming platforms provide this extra level of indirection (and insulation).

Platforms also abstract out routine enterprise tasks and package them into high-level, easy-to-use application programming interfaces (APIs). Routine enterprise tasks can consist of accessing databases, messaging, e-mailing, parsing XML, networking, supporting telephony, maintaining advanced GUIs, running Web applications, and so on. Platforms provide basic infrastructure services that developers can leverage using the language API.

Both C# and Java offer a level of sophistication in programming that is important if you want to implement enterprise applications rapidly. These two languages provide a one-stop, high-level API for doing myriad enterprise-level programming tasks. However, the API is merely an abstraction provided to the developer to interact with the platform; it is the platform that translates the high-level API calls to the low-level system calls.

C# runs on the .NET platform, whereas Java runs on the Java platform. Note that "Java" is used to refer to the platform as well as the language.

3.1.1 The Java Platform

Sun Microsystems has reorganized the Java platform into three main categories:

  1. J2SE: The Java platform Standard Edition targeted at desktop machines

  2. J2ME: The Java platform Standard Edition targeted at handheld devices

  3. J2EE: The platform for developing large-scale, server-side enterprise applications typically deployed on load-balanced server clusters

Although it's somewhat of a simplification, you can think of J2ME as a subset of J2SE and think of J2SE as a subset of J2EE. J2EE is a Java-based technology stack built on top of J2SE, and J2EE provides development and runtime tools used by developers to build enterprise applications. The latest J2EE technology stack (J2EE 1.3) consists of the following components: JavaServer pages (JSP), servlets, Enterprise JavaBeans (EJBs), Java Messaging Service (JMS), Java Connectivity Architecture (JCA), Java Naming and Directory Interface (JNDI), and Java Management Extensions (JMX). Although Java Database Connectivity (JDBC) and the HotSpot VM are defined in the J2SE stack, they are also an integral part of the J2EE stack.

It is important to note that J2EE is a platform specification and not a product. Java programmers get to pick from a wide variety of vendors that sell J2EE application servers. These servers are products built on top of the J2EE specification.

3.1.2 The .NET Suite

As indicated in Chapter 1, the term ".NET" covers a lot of ground. Unlike J2EE, which is a set of specifications, .NET is a suite of products (although some parts of .NET have been ratified as standards). The suite consists of the following:

  • Smart client software that runs on handheld devices, PDAs, and embedded systems.

  • XML Web services, which are used for integrating applications. There are commercial implementations of these Web services. For example, MapPoint is a Web service for providing mapping and driving directions in applications.

  • Enterprise servers, such as BizTalk and SQL Server.

  • Enterprise development tools such as Visual Studio .NET and the .NET Framework. These consist of framework classes, the CLR, ASP.NET, and managed code.

As a C# programmer, you are concerned mostly with the .NET Framework.

As mentioned earlier, both Java and .NET equip you with tools to develop an enterprise application. A somewhat routine and ubiquitous enterprise application is any nontrivial Web-based application (such as a company intranet, an e-commerce site, or a Web-based collaboration tool).

An application typically consists of three layers: the presentation layer, the business logic layer, and the data layer. The next section compares the components of J2EE and the .NET Framework that enable you to build the three layers.

3.1.3 The Presentation Layer

The J2EE specification provides for servlets and JSPs for generating dynamic HTML. The servlets and JSPs are run by servlet containers. These containers provide support for maintaining session state, security, and configuration. Tag libraries are used to make JSPs more readable to HTML coders.

ASP.NET runs Web applications using Microsoft's Internet Information Server (IIS). ASP.NET includes facilities for managing session state, security, and HTML generation using ASPX. You can match server-side Web controls using custom ASP tags. Web controls encapsulate reusable user interface logic and provide many advanced features to ease Web programming.

3.1.4 The Business Logic Layer

There is no standard definition for the term "business logic," but anything that encompasses common enterprise computing tasks梥uch as processing transactions, creating XML Web services, or calling methods on distributed remote objects to execute business rules based on triggered events or messages梬ould fall under this layer. Let's look at some examples.

Transactions

J2EE application servers support manual and container-maintained transactions through EJB. In .NET, transactions can be manual or automatic. Manual transactions can be error-prone but give finer control, whereas automatic transactions ease development.

Calling Remote Objects

Execution of business rules based on certain events or triggers is usually wrapped in server-side components such as EJBs (Java) or JMS queues. EJBs are distributed components, and JNDI provides location transparency in identifying EJBs for executing specific business rules. All calls are made through interfaces. In practice, application server vendors tend to optimize the distribution and clustering of EJBs. In this way, method calls usually end up within the same virtual machine instance, thereby avoiding out-of-process method calls.

With .NET remoting, developers can call remote objects distributed across application domains, processes, and machine boundaries. In .NET you can't automatically decide to distribute your objects as you can in J2EE, because you pay a price in network latency when you do so. In .NET, developers employ remoting to increase security and ease maintenance but not to improve scalability; you usually add Web servers for that task.

XML Web Services

By downloading and installing the Java Web Services Developer Pack from http://java.sun.com, you can begin creating Web services. Sun got on board the Web services bandwagon a little later than Microsoft, and that can be seen in Sun's current support for Web services. Microsoft placed XML Web services at .NET's core, and it shows. .NET contains the latest accepted XML Web service standards.

3.1.5 The Data Layer

The bread and butter of any enterprise application is data, which typically is stored in relational database management systems such as Oracle or Microsoft SQL Server.

Java has abstracted out the raw SQL calls to any database into a wonderful abstract layer called JDBC. The JDBC API provides everything you need to access an enterprise API. The API is used to interact with a JDBC driver, which is the pipeline through which your SQL goes to the database server. J2EE supports two approaches to accessing this data. One is through bean managed persistence (BMP), which essentially uses the JDBC driver to make the raw SQL calls to the underlying database. In the second approach, container managed persistence (CMP), you use object relational mapping to map objects to database tables, thereby providing automatic persistence to the database without needing to generate the raw SQL.

With the .NET Framework, developers can access a variety of data sources, including XML, through .NET's ADO.Net classes. ADO.Net includes data providers that let you connect to a database and execute commands. Developers can also transport data over the Web using XML Web services, or across process boundaries using .NET remoting.

    [ directory ] Previous Section Next Section