picking a winner: .net vs. j2ee
although both frameworks stand on a foundation of programming languages, object models and virtual machines, they are strikingly different when you consider the design goals of their runtime environment.
the java 2 enterprise edition (j2ee) framework has captured significant mindshare among online application developers and their organizations, as a powerful, portable and widely-supported application development environment. microsoft's announcement of .net (dot-net) has captured the attention of just as many, since it represents the future direction of all things microsoft, from desktop applications like microsoft office to development tools like visual studio to back-end servers like sql server, and everything in between.
opinions on the ultimate outcome of this framework competition range far and wide—zealots on either side of the "demilitarized zone" claim emphatically that either sun and j2ee or microsoft are doomed to fail. some of the more balanced analysts predict a near-term stalemate, with j2ee and dot-net eventually claiming a roughly equal share of the application development market. this prediction seems the most sensible, given the two forces facing off—j2ee with a significant amount of development inertia and a broad array of tool and application vendors behind it, and dot-net with the marketing influence of microsoft fueling its spread.
regardless of the long-term result, it seems unavoidable that technology managers, strategists and software developers will have to contend with both of these frameworks for some time to come, and i've tried to provide some guidance to the development community around this "framework divide." whether you're part of an organization committed to either j2ee or microsoft platforms, trying to assess the costs and benefits of sticking with your current framework, jumping to the other or attempting to support both; or if you're an organization about to venture into a development effort and attempting to pick the most suitable path, i've attempted to lay out the two frameworks as clearly and unambiguously as possible.
(half-)sisters under the skin
it's important to acknowledge that despite what the best marketing minds at sun and microsoft might lead you to believe, dot-net and j2ee are surprisingly similar from a pragmatic standpoint. both offer a server- and client-side component model for assembling enterprise applications, apis that allow you to create both fat and thin user interfaces for these applications, and specifications and corresponding apis that allow you to access critical services such as transactional data sources, directory services and remote objects.
at a lower level, the two frameworks are both based on a virtual machine architecture aimed at portability (though the type of portability each strives for is a critical difference between the two). also, j2ee and dot-net are comparable in some areas in terms of feature support and architecture.
don't know beans?
when j2ee was introduced by sun, it subsumed, to a large degree, the javabean and enterprise javabean component models. javabeans are the meat-and-potatoes java components, with well-defined properties, event-handling provisions, persistence through java serialization and introspection, in addition to all of the basic services provided by the java runtime environment, like memory management, "sandbox" security and the core java apis. enterprise javabeans are the distributed equivalent: remotely-accessible components that operate within an environment that provides application security, distributed transaction support, richer persistence management facilities, life cycle management and resource pooling.
the dot-net framework, meanwhile, subsumes microsoft's workhorse com and com+ component models. these component models are replaced, in a sense, by the new component architecture of the dot-net framework. the common language runtime (clr) now provides "sandbox" security and basic services like garbage collection, similar to the java virtual machine, which were not available previously in the com and com+ environments. it also extends the component model itself with features such as multiple interface inheritance, extensible meta-data and a new delegate model. so the clr defines a new, richer component model, which com and com+ components can be mapped into, and which is accessible by com and com+ components, but it is separate and distinct from com. this has fueled doubts as to whether com and com+ will continue as "first-class" supported programming models in microsoft's product line (see don box's article, "house of com," in the december 2000 issue of msdn magazine on how the new clr environment differs from the com environment).
microsoft's support for components has a long history, driven in part by the fact that it provides the principal visual ide for microsoft developers (visual studio and its predecessors). microsoft has had the luxury of taking its component model through several iterations of improvements, despite the subsequent churn inflicted on its developers. java's component model inherited the institutional learning that came before it, but improvements to the java component model are handicapped to some degree by its dependence on the java language and the open nature of java's evolution.
the skinny on fat clients
for "fat" gui clients, j2ee offers the java swing api, with a palette of standard gui javabean components that can be assembled programmatically, or pulled into visual gui design tools like webgain (formerly symantec) visual cafe, borland jbuilder, ibm visualage for java and so on. for thin-client development, the servlet and javaserver pages (jsp) standards provide ways to build hmtl, wml, xml and other thin interfaces on top of a java middle tier. java servlets and jsps are supported by a number of application server vendors, both commercial (such as bea weblogic, iplanet, ibm websphere and silverstream), and open source (for instance, apache's jakarta project, enhydra and resin).
in the past, microsoft has offered "fat" client support through its microsoft foundation classes (mfc) api, but dot-net offers a new set of components: windows forms. windows forms fill the same functional role as mfc, but they are plugged into the new dot-net runtime framework and component model. similarly, on the thin-client front, asp.net is the dot-net successor to active server pages (asp): functionally, it fills the same role as a thin-client (hmtl, wml or xml) paradigm for applications, but asp.net pages participate in the new clr. in this case, that means that code snippets and component references can be added to pages using any clr-compliant language, and asp.net pages are compiled into the il-based clr runtime, rather than interpreted, as asp pages are.
data sources and directory services
j2ee and dot-net both support, in different ways, a few strategic apis and services such as access to data sources and directory services, and general-purpose xml support for applications. access to data sources within the java environment is handled through jdbc, an rdbms-independent java specification for interfacing with relational databases. specific vendor rdbmss are supported through jdbc drivers, which are available for all of the popular commercial and open-source database options.
jdbc is a fairly low-level api, in that it models database access in terms of connections, statements and resultsets. jdbc 2.0 and its standard extensions add useful services such as connection pooling and support for open xa distributed transactions—j2ee 1.2.1 (the current industry-supported version of the standard) doesn't mandate these extensions, but j2ee 1.3 (currently in development) does. higher-order data access services are provided within j2ee by entity ejbs and the persistence management services of ejb containers. commercial third-party object-relational tools, such as sun's java blend or webgain's toplink, are also available, but aren't strictly part of the j2ee framework.
directory services are accessed in java using java naming and directory interface (jndi), and a different object model involving names, contexts and attributes, which represent name-to-object mappings within a naming or directory service, and meta-data attributes associated with these objects within a directory. access to various types of directory services, such as ldap, novell nds, nis, and more recently with dns and directory services markup language (dsml) xml sources, are accomplished through jndi providers, which are analogous to jdbc drivers.
microsoft's data-oriented services and apis have had a bumpy past. early efforts stemming from ole and odbc led to data access objects (dao), which led to the activex data objects (ado) api. ado sits as a peer to both jdbc and jndi—data access is modeled as connections, commands and recordsets, and ado provides unified access to both relational data sources and directory services. ado has offered some features, such as record navigation and "offline" rowset access, that weren't available in jdbc until the 2.0 version of that specification. on the negative side, ado rides on top of the com-based ole db and odbc interfaces, which severely limits its interoperability and scalability.
in recognition of this, dot-net replaces ado with ado.net. (microsoft's earlier term for the dot-net data access components was ado+; it's unclear whether this change in nomenclature will stick or not, but in this article i'll use ado.net, instead of ado+, for simplicity). ado.net is a new data access api that replaces the com-based marshalling of data with xml data transmission from data source to the ado.net data component. the api model is essentially the same—recordsets are replaced with datasets, commands are replaced with datasetcommands and so on. in the dot-net framework, there is also the new system.directoryservices package, which provides interfaces specifically designed for accessing directories. the big difference in ado.net (from both its predecessor, ado, and its competing apis, jdbc and jndi) is that the data transmission format from source to dataset is xml, which allows ado.net to treat anything that emits xml in the ado.net schema as a data source. contrast this with jdbc and jndi, where the api allows the driver or provider to use whatever exchange protocol is appropriate (for example, an oracle driver can use a jni interface to the oci libraries, or it can implement the sql*net or net8 protocols directly in java). it would be possible to implement a jdbc driver, for example, that communicates with a data source using xml, which would open up the same types of portability potential that ado.net promises. but the jdbc api doesn't expose this potential data access paradigm to the application layer directly—you would still need to interact with the data in the form of resultset objects.
xml is a more accessible and portable data exchange protocol, and support for it within ado.net is good for developers and vendors alike. it opens up interesting possibilities in terms of exporting virtual "data sources," or components themselves being able to serve as a data source for each other. however, in practice, high-volume data exchanges would probably be better served by a more compact, efficient protocol dictated by the data source engine. xml is well-structured and humanly readable, but it's rather fat as data protocols go.
general-purpose xml support
both java and dot-net provide the now-expected basic xml support, which includes apis for document object model (dom) generation and parsing. the java api for xml processing (jaxp) is a java extension api that supports dom and sax (simple api for xml) models for xml sources, and provides a plug-in architecture for different parsing engines. note that i didn't mention j2ee here. j2ee 1.2.1 doesn't dictate that an xml api be present in the environment—a requirement that wasn't added until j2ee 1.3. of course, this is largely academic, since virtually any java application server has already, or is planned to have, a java xml api and parser bundled. but the lack of a requirement for an xml api in the framework is a sign of the level of xml adoption present in j2ee.
this isn't to say that sun and the java community have been slouches in the xml arena. quite the contrary. xml support in the java environment is plentiful and timely: new xml-related standards are almost ubiquitously implemented in java, and typically before other languages. more recently, sun has announced plans to define a standard java api for xml messaging (jaxm), which uses ebxml messaging to provide xml request and response services for the java environment, and the java api for xml data binding (jaxb), which uses both xml schema and xml binding to define a standard java api for the marshalling and unmarshalling of java objects into and out of xml document models. at the time of this writing, these apis aren't formal elements of the j2ee framework and plans to incorporate them into its application, ui and data access services haven't been announced.
microsoft has also embraced xml vigorously. at the ground level, the company provide its msxml api for dom and sax parsing and xml generation. more importantly, xml is an underlying feature of dot-net at many layers. we've already discussed how ado.net uses xml for its underlying data exchange protocol. in general, dot-net components use xml by default for data representation of various kinds. an especially interesting aspect of the dot-net architecture is the ability for dot-net web services to easily export an xml interface, in the form of soap, across the network. (see my article on the o'reilly web site about the pros and cons of soap as a data exchange and rpc mechanism.)
this provides for some interesting possibilities: clients of these soap-accessible web services can take many forms, from client browsers to mobile devices to other web services (implemented in dot-net or in other frameworks). again, the practicalities of having an xml parser in the mix, and the subsequent reduction in transaction rates, may keep you from using soap interfaces to dot-net components in high-volume, high-scalability situations. but it's still nice to know that level of flexibility is there if you need it.
where the code hits the road
formal deployment schemes are an attempt to reduce the confusion of loosely-defined dependencies between libraries, classes and media assets sitting on local and remote file systems, and "component versioning hell."
in j2ee, applications are composed of modules, which are collections of interrelated components, which come in three major flavors: web components, ejb components and java "clients" (which includes both application clients and applet clients). each type of component is managed at runtime by a corresponding container type that provides it with services and apis (for example, web components have the jsp and servlet apis available through their container, while ejb components have access to the full ejb api and its security, life cycle and transactional services).
the dot-net environment proposes an analogous application assembly and deployment scheme. dot-net applications are built up from assemblies, which contain exe and dll files that contain compiled dot-net components. assemblies can also contain other required resources, like media assets, support code or classes, and so on. assemblies can be packaged in the form of windows installer files (.msi), windows cab files (.cab), or they can be dynamically downloaded by a web application (similar to the way java applet context and browser plugins are currently downloaded). dot-net assemblies can be deployed as standalones, or they can be grouped into an application.
dot-net defines an xml-based configuration scheme, where interassembly dependencies, security settings and resources are defined. creation of dlls, exes, resource files, configuration files and so on can be accomplished using command-line tools provided in the dot-net framework sdk, or graphically through the upcoming dot-net version of microsoft visual studio (both of which are available in beta form at the time of this writing).
j2ee also makes use of xml deployment descriptors for modules and applications, in order to provide configuration information to the runtime j2ee environment. this configuration information includes a manifest of the contents of the module, component dependencies, details about required external resources, and security-related roles and access rights. although the core java environment supports command-line editing, a number of j2ee tool and application server vendors provide deployment tools that make point-and-click work out of the generation of xml deployment descriptors and the assembly of javabeans, servlets, jsps and ejbs into jar files, and the actual deployment of these modules and applications into running application servers, local or remote.
this leads to another distinction between dot-net and j2ee application deployment. deploying a given j2ee component within a particular j2ee server often involves, in addition to modifying the deployment descriptors, the generation of vendor-specific support classes for your components. this complicates matters with regards to tying application servers to integrated development environments. dot-net, as a single-vendor platform and framework, doesn't have to concern itself (or you) with this issue, since microsoft provides both the development and deployment tools.
dot-net also doesn't make the same clear distinctions between different types of assemblies as j2ee does. there are clear application types (web-based asp.net applications where asp pages interact with back-end clr components, or windows forms applications where the gui is desktop windows components interacting with clr components), but the components themselves aren't categorized by service-levels—it's assumed that all components can have access to all of the services and apis of the dot-net environment. since microsoft is the sole provider of dot-net implementations, it doesn't have to include such multivendor considerations in the architecture.
critical differences
i've outlined some subtle differences between today's dot-net framework and j2ee framework, and so far the two frameworks have been fairly comparable on a pragmatic, functional level. however, there are critical differences between the two frameworks at a number of levels.
dot-net and j2ee both stand on a foundation of programming languages, object models and virtual machines. the most striking difference between the two frameworks is the design goals of their runtime environment and how these support very different programming and deployment schemes. the cliché developing in the community around this point is that "java is language-specific and platform-independent, and dot-net is language-independent and platform-specific." this cliché is in many ways an oversimplification since numerous j2ee implementations aren't entirely cross-platform. microsoft has made some preliminary attempts to make dot-net cross-platform, such as submitting the clr specification and the c# language to the european computer manufacturers association for public standardization, as well as announcing versions of the clr for a variety of non-pc devices, including the linux platform (if there is a market for it). the cliché remains fairly accurate, though, because the j2ee specification is fundamentally cross-platform and the full dot-net story incorporates windows as a central piece.
figure 1. competing development models
java's unified programming environment is platform-independent; xml-enabled dot-net is language-independent.
j2ee is a framework that evolved out of the core java environment, which is founded on the java language, the java virtual machine (jvm) and the java core apis. the java programming model calls for class descriptions written in java to be compiled into platform-independent bytecodes as defined by the java virtual machine specification (figure 1). these bytecodes are then interpreted and executed by an implementation of the jvm targeted for the particular platform at hand—solaris, windows, linux, aix and so on. the jvm defines and provides a standard runtime environment that provides memory management and security. alternatively, java code (or the resulting java bytecodes) can be compiled to a native executable for a specific platform, or runtime compiled to native code by a just-in-time (jit) compiler. so, development in j2ee is meant to be done in java, resulting in class bytecodes that can be run on any platform with a jvm or a java-to-native compiler. access to objects and components written in other languages is possible, using the java native interface (jni) and corba, but these are largely ancillary to the core development and runtime model. in both cases, these are also rather complicated apis to master, which in part hinders their broad adoption.
microsoft's dot-net framework is based on its common language runtime (clr), which is composed of a specification for language-independent intermediate language (il) code and a runtime that provides memory management, security and so on. this may seem analogous to the java runtime architecture, but the difference is that code targeted for the dot-net framework can be written in any language that supports the clr's core component model. a compiler must be developed which compiles the code into il—once there, the objects and components can run side-by-side and interact with components written in other languages and compiled into the clr. blocks of il code are jit-compiled into native windows code, or your whole application and assembly can be compiled once into a native windows dll or exe as shown in figure 1.
the interesting thing about this difference in the two frameworks, and the reason it's a critical differentiator, is that this relatively low-level design feature strikes right at each framework's strategic direction. java is designed to be a unified programming model that is platform- independent. sun would say (and has, in different words): once you have everything in the java environment and the java virtual machine, you gain tremendous flexibility in choosing tools and off-the-shelf components at development time, platforms at deployment time and interservice connections and live code sharing at runtime.
dot-net, on the other hand, is a unified platform (windows) that is language independent and deeply xml-enabled. microsoft might tell you: once you have everything in the windows platform and the common language runtime, you gain tremendous flexibility in the ability to choose the development language that's right for you at development time, and in interconnecting components and web services at runtime, either at the component and object level using the clr, or in a looser sense using soap and xml. and deployment time decisions are simplified because everything is integrated into the windows environment.
we'll return to the xml issue in a moment, but the language and platform distinction is critical. and there are chinks in the armor on either side of this architectural battle.
java's true potential is realized by a development team and its surrounding organization only when a critical mass of development (or all of it) is done in java. if, for some reason (legacy system, third-party requirements, component availability), a subset of a given system falls outside of the java environment, things get complicated, and you have to turn to corba or jni or other ways to bridge the gap.
this language-centric approach is also limiting strategically. it's easy to imagine some powerful improvements to the java core environment that would be best accomplished by making changes to the syntax of the java language, and these changes are very difficult to make because there is a vertical dependence, from the jvm to the j2ee application services, on the fact that everything happens in java bytecodes.
a good example is the explicit declaration of properties on javabeans. given java's preexisting syntax, the javabeans specification was defined so that component properties are implicitly defined by the presence of methods of a particular signature (setxxx and getxxx) on the bean's java class. a better solution would be to have a way to explicitly declare properties, keeping the method namespace independent. doing this, however, would require altering the syntax of the java language to include a scheme for declaring properties explicitly, and changing the java language itself would cause changes to ripple upwards through the apis and specifications, and downwards into the jvm in some cases. given the success of java and the number of vendors coding to its specifications, this would be a herculean task in concensus-building and making provisions for migration and backwards-compatibility. ironically, it's analogous to the woes that microsoft faced when it attempted to eliminate the dos kernel from its os.
microsoft dot-net, on the other hand, realizes its true potential only if it's necessary and prudent to create and manage components developed in multiple languages, and do it all on windows. on the face of it, being able to use the language of your choice (from the set that supports msil compilation, that is) seems like a valuable possibility—if i don't know c# or c++ or java, i can stay productive and write code in what i know, instead of starting a new learning curve. this is appealing for both developers and managers alike, but the clr achieves somewhat less than this in reality.
you can't write standard, ansi-compliant c++ or standard cobol or eiffel and make it work in the clr sandbox. to make your code accessible to other clr components, you have to write your code in managed extensions to c++, eiffel# or cobol#, which are syntactic variants of the original languages that they share names with. these variants include syntax extensions that are required in order to provide all of the component meta-data that the clr requires, which can't be supported by the standard language. this means two things: there is still a learning curve to be climbed (although probably not a large one) in order to program to dot-net's clr, and the code that you write for dot-net won't be understood by the standard compilers or interpreters for these languages.
as an example, the following is a class written in managed extensions for c++:
#using <mscorlib.dll>
using namespace system;
namespace sdexample {
__gc public class simplecomponent {
private:
string* mname;
public:
simplecomponent() {
mname = new string("anonymous");
}
__property int get_name()
{ return mname; }
};
};
the red areas show the syntax elements that aren't standard c++. the "#using" preprocessor directive declares a windows dll that this component requires, the "__gc" tag marks this class as a clr component eligible for memory management services, and the "__property" tag declares a property of the component. a developer still needs to learn the new component model of the clr, and learn how the model impacts her "home" language, before she can write code for dot-net. and ansi-compliant third-party c++ compilers and tools won't understand this c++ variant—only dot-net-enabled compilers can be used. the extensions to c++ that i've shown here are fairly minor, since c++ is a contemporary object-oriented programming language and has a large overlap with the object model of the clr. similar extensions were required to eiffel to create "eiffel#" (see the article "eiffel on the web: integrating eiffel systems into the microsoft .net framework" in the msdn library). other languages, such as the non-object-oriented cobol, will require more significant extensions in order for their compiled code to be accessible as first-class msil components.
xml services
j2ee has a lot of catching up to do on the xml front. dot-net uses xml and provides xml services from top to bottom. ado.net uses xml for data transmission, msxml provides general-purpose xml parsing and generation capabilities for applications, and web services can be exported as soap interfaces. in addition, microsoft released a beta of its xml for analysis specification in october 2000, which defines a soap-based protocol for remote method calls and data exchanges over http. all in all, dot-net is making it very easy for developers to take advantage of xml in innovative ways.
to its credit, sun has been very active in the xml space, with the jaxp specification released in march 2000, then required in the j2ee 1.3 specification proposed final draft, which was released in october 2000. and in december 2000, sun announced the java api for xml messaging (jaxm) and the java api for xml data binding (jaxb). as of this writing, however, xml remains at the periphery of the j2ee framework (basic sax and dom apis, and the use of xml for deployment descriptors). the parsers are there, and standard java xml messaging and data binding apis are in the works, but they need to be integrated seamlessly into the j2ee environment. xml messaging via jms seems an obvious next step, exporting ejbs with xml messaging interfaces would also be very cool.
strategic practicalities
where does all this leave us in terms of enterprise application frameworks? well, at a high level, we're all in a much better place—microsoft is fixing its web application environment, making it a peer (at the very least) to j2ee, so when dot-net arrives we'll have two very capable development frameworks to choose from. perhaps more importantly, microsoft has pushed the envelope in terms of application services (especially xml support), and the company's put a new twist on portability with the language-independent clr. these efforts have spurred sun's efforts around xml support (as mentioned previously with it's recently-announced jaxm and jaxb efforts), and in other areas as well. and both sun and microsoft, through all their bickering, have gotten the developers and technology strategists talking about new perspectives on enterprise development.
but at the end of the day, you have to decide which framework to adopt. given all the technology issues i've discussed, the path to a decision is fairly simple. in any significant development effort, whether you're a software product vendor, a consultant on a custom development engagement, an internal developer of application service provider (asp) offerings, or building the internal enterprise infrastructure for an organization, you need to decide who your target customers are (today and in the future), what platforms you need to support from a strategic level (today and in the future), and what framework provider you want to partner with to push forward (today and in the future).
if you have the luxury of only supporting the windows platform (with respect to both customers and internal development needs), and if you feel microsoft is the right partner (for development tools, servers, administrative systems and so on) for your organization, then you have an easy decision indeed. alternatively, if you have the luxury of defining a web development practice based on a single language, and can't say with finality that microsoft and windows can be your sole vendor and platform, then you have an equally easy decision to make. conversely, if you face the strategic need to support (or standardize on) unix and other non-windows servers, or if you want to leave your options open in other areas (tool vendors, application servers, component vendors and so on), then jump on the j2ee bandwagon. alternatively, if supporting development in multiple languages is a strategic need of yours, and you can live with a single platform and tool vendor, then use dot-net.
of course, very few groups or organizations find themselves in any of these neat compartments, but hopefully these examples will serve as markers on this slalom course. perhaps we will reach the day when enterprise systems crafted in either of these frameworks can be easily and seamlessly integrated with each other. until then, choose your steed wisely and charge onward—there is an interesting road ahead either way.
国内最大的酷站演示中心!