C# and Java are both object-oriented languages descended from C and C++. They both use intermediate languages and virtual machines. While they have many syntactic similarities, C# supports further compilation to native code. C# also has more primitive data types than Java, supports enums, structs, operator overloading, and genuine multi-dimensional arrays. C# is closer to C++ than Java, but uses memory management like Java and has less emphasis on pointers. Key differences between C# and C++ include memory management in C#, classes vs structs, delegates vs function pointers, and array and initialization semantics.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
28 views
Comparing C# To C++ and Java
C# and Java are both object-oriented languages descended from C and C++. They both use intermediate languages and virtual machines. While they have many syntactic similarities, C# supports further compilation to native code. C# also has more primitive data types than Java, supports enums, structs, operator overloading, and genuine multi-dimensional arrays. C# is closer to C++ than Java, but uses memory management like Java and has less emphasis on pointers. Key differences between C# and C++ include memory management in C#, classes vs structs, delegates vs function pointers, and array and initialization semantics.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13
Comparing C# to C++ and
Java C# versus Java
• C# and Java are both new-generation languages
descended from a line including C and C++. • Each includes advanced features, like garbage collection, which remove some of the low level maintenance tasks from the programmer. • In a lot of areas they are syntactically similar. • Both C# and Java compile initially to an intermediate language: C# to Microsoft Intermediate Language (MSIL), and Java to Java bytecode. • In each case the intermediate language can be run - by interpretation or just-in-time compilation - on an appropriate 'virtual machine'. • In C#, however, more support is given for the further compilation of the intermediate language code into native code. Access Modifiers Application Startup • C# contains more primitive data types than Java • C# supports 'enumerations', type-safe value types which are limited to a defined set of constant variables and 'structs', which are user-defined value types. • Unlike Java, C# has the useful feature that we can overload various operators. • Like Java, C# gives up on multiple class inheritance in favour of a single inheritance model extended by the multiple inheritance of interfaces • However, polymorphism is handled in a more complicated fashion, with derived class methods either 'overriding' or 'hiding' super class methods • C# also uses 'delegates' - type-safe method pointers .These are used to implement event-handling • In Java, multi-dimensional arrays are implemented solely with single-dimensional arrays (where arrays can be members of other arrays. In addition to jagged arrays, however, C# also implements genuine rectangular arrays. C# versus C++
• Although it has some elements derived from Visual Basic
and Java, C++ is C#'s closest relative. • In an important change from C++, C# code does not require header files. All code is written inline. • The .NET runtime in which C# runs performs memory management, taking care of tasks like garbage collection. • Because of this, the use of pointers in C# is much less important than in C++. • Pointers can be used in C#, where the code is marked as 'unsafe' but they are only really useful in situations where performance gains are at an absolute premium • The syntax of declaring • In C#, classes and structs C# arrays is different from are semantically different. that of C++ arrays. The A struct is a value type, tokens "[ ]" appear while a class is a following the array type in reference type. C#. • Delegates are roughly • The Main method is similar to function declared differently from pointers in C++, but they the main function in C++. are type-safe and secure. • Local variables in C# cannot be used before they are initialized. • C# types are ultimately derived from the 'object' type . • There are also specific differences in the way that certain common types can be used. • For instance, C# arrays are bounds checked unlike in C++, and it is therefore not possible to write past the end of a C# array.