|
This is a comparison of the C# programming language to the Java programming language. As two modern garbage-collected runtime-compiled languages derived from C and C++, 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. C# (pronounced see-sharp) is an object-oriented programming language developed by Microsoft as part of their . ...
Java is an object-oriented programming language developed by James Gosling and colleagues at Sun Microsystems in the early 1990s. ...
In computing, garbage collection (also known as GC) is a form of automatic memory management. ...
The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language The C programming language is a standardized imperative computer programming language developed in the early 1970s by Dennis Ritchie for use on the Unix operating system. ...
C++ (pronounced see plus plus, IPA: /siË plÉs plÉs/) is a general-purpose computer programming language. ...
Similarities - The syntax of both languages is similar to C++, which was in turn derived from C.
- Both languages were designed to be object oriented from the ground up; unlike C++, neither is a strict superset of C.
- Both include 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 APIs for performing many common programming tasks.
- Both provide parametric polymorphism by generic classes.
C++ (pronounced see plus plus, IPA: /siË plÉs plÉs/) is a general-purpose computer programming language. ...
The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language The C programming language is a standardized imperative computer programming language developed in the early 1970s by Dennis Ritchie for use on the Unix operating system. ...
Object-oriented programming (OOP) is a computer programming paradigm in which a software system is modeled as a set of objects that interact with each other. ...
In general terms, a virtual machine in computer science is software that creates an environment between the computer platform and the end user in which the end user can operate software. ...
Synchronization is coordination with respect to time. ...
In computing, garbage collection (also known as GC) is a form of automatic memory management. ...
In computer science, an object type (a. ...
In computer science, primitive types, as distinct from composite types - are datatypes provided by a programming language as basic building blocks. ...
In object-oriented programming, an iterator is an object allowing one to sequence through all of the elements or parts contained in some other object, typically a container or list. ...
API with 3 clients, using the Unified Modeling Language notation An application programming interface (API) is a set of definitions of the ways one piece of computer software communicates with another. ...
A Java Virtual Machine or JVM is a virtual machine that runs Java byte code. ...
The . ...
In computing, just-in-time compilation (JIT), also known as dynamic translation, is a technique for improving the performance of bytecode-compiled programming systems, by translating bytecode into native machine code at runtime. ...
Features of C# absent in Java - C# includes more primitive types and the 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.
- 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).
- C# implements properties as part of the language syntax.
- C# allows
switch statements to operate on strings. - C# has support for output parameters, aiding in the return of multiple values, a featured shared by C++ and SQL.
- C# allows a class to specifically implement methods of an interface, 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 COM.
- Following the example of C and C++, C# allows call by reference for primitive and reference types
Exception handling is a programming language construct or computer hardware mechanism designed to handle runtime errors or other problems (exceptions) which occur during the execution of a computer program. ...
In computer programming, operator overloading (less commonly known as operator ad-hoc polymorphism) is a specific case of polymorphism in which some or all of operators like +, = or == are treated as polymorphic functions and as such have different behaviours depending on the types of their arguments. ...
An event handler is a part of a computer program created to tell the program how to act in response to a specific event (e. ...
Stack in computing refers to: Stack (data structure) Stack-based memory allocation as opposed to Heap-based memory allocation in computing architecture. ...
In information processing, properties are transmitted by objects and received by observers. ...
This article needs to be cleaned up to conform to a higher standard of quality. ...
SQL (commonly expanded to Structured Query Language - see History for the terms derivation) is the most popular computer language used to create, modify and retrieve data from relational database management systems. ...
Many modern computer languages provide support for namespaces. ...
An interface defines the communication boundary between separate computer components. ...
Component Object Model (COM) is a Microsoft platform for software componentry introduced by Microsoft in 1993. ...
Parameters are a way of allowing the same sequence of commands to operate on different data without re-specifying the instructions. ...
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. Features of the .NET Framework absent in the Java Virtual Machine Microsoft Windows is a range of commercial operating environments for personal computers. ...
Features of the Java Virtual Machine absent in the .NET Framework - Java is ubiquitous across disparate operating systems and environments. (The C# implementation Mono 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.
Mono is a project led by Novell (formerly by Ximian) to create an ECMA Standard compliant (Ecma-334 and Ecma-335), .NET compatible set of tools, including among others a C# compiler and a Common Language Runtime. ...
Tux, a cartoon penguin frequently featured sitting, is the official Linux mascot. ...
Mac OS X is the operating system which is included with all shipping Apple Macintosh computers in the consumer and professional markets. ...
A Java virtual machine or JVM is a virtual machine that runs Java byte code. ...
Open source refers to projects that are open to the public and which draw on other projects that are freely available to the general public. ...
Byte-code is a sort of intermediate code that is more abstract than machine code. ...
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#. Lingua franca, literally Frankish language in Italian, was originally a mixed language consisting largely of Italian plus a vocabulary drawn from Turkish, Persian, French, Greek and Arabic and used for communication throughout the Middle East. ...
A computer network is a system for communication between computers. ...
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 may 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 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. (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 complicate the method invocation model, because they are handled through reflection, which is generally slow. On the other hand, they can simplify the code by removing the need to declare new (possibly anonymous) classes to hook to events.
- 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 (which C# calls jagged arrays). Multi-dimensional arrays are always rectangular (in the 2D case, or analogous for more dimensions), whereas an array-of-arrays may store rows (again in the 2D case) of various lengths. Rectangular arrays may speed access if memory is a bottleneck (there is only one memory reference instead of two; this benefit is very dependent on cache behavior) while jagged arrays save memory if it's not full but cost (at the penalty of one pointer per row) if it is. Rectangular arrys also obviate the need to allocate memory for each row explicitly.
- Java does not include operator overloading, because abuse of 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. Conversely, .NET's numeric types do not share a common interface or superclass with add/subtract/etc. methods, restricting the flexibility of numerical libraries.
- Methods in C# are by default "sealed" (or "final" in java terminology), meaning you cannot override them in subclasses. In Java however, methods are virtual by default. This is a major difference of philosophy between the designers of the Java and .NET platforms.
- Java 1.5's generics use type-erasure. Information about the generic types is lost when Java source is compiled to bytecode. .NET 2.0's generics are preserved after compilation due to generics support in the .NET 2 class library. Java's approach allows Java 1.5 binaries to be run in the 1.4 JRE, at the cost of additional runtime typechecks.
- C# is defined by ECMA and ISO standards, whereas Java is proprietary, though largely controlled through an open community process.
- The .NET run-time allows both managed and unmanaged code, enabling certain classes of bugs that do not exist in Java's pure managed code environment but also allows interfacing with existing code.
- C# is a more complicated language than Java. Choices about language complexity are trade-offs between time spent learning the language (C# has a harder learning curve) and time programming (C# programmers may be more efficient)
Exception handling is a programming language construct or computer hardware mechanism designed to handle runtime errors or other problems (exceptions) which occur during the execution of a computer program. ...
Exception handling is a programming language construct or computer hardware mechanism designed to handle runtime errors or other problems (exceptions) which occur during the execution of a computer program. ...
Anders Hejlsberg born 1961? (he states 1960 in a video at the Microsoft Museum) in Copenhagen. ...
In object-oriented programming there are two notions of delegation. ...
In computer science, reflection (or computational reflection) is the ability of a program to observe and possibly modify its high level structure. ...
In computer science, a pointer is a programming language datatype whose value refers directly to (points to) another value stored elsewhere in the computer memory using its address. ...
The Java Remote Method Invocation API, or RMI, is a Java application programming interface for performing remote procedural calls. ...
// Grid computing uses the resources of many separate computers connected by a network (usually the internet) to solve large-scale computation problems. ...
GOTO is a command found in many programming languages which instructs the computer to jump to another point in the computer program, specified by a label or line number. ...
In computer programming, an array, also known as a vector or list, is one of the simplest data structures. ...
ECMA is short for European Computer Manufacturers Association (Name of Ecma International until 1994) East Coast Music Awards European Carton Makers Association[1] ECMAScript This is a disambiguation page — a navigational aid which lists other pages that might otherwise share the same title. ...
ISO has many meanings: Iso is the stem of the Latin transliteration of the Greek word ίÏÎ¿Ï (Ãsos, meaning equal). The iso- prefix in English derives from this and means equality or similarity. ...
Managed code is code executed by a . ...
See also This is a comparison of the Java programming language to the C++ programming language. ...
External links |