Comparison of C Sharp to Java

The title of this article is incorrect because of technical limitations. The correct title is Comparison of C# 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 iterator-based 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).

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.
  • C# is defined by ECMA and ISO standards, whereas Java is proprietary (although largely controlled through an open community process.)
  • 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# 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.
  • C# allows switch statements to operate on strings.
  • C# has autoboxing of primitives, which is present in Java 1.5/5.0 but not in earlier versions.
  • C# has the ability to alias namespaces, which can be used to create more readable code (if not abused).

Disadvantages of C#

  • No support for generics (present in Java 1.5/5.0, will be implemented in the upcoming release of C#)
  • Not as ubiquitous as Java across disparate operating systems and environments. Currently no real market presence outside of desktop and server environments (ie. embedded or mobile computing.)
  • Although not a critisism of the language itself, associated firmly with the proprietary .Net framework, which has patchy (or non-existent) support away from Microsoft operating systems.

Advantages of Java

  • Enormous and highly active user base. Java has also become a lingua franca in many modern branches of computer science, particularly areas which involve networking.
  • For better or worse, Java now dominates programming courses at high school and college level in the West. At the time of writing, the number of new Java books still continue to outgrow C# books.
  • 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.
  • Numourous JVM implementations exist, some under open source licensing.
  • Java's strictfp keyword can be used to guarantee that the results of floating point operations remain the same across platforms.
  • Java's method invocation system is simpler than C#'s because it lacks support for delegates.
  • Java Webstart and Java applets provide convenient, lightweight and secure means of distributing an application to the desktop.
  • Its maturity and popularity have ensured more third party Java API's and libraries (many of them open source) than C#.
  • The efficiency of its Bytecode implementation, coupled with agressive Java-specific compression technologies such as pack200, makes Java a very bandwidth friendly means of distributing applications over a network.


Disadvantages of Java

  • Does not include operator overloading -- although this is a done for a reason. Some people consider operator overloading bad, because it leads to code that is harder to understand and debug
  • The lack of any call by reference for primitive (or reference) types makes certain procedural programming tasks awkward.
  • The Java Language Specification is a proprietary Sun product (however other Java VMs, both free/open source and closed source, exists).
  • No support for namespace aliasing.
  • Although not a critisism of the language itself, Java's standard API's are somewhat weak when writing applications targeted at desktop users.

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] (http://www.artima.com/intv/handcuffs.html) [2] (http://msdn.microsoft.com/vcsharp/team/language/ask/exceptionspecs/default.aspx).
  • C#'s namespaces are more similar to those in C++. Unlike Java, the namespace does not specify the location of the source file. (Actually, it's not strictly necessary for a Java source file location to mirror its package directory structure.)
  • 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. Pointers also greatly complicate technologies such as Java's RMI (Remote Method Invocation), where program objects resident on one computer can be referenced within a program running on an entirely separate computer. Some have speculated that the lack of memory pointers in Java (substituted by the more abstract notion of object references) was a nod towards the coming of grid computing, where a single application may be distributed across many physical pieces of hardware.
  • C# supports the goto keyword. This can occasionally be useful, but the use of a more structured method of control flow is usually recommended.
  • C# has true multi-dimensional arrays, as well as the array-of-arrays that is available to Java. Mutli-dimensional arrays are always rectangular (in the 2D case, or analogous for more dimensions), whereas an array-of-arrays may store arrays of various length.

See also

External links

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools