Skip to content

C# Versus Java

August 6, 2009
tags:
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.
C# contains more primitive data types than Java and also allows more extension to the value types. For example, 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.
Similarities of C# and Java
  • Powerful reflection capabilities
  • No header files, all code scoped to packages or assemblies, no problems declaring one class before another with circular dependencies
  • Thread support by putting a lock on objects when entering code marked as locked/synchronized
  • Inner classes
  • No concept of inheriting a class with a specified access level
  • No global functions or constants, everything belongs to a class
  • Arrays and strings with lengths built-in and bounds checking
  • The ‘.’ operator is always used, no more ->, :: operators
  • null and boolean/bool are keywords
  • All values are initialized before use
  • Can’t use integers to govern if statements
  • Try Blocks can have a finally class.
Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: