View this PageEdit this Page (locked)Attachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Discussion 1 - Eliot Kim

Comparing C# and Java

This article compares made obvious by the title compares two OOP languages C# and Java, and to a lesser extent C++. I decided to focus my discussion on these two languages, since often times, as stated by the first paragraph of this article, it is a common belief that C# is Microsoft's version of Java, even though it was touted by Microsoft as, "the first component-oriented language in the C/C++ family." This article states that even though C# is not a clone of Java as many believe, it's most important features are closer to Java than to C++.

The article begins by listing in table form C#'s most important features compared with C++ and Java. For example, inheritance. C# and Java both implement single class inheritance with multiple interface whereas C++ uses multiple class inheritance. The notation of interface in both C# and Java are through the keyword "interface", in C++ the notation of interface is through an abstract class. Both C# and Java uses a garbage collector, but C++ memory management is done manually. C# like C++ does have pointers, however they are rarely used and references are used instead. Java uses references and does not have pointers. Finally, C# and Java have one common base class, however C++ does not.

It is important to note that from an object-oriented language standpoint C# and Java are basically identical. They both support single class inheritance, but a class can implement multiple interfaces. Also, in terms of encapulation and polymorphism, Java and C# are almost exactly the same. The differences between the two languages seems to be that C# offers features that as of yet Java does not have.

The reason for this is that C# was born after Java was a mature language. In fact the article I was going to use originally (I chose not to, for several reasons, most notably a huge bias towards C#) argues that Java is at the end of its life cycle, and has been surpassed by C# which is still growing.

As stated above, C# offers many features that Java does not have. In C# you are allowed to overload the Main method. In Java, that is illegal, the main method in Java will always be a static void type, and always have a String[] as a parameter regardless of whether you need to pass in information or not. Both C# and Java have garbage collection, however C# also preserves the C++ way of managing memory manually, which if used properly can increase performance and speed. This is because pointers are still available in C#, however this code must be marked as unsafe code so developers do not use unsafe features accidentally. Structs are also allowed in C#. Since, structs are similar to a class in design, however a struct is a value type therefore stored on the stack. As long as a struct is relatively small, it can be faster than a class. Java does not have structs. In C# primitive parameters can be passed by reference, in Java it can only be passed by value. C# can also pass in a reference parameter that has not been initialized.

In terms of the way people program with C# and Java, there really isn't much of a difference, especially to beginning programmers. The important point to stress, is that from an object-oriented perspective, Java and C# are almost exactly the same. In this aspect, the only real significant difference is syntax, and even that is somewhat similar. Since, there really is no difference in philosophy from an OOP standpoint, C# does not really change the way that people program or learn OOP through Java. Java might be slightly easier to learn than C# since, Java has the java.lang package as a default package, and its own class libraries, whereas C# has no default package and you must always import packages explicitly. C# also does not have its own class library, instead it shares the .NET class libraries with the other .NET languages. Java is also more flexible in the ways you can declare an array, however these are minor differences which should not hinder any would be programmer in my opinion. The main difference lies in memory management. Since, C# allows both automatic memory management, and manual memory management, it allows savvy and more advanced programmers, more options in terms of performance, than Java does. Thus the only real significant difference between Java and C# is performance.

I read Sashmit Bhaduri's discussion on his article similarly titled "A Comparison of C# and Java." I liked his quote about C# being a "cleaned up version of Java", and that most of the stuff "is mostly syntaxtial suger". The article I read coincides with this view, since it states that from an OOP perspective the two languages are virtually identical.

Links to this Page