Google
 
   
Login
Username:

Password:


Lost Password?

Register now!
Search
Main Menu
service
top books
Polls
What do you think about php-deluxe.net?
Excellent!
Cool
Hmm..not bad
What the hell is this?
encyclopedia
recommendation
Freenet DSL
Who's Online
9 user(s) are online (8 user(s) are browsing encyclopedia)

Members: 0
Guests: 9

more...
partner

Comparison of C Sharp to Java

This is a comparison of the C Sharp programming language to the Java programming language. As two modern garbage collection (computer science) runtime-compiled languages derived from C programming language and C plus plus, Java and C# are very similar. This page documents the strong general similarities of the languages and then points out those instances where the languages diverge. Both languages were designed carefully, and if one language has a feature another lacks it is the result of a conscientious design decision. Thus, the reader is advised to avoid the temptation to keep score, and instead think about why the designers made each decision.

= Similarities =

  • The syntax of both languages is similar to C plus plus, which was in turn derived from C programming language.
  • Both languages were designed to be Object oriented programming 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 include garbage collection (computer science).
  • Both include object type#Boxing and unboxing of primitive 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 application programming interface for performing many common programming tasks.
  • Both the Java Virtual Machine and the Microsoft .NET platform optimize code at runtime through Just-in-time compilation.
  • = Features of C# absent in Java =

  • C# includes more primitive types and the functionality to catch arithmetic exception (computer science).
  • 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.
  • Allows the definition of structs , which are similar to classes but may be allocated on the stack (computing) (unlike instances of classes in C# and Java).
  • C# implements property (computer science) as part of the language syntax.
  • C# allows switch statements to operate on strings.
  • C# has support for output parameter (computer science), aiding in the return of multiple values, a featured shared by C++ and SQL.
  • C# has the ability to alias namespace (computer science).
  • C# allows a class to specifically implement methods of an interface (computer science), separate to its own class methods. This allows it also to implement two different interfaces which happen to have a method of the same name. The methods of an interface do not need to be public ; they can be made to be accessible only via that interface.
  • C# provides integration with Component Object Model.
  • Following the example of C and C++, C# allows call by reference for primitive and reference types
  • = Features of Java absent in C# =

  • Java s strictfp keyword can be used to guarantee that the results of floating point operations remain the same across platforms.
  • Support for generic programming (C# will gain support for generics in its upcoming 2.0 release)
  • = Features of the .NET Framework absent in the Java Virtual Machine =

  • The .NET Framework is tied more closely to the Windows operating system, allowing for native UI.
  • = Features of the Java Virtual Machine absent in the .NET Framework =

  • Java is ubiquitous across disparate operating systems and environments. (The Mono development platform implementation for Linux, Mac OS X, et al. is still incomplete.)
  • Numerous JVM implementations exist, some under open source licensing.
  • Java Webstart and Java applets provide convenient, lightweight and secure means of distributing an application to the desktop.
  • The efficiency of its bytecode representation, coupled with agressive Java-specific compression technologies such as pack200, makes Java a very bandwidth-friendly means of distributing applications over a network.
  • = Differences in maturity =

    Java is older than C# and has built up a large and highly active user base, becoming the lingua franca in many modern branches of computer science, particularly areas which involve networking. Java dominates programming courses at high school and college level in the West, and there are currently many more Java than C# books. Java s maturity and popularity have ensured more third party Java API s and libraries (many of them open source) than C#.

    By contrast, C# is a relatively new language. Microsoft has studied Java, building on its successes, and changed some aspects of the language to better suit certain types of applications. Over time Java s headstart will become less relevant.

    = Philosophical 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 exception handling#Checked_exceptions exception handling. 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 [http://www.artima.com/intv/handcuffs.html] [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 delegation (programming), whereas Java does not. Some argue that delegates complicate the method invocation model, because they are handled through reflection (computer science), which is generally slow.
  • 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 Java remote method invocation (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 (command) 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. Multi-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.
  • Java does not include operator overloading, because operator overloading can lead to code that is harder to understand and debug. C# allows operator overloading, which, when used carefully, can make code terser and more readable. Java s lack of overloading makes it somewhat unsuited for certain mathematical programs.
  • C# is defined by ECMA and ISO standards, whereas Java is proprietary although largely controlled through an open community process.
  • The .NET run-time allows both managed code and unmanaged code, enabling certain classes of bugs that do not exist in Java s pure managed code environment. This decision was made to allow easier porting of code from unmanaged languages.
  • C# is a more complicated language than Java. Choices about language complexity are trade-offs between developer convenience, and the ease of learning and debugging.
  • == See also ==

  • Comparison of Java to C Plus Plus
  • = External links =

  • [http://www.csse.monash.edu.au/courseware/cse1203/Resources/CsharpVJava.htm A Comparison of Microsoft s C# Programming Language to Sun Microsystems Java Programming Language]
  • [http://www.javaworld.com/javaworld/jw-11-2000/jw-1122-csharp1_p.html C#: A language alternative or just J--]
  • [http://www.ondotnet.com/pub/a/dotnet/2001/06/14/csharp_4_java.html Contrasting C# and Java Syntax]
  • [http://www.javacamp.org/javavscsharp/ Java vs. C# - Code for Code Comparison]
  • [http://www.osnews.com/story.phpnews_id=5602 Nine Language Performance Round-up]
  • [http://virtualschool.edu/objectivec/influenceOnJava.html Java Was Strongly Influenced by Objective-C ... and not C++]
  • [http://www.csharphelp.com/archives/archive96.html Java and C-Sharp Compared]