2.1 Potent combo of Java and C++When I first started learning C#, I was mildly surprised at how much the C# team ' copied ' from the Java programming language. Microsoft defined C# as "a modern object-orientated language that enables programmers to quickly build a wide range of applications for the new Microsoft .NET platform". It was added that C# was "derived from C and C++". It has never been mentioned in any official Microsoft literature (not even the C# Language Specification) that certain features in C# have been developed after considerable study of the Java language, though this fact is immediately obvious to anyone who knows a bit of Java and C++. Many of us will agree that Java is an improved version of C++. Java got rid of several unpleasant C++ features such as multiple inheritance, the goto keyword, and added a host of nice features such as a common class ancestry for all Java classes and Java interfaces (in place of multiple inheritance). C# can also be viewed as an improved version of Java. Like Java, C# supports only single inheritance, uses interfaces, and all objects have a common ancestral class (C#'s System.Object ). Despite the similarities between C# and Java, to say that C# has been totally modeled on Java alone is not fair [5] . There are also several C++ 'legacies': such as the destructor, preprocessor directives, enum keyword, structures, and operator overloading to name just a few. These 'legacies' will be total strangers to Java developers with no C/C++ background.
In addition to C/C++ 'legacies' and Java 'add-ons', C# spots several new useful features not found in both languages “ examples include C# indexes, properties, attributes, delegates and events. A summary is shown in Figure 2.1. Figure 2.1. C# has not only extracted the cream features from both C++ and Java, it has come up with several new extras to aid the powerful developer. These extras come at a price “ a steeper learning curve and the possibility of 'abuse' by weaker developers who use them for the wrong purposes.
Microsoft calls C# "a combination of the ease of use of VB and the power of C++". I would rather view it as having the elegance and simplicity of Java coupled with the power and convenience of C++ (see Figure 2.2). The C# team obviously had the advantage of benefit from the experience of both Java and C++ when they came up with a whole new programming language (and I think they have done a good job having seen the product.) Figure 2.2. The new .NET programming languages and their predecessors in VS .NET. C# is a brand new language targeted primarily at the .NET platform. C# inherited elegance and simplicity from Java, and power and convenience from C++.
Because of C#'s similarity to Java, learning C# will be relatively easy if you have a good Java foundation (compared to learning C# with a VB background, for example). Despite the initial "Hey-that's-a-feature-of-Java!", as you go along you will realize that C# is, after all, not so much like Java in certain aspects. There is a learning curve to climb even if you are a Java expert (and especially if you have never been exposed to C or C++). Nevertheless, it is the objective of this book to bridge this gap. 2.1.1 Is C# superior to Java?It is difficult to say if Java or C# is the superior language because their purposes are vastly different in the first place. [6] Java emphasizes portability, platform independence, and simplicity. C# is commonly viewed as the most powerful .NET language used for writing web applications, Windows applications, and web services on the .NET platform. For C#, portability is of low value “ rather, the emphasis is on giving the programmer as much power and convenience as needed, even if it takes more effort to master the language.
One thing is for sure, learning C# can involve a steeper climb than learning Java if you start from scratch. In addition to the 'convenience features' added into C#, C# has also preserved several features from C++ which the Java designers left out deliberately (such as operator overloading and the enum keyword), thus making learning C# more difficult compared to Java. Table 2.1 compares the features of C# and Java. Where feature richness and power is concerned , I would say that C# is the clear winner. But Java wins in ease of use and learning. In my personal opinion, C# will succeed if, and only if, .NET succeeds. This language has been created from the ground up just for the .NET platform “ if vendors do not use .NET for their implementations , there is little reason for software engineers around the world to learn a new language. One important advantage of C# is the ability to write unsafe codes. Java codes must run within the JVM, and that is a severe limitation when it comes to real time programming. It is also impossible to write to memory-mapped devices using Java. JNI “ which comes with performance overheads “ is needed for Java codes to 'talk to' native components . It all boils down to the same engineering problem “ where is the appropriate balance between portability and efficiency. Table 2.1. Comparing some aspects of Java and C#
The next chapter will discuss Microsoft's JUMP to .NET strategy specially tailored for Java developers. |