biology daily - the biology and biochemistry encyclopedia
biology daily articles and research Encyclopedia Dictionary Forums biology research links Weblinks Pictures Articles Blogs Newsletter

Comparison of C Sharp to Java


This is a comparison of the C# programming language to the Java programming language.

Contents

Similarities

  • Both languages were derived from C++ (at least in their syntax), which was in turn derived from C.
  • Both languages were designed to be object oriented from the ground up; unlike C++, they were not designed to be compatible with C.
  • Both languages rely on a virtual machine.
  • Both languages include synchronization.
  • Both languages support generic programming.
  • Both include garbage collection.
  • Both include boxing and unboxing of value types, allowing numbers to be handled as objects.
  • Both include foreach, an enhanced for loop.
  • Both include a large class library, which provides APIs for performing many common programming tasks.
  • Both the Java VM and the .NET platform optimize code at runtime through just-in-time compilation (JIT).
  • Both languages allow the use of enumerations, via the enum keyword.

Advantages of C#

  • Tied more closely to the Windows operating system, making for better performance in OS-specific tasks such as user interfaces. C# also provides close integration with COM.
  • The .NET framework was designed to support the execution of many different languages using the same bytecode (MSIL) and virtual machine. While this is possible with Java, the design of .NET allows for better cross-language compatibility.
  • Better support for arithmetic by including more primitive types and functionality to catch arithmetic exceptions.
  • Includes a large number of notational conveniences over Java, many of which, such as operator overloading and user-defined casts, are already familiar to the large community of C++ programmers.
  • Event handling is a "first class citizen" — it is part of the language itself.
  • C# is defined by ECMA and ISO standards, whereas Java is proprietary.
  • Allows the definition of "structs", which are similar to classes but may be allocated on the stack (unlike instances of classes in C# and Java). This can improve performance in some situations.
  • C# support for properties allows for better code readability.

Disadvantages of C#

  • Little support for platforms other than Microsoft Windows, like Mac OS, Linux and Unix. However, some initiatives, such as the Mono project are adding some functionality of the common language runtime needed for C# to other platforms.
  • Some would argue that C# is under too much control by Microsoft (just as Java is controlled by Sun Microsystems), making it a poor choice in the long run. However, C# has been submitted to ECMA for standardization while Java is still entirely controlled by Sun Microsystems.
  • It is still unclear whether the C# design include software patents potentially enforcable by Microsoft. However, some argue that Microsoft's strong backing of C#'s standardization indicates their intention to spread the language rather than to keep it under monopoly.

Advantages of Java

  • Already implemented on a larger number of platforms, making for better cross-platform compatibility.
  • More mature, meaning a lot of problems may have already been worked out, and more code is already widely available.
  • Method invocation model is simpler, making it easier to implement and at times easier to read.
  • Numourous JVM implementations exist, some under open source licensing.

Disadvantages of Java

  • Does not include operator overloading, making it ill-suited for scientific programming.
  • The lack of any pass-by-reference for primitive (or reference) types makes certain procedural programming tasks awkward.
  • Java is a proprietary Sun product.

Differences between the languages

  • There are no unsigned primitive numeric types in Java. While it is universally agreed that mixing signed and unsigned variables in code is bad, Java's lack of support for unsigned numeric types makes it somewhat unsuited for low-level programming.
  • C# does not include checked exceptions. Some would argue that checked exceptions are very helpful for good programming practice. Others, including Anders Hejlsberg, chief C# language architect, argue that they were to some extent an experiment in Java and that they haven't been shown to be worthwhile [1] [2].
  • C#'s namespaces are more similar to those in C++. Unlike Java, the namespace does not specify the location of the source file.
  • C# includes delegates, whereas Java does not. Some argue that delegates are extremely useful, but others point out that their inclusion complicates the method invocation model.
  • Java requires that a source file name must match the only public class inside it, while C# allows multiple public classes in the same file.
  • C# allows the use of pointers, which some language designers consider to be unsafe, but certain language features try to ensure this functionality is not misused accidentally.
  • C# supports the goto keyword. This can occaisonally be useful, but the use of a more structured method of control flow is usually recommended.
  • C# has properties. This is an improvement on code readability and simplicity as compaired with Java and C++ where separate get and set methods have to be used.

See also

External links



07-14-2008 23:18:10
The contents of this article are licensed from Wikipedia.org under the GNU Free Documentation License. How to see transparent copy
BiologyDaily.com 2005. Legal info   Privacy