.NET Framework For Java Programmers
Author: Ashish Banerjee
After reading this article Java programmers should be able to decipher and de-jargonize the .NET architecture and relate it with the proposed ECMA standard.
Java programmers and system architects.
This article outlines Microsoft's proposed standardization of .NET framework in ECMA forum as CLI (Common Language Infrastructure), but the Microsoft documentation refer this as CLR (Common Language Runtime). The CLR and JVM are compared with respect to market forces which shaped the CLR definition. Components of CLR are examined followed by details of Microsoft's implementation of the CLR as the .NET framework.
All along .NET framework is compared with Java architecture.
The material is derived from author's own experience with Java since early 1996, Microsoft's MSDN site and standard documents from sites like ECMA and W3C.org.
.NET framework is the Microsoft's answer to Java commune's objections to \"
\" of Java.
Microsoft introduces a new language C#, designed by the Visual J++ team. But in the process it has done away with DCOM and also have changed it's flagship language Visual Basic.
In a nutshell, .NET constitutes presently of three compiled languages C#, VB.NET and C++, a Java like runtime virtual machine environment, five execution containers hosting this runtime, namely: ASP.NET, Windows Shell, VBA scripting host for Office suite, Visual Forms container and IE (Internet Explorer). Much like Java it contains a rich set of API and lib.
Enhancements over Java framework include use of SOAP (Simple Object Access Protocol) for remoting. Version and security scoping using concept of Application Assembly (described later). A Common Type System is introduced for making mixed language programming easier. For example a VB component can inherit from a C# class.
In longer term Java and .NET will converge and therefore an overview of the new framework is presented here from Java programmer's perspective.
Comparing CLR with JVM
The .NET framework's Common Language Runtime (CLR) is much similar to Java Virtual Machine (JVM), in terms of garbage collection, security, just in time compilation (JIT).
However, the fundamental difference arises from the variance in perception of the Sun's Java design team headed by James Gosling and that of Microsoft's C# designers spear headed by Anders Hejlsberg
Sun viewed the Internet as an heterogeneous network consisting of multiple operating systems. Thus Sun had to design the GUI as the least common factor, supportable by all such platform. This was also the major reason of Java's failure in client side applications. Java has been successful only on server side where there is no great need for GUI.
Having failed at client side desktop application arena, Sun is now targeting Java to server side applications market, which is dominated by Unix and Linux flavors having approximately 60% of the server market, the rest 40% rests with Windows NT.
But this view was not conducive to Microsoft, which holds about 90% of client side desktop market. Microsoft wanted to provide a window centric Internet development platform. Thus it added a few Window specific features in it's Java implementation, similar to what it had had done with it's C++ implementation. This along with Microsoft's refusal to support Java RMI, which competed with it floundering remoting technology called DCOM, resulted a law suite. Microsoft lost the law suite in late 2000, and had to pay USD 20 million to Sun as settlement amount. This antagonist attitude made Microsoft break away from Java and float it's own language called C#.
The C# team was carved out of the Microsoft J++ team, and it's effort finally led to the creation of .NET framework.
Microsoft intends to leverage it's desktop leadership, to shape the Internet applications development by introducing the .NET framework. Thus the supported languages map the Windows GUI more closely in it's framework, much similar to C++ MFC and J++ WFC (Windows Foundation Classes). In spite of the platform independence design claims, all the three supported languages produce windows .exe code by default.
Microsoft played the standardization game better than Sun. Microsoft, though being an USA based company proposed the C# and Common Language Infrastructure (CLI), the back bone of .NET framework, for standardization with ECMA (European Computer Manufacturing Association) TC39 Technical Committee in October 2000. Ironically Sun also happens to be a member of this standing committee, which looks after computer languages related standardization issues. See http://www.ecma.ch.
Microsoft has also successfully standardized Simple Object Access protocol (SOAP) through W3C (http://www.w3c.org). SOAP is a XML and HTTP based remote object access protocol. SOAP competes with Java's RMI and Microsoft's own DCOM. RMI has the limitation of being language specific, and DCOM had limited acceptability outside the Windows community, this was, despite the best of Microsoft's effort to port DCOM on Unix platforms.
CORBA, another remoting contender, which even has internet specific transport namely IIOP, is more or less dead, due to it's vendor non interoperability.
SOAP, by virtue of HTTP transport can operate easily over firewalls and therefore can easily transident LAN and Internet. However, SOAP being XML based, burdens both client and server for XML parsing, which is relatively CPU intensive, compared to binary protocols like RMI and DCOM.
Java platform views the Internet world as one language running on different operating systems (OS), whereas .NET framework views the world running on one OS with a programmers having choice of multiple languages. Therefore Java platform interpolates multiple operating systems, and .NET framework interpolates multiple languages.
Apparently from the above discussion, the market forces are largely responsible for the state-of-the-art rather than technical design considerations.
Inside The Common Language Runtime
The Common Language Runtime (CLR), is the runtime environment of the .NET framework, which manages the execution of code and provides services.
The Common Language Runtime (CLR), is also proposed for ECMA standard. However, The ECMA documents refer the CLR as Common Language Infrastructure (CLI). It has five components namely:
- CTS - Common Type System
- CLS - Common Language Specification
- CIL - Common Intermediate Language
- JIT - Just in Time Compiler
- VES - Virtual Execution System
CLI - Common Language Infrastructure
The Common Language Infrastructure (CLI) provides a language neutral platform for application development and deployment. CLI supports both Object Oriented Paradigm (OOP) as well as hooks for modeling procedural and structured languages.
CLI provides languages with a framework for security, garbage collection, exception handling and also provides a platform for language interoperability. For example C# objects can inherit from C++ classes and VB procedures can use the C# components.
Please Note that the Microsoft documentations refer CLI as CLR (Common Language Runtime).
After reading through the ECMA standard documents, like me, you will probably develop the feeling that CLI is an attempt to standardize the next generation Java framework for accommodating the older pre Internet era languages like VB and C++.
The five components of the CLI is briefly described below.
CTS - Common Type System
The Common Type System, support both Object Oriented Programming like Java as well as Procedural languages like 'C'. It deals with two kinds of entities: Objects and Values. Values are the familiar atomic types like integers and chars. Objects are self defining entities containing both methods and variables.
Objects and Values can be categorized into the following hierarchy:
Types can be of two kinds Value Types and Reference Types. Value Types can further categorized into built-in (for example Integer Types and Float Type) and user defined types like Enum.
Reference Type can be divided into three sub categories: Self Describing Reference Type, Pointers and Interfaces. Pointers can be sub divided into Function pointers, Managed and Unmanaged Types.
Value Types can be converted into Reference Type, and this conversion is called Boxing of Values. De-referencing the Boxed Value Types from the Referenced Type is called Un-Boxing.
Casting rules from one type to another, for example conversion of char to integer types are also defined within the Common Type System.
Common Type System also defines scope and assemblies. An assembly is a configured set of loadable code modules and other resources that together implement a unit of functionality. A scope is a collection of grouped names of different kinds of values or reference types.