C# – A Threat To JAVA?
Setul Verma
Lecturer in Computer Science
Punjabi Univ. Regional Center for Information Technology and Management, Mohali
Amandeep Singh
Lecturer in Computer Science
Punjabi Univ. Regional Center for Information Technology and Management, Mohali
Microsoft really is troubled with theinflating aura of JAVA. In 1995, JAVA emerged on the horizon and in theprevious 6 years, JAVA has stamped the victory over other rival popularlanguages. Microsoft initially resisted JAVA but eventually it became apart of its so much famous Visual Studio (and named VJ++), which it hadto pay for. Sun Microsystems sued Microsoft for violating the licensingagreement.
Eventually the matter settled down andMicrosoft continued releasing new versions of VJ++. But the Microsoftefforts to giving JAVA flavor to Visual Studio did not succeed and VJ++ultimately failed. There were of course, other reasons like poormarketing for its failure. Consequently Microsoft has not released newversions of VJ++ after 1998 and has no plans for it in near future.
Microsoft finally learnt a lesson thatborrowed things do not pay in long run, hence, it started developing anew language -C#(pronounced C-sharp) which conceptually is much likeJAVA but provide additional features missing in JAVA. The purpose ofthe article is to clarify the doubts about C# and to compare it withJAVA.
What is that Microsoft offering in the Package deal?
There are two major components, Microsoft offered in the package.
.NET architecture
New language – C#
.NET architecture
There are three main components of the architecture:
Set of common services which can be used froma no. of languages (also called web services)These services are executed in the form of intermediate code that isindependent of the underlying architectureThe intermediate code is then executed in a runtime environment calledCLR(Common Language Runtime), which manages resource and monitorsapplication execution.
The primary goal of .NET is to facilitatedevelopers to create interoperable applications using Web Services fromany sort of terminal, be it a PC, PDA, Mobile phone and so forth.
Let us take these components one by one:
Web Services
Web services are facilities that are accessedthrough the use of Internet standards such as XML and HTTP.More technically, web services can be thought of as libraries/functionsor databases that you can access through the Internet. For example:
A web service by a business group (Say Alliance) could potentiallyexpose a functions that returns the turnover for a particular year. Inwhich you can pass the year as a parameter.So you applications will just be calling a function Get_turnover(2000)which would return to you the turnover, company earned in year 2000.
Actually you can use web services tointer-relate and synchronize multiple application written for differentplatform in an enterprise environment.
Even though ?Web services ? term uses word?web? and hence a strong flavor of internet access, but, there are manyuses for web services from within normal applications.
The nice thing about Web services is that theycan be called from anywhere. So, in short, the applications of webservices are very vast and the application areas ranges from web sites,to windows, Linux, Unix, Mac-Os, application or even command lineutilities.
Because of the platform independent nature ofInternet standards, the web services are not bound to a particularoperating system or a programming language.
Intermediate Code
Intermediate Code! Doesn?t this term soundsfamiliar? That reminds me something??er??JAVA? Yes, of course.Microsoft plainly admits that invention of .NET is inspired fromruntime environment of JAVA. In a .NET environment, the programs arecompiled via an intermediate binary code, which is independent ofhardware and operating system. The language called MSIL (MicrosoftIntermediate Language) is then executed in the Common Language Runtime(CLR), which conceptually is same as the JVM in the JAVA platform. MSILis then translated into machine code by a Just In Time (JIT) compiler.
The application compiled as intermediate codeis presented as ?PE? (Portable Executables). The requirement of CLS isthat all languages must comply with a common agreement. But the problemis all the existing languages are heterogeneous i.e. they differ infeatures, some are procedural, other object oriented, some supportoverloading, others not and so on.
For a language to be supported by .NETplatform, it must comply with CLS(Common Language Specification). So,if a language needs to be supported by NET, it needs two things:
Compliance with CLS
Compiler for the language into MSIL code.
So what is all that we got after handling suchcomplex jargon? Interoperability. The fact that all the .NET compliancelanguages are compiled in the form of an intermediate code, means thatClass written in one language can be instantiated and hence called inanother language.
Where does JAVA come into this picture? OrMicrosoft has finally kicked JAVA from this picture? Not really. Itremains one of the intending .NET languages. Design of compiler of JAVAto MSIL is already in progress, thanks to Rational (remember famous UMLSoftware developer). But will it be the same JAVA. Not actually. Itwill be a JAVA, which runs an MSIL code not byte code. The JAVA willnot benefit from APIs offered by J2EE platform like RMI, JMS, JDBC, JSPetc. This is JAVA in which EJBs will be replaced by .NET distributedObject Model.
Common Language Runtime
CLR as I have stated above is conceptuallyvery much similar to JVM, a runtime environment which handles resourcemanagement for memory allocation and garbage collection and providesthe necessary abstraction between the application and the underlyingoperating system.
CLR watches traditional programming errorsthat has been the cause of majority of software failures like violatingarray boundaries, access to non-allocated memory locations, memoryoverwritten due to exceeded sizes. This monitoring comes at the priceof speed. Microsoft itself admits the performance degradation by 10%,but is worth if it leads to better reliability and availability.
. NET in present scenario
The full version of .NET is likely to come inthe mid of this year. Old applications built on Microsoft architecturewill still function on Windows 2000 servers with .NET support.Microsoft assured the computer world to provide necessary tools andassistance for migrating from old generation to the coming one, butthat does not seem to be a good solution. Readymade tools cannot 100%migrate the code. Developers will have to devote time to manually dothe migration.
Future of .NET
With the advent of .NET, it cannot be deniedthat th
e way we
design at least e-applications is going to undergoarchitectural changes. Every language is needed to make necessarychanges in the structure to incorporate .NET compatibility. Think ofJAVA. Which JAVA will be preferable, JAVA with JVM or JAVA with .NET. Ileave this question to you readers.
Advent of New Language
Microsoft claims that .NET has support of 27different languages. To incorporate the .NET compliance into a languagemeans putting patches on the existing architecture of language.Microsoft appreciates this point and designed a new language with .NETarchitecture as the base. It was named as C-Sharp or C# (earlierthought to be called ?cool?). The language is inspired of JAVA andcontains best features all over from all the languages extracted fromall the languages.
What is C#
For the past two centuries, C and C++ havebeen the most widely used language for developing commercial andbusiness software. While both languages provide the programmer with atremendous amount of fine-grained control, but at the cost ofproductivity.
Compared with a language like Visual Basicequivalent C/C++ applications often take longer to build up. A languagewas much in demand for so many years, which could offer better balancebetween power and productivity. In the previous few years, the problemwas understood by Sun Microsystems, which provided a language like JAVAwhose way of working is very much different from all other languages.The concept of byte code, JVM and open class codes etc. and that toofreeware.
But something is missing. The code written inJAVA cannot be reused in another language. The feature calledreusability of code is missing in JAVA. So and environment was neededwhich could standardize the code, facilitating reusability. Theenvironment was provided by .NET platform by forcing the supportedlanguages to conform to CLS standards. But as I said earlier, there isa need to have a full fledged language with the best features fromdifferent languages and full support for .NET platform.
The language I am talking about is C# pronounced C-sharp.
C# is a modern, object-oriented, type safelanguage that enables programmer to quickly build a wide range ofapplications for the new Microsoft .NET platform which provides theservices that fully serve both computing to communications.
C# is designed to bring rapid development tothe C++ programmer without sacrificing the productivity and controlthat have been a hallmark of C and C++.
Comparison of C# and JAVA
What should a good language provide? Or whatshould a new language has in store to win hearts of programmers? Theseare controversial questions and have been the major source ofconsiderations for language designers for decades. The language whoseanswer to these questions was unanimously appreciated by almost all theprogrammers was JAVA.
C# seems to be very much similar to JAVA insyntax, but if we go deeper, we will appreciate the efforts done byMicrosoft and thank it for providing the new features.
Let us take the features of JAVA one by one and compare with corresponding features of C#.
Intermediate Language
JAVA compiles to byte code while C# compilesto MSIL(Microsoft Intermediate Language), which is an intermediatelanguage to which all .NET compliant languages compile.
But there is a slight difference in working. JAVA bytecodes are interpreted, whereas MSIL compiles to machine code.
Interoperability
JAVA has its strength in platforminteroperability while C# has strength in language interoperability.Sounds tricky, actually what it means is: JAVA programs can be run onany platform supporting JVM, whereas C# demands the standardization ofcode so that the code written in one language can be reused in anotherlanguage e.g. classes written in one language can be used in anotherlanguage program.
Memory Management
JAVA provides automatic memory management(more technically called garbage collection). Which was once thepowerful feature much appreciated by programmers. But as the old C/C++programmers tried to use JAVA, they felt uncomfortable with thischaracteristic. So keeping in mind the problems of these programmers,C# is designed to provide both automatic and manual memory management.What does this mean? Simple. Pointers are not out of this language.
Reference to external code
External code is handled in JAVA and C# in a much similar way. Keyword import is used in JAVA and using in C#, JAVA uses packages, while C# uses namespaces. But the meaning is more or less same.
Data types
The power of any language is determined by thedifferent data types provided by that language. Data types are theentities which provide the programmers with power and flexibility. Asfar as C# is concerned, it provides all the data types provided byJAVA, but with additional unsigned counterparts.C# has a new 12-byte-decimal floating-point number also.
Field modifiers
Field modifiers are basically same as in JAVA.To define constant or unmodifiable value, C# uses the const and readonly modifier, instead of JAVA?s final. The const field modifier meansthat the value is part of IL (Intermediate Language) code and is onlyevaluated at run time.
Control constructs
If-else, switch, while, do-while, for, break,continue statements are similar in both languages. But still there areadditions. C# has a built in construct, for each, used for iteratingcollection e.g.
int slist(Arraylist alist)
???.
foreach (int j in alist)
{
????.
}
In above snapshot, j is an iteration variable which is sequentially assigned to integer values of array alist.
Interface and Class definition
extends and implements keywords of JAVA are replaced with a colon(:) in C#.
Exception handling
The arguments of catch clause are optional inC#. If it is absent, catch block is for any exception thrown by tryblock. The entire catch clause may be omitted in C#, and C# has nothrows keyword.
Interfaces
In C#, a class may optionally explicitly implement an interface. Explicitly implemented methods are invoked by type-casting a class to the interface required.
Inheritance
In both the languages, only single inheritanceis allowed. If multiple inheritance is to be implemented, usinginterfaces is the only way.
Polymorphism
Virtual methods are used to expresspolymorphism. What this means is that base class will call overloadedmethod of derived class All methods are virtual in JAVA, but in C#, wehave to use explicitly virtual keyword, so that the method will becalled by the base class. In C#, override keyword is required
tospecify that a method should override a method of its base class. Anyattempt to override non-virtual method will result in compile-timeerror. But if new keyword is added, indicating hiding of base class methods, the program compiles without errors.
So what is the conclusion? Do you findanything new in C# or does it look like a step-brother of JAVA? Willthe effort of Microsoft pay it in future? What will be the impact ofthe new language over the existing applications, environments and evenprogrammers? These are some of the crucial questions which only thetime can answer. But meanwhile just munch the questions in your mindand think Is C# really a threat to JAVA?












No comments yet... Be the first to leave a reply!