Java to C# – The knowledge upgrade

Christopher Roberts-York, BSc Computer Science undergraduate, Level 3 2011-12.

So a couple weeks ago I decided to take on the challenge of converting my Java knowledge into C# (pronounced C Sharp) knowledge.  Armed with two  Java courses I got stuck in and the switch has been suprisingly easy.

I fired up my web browser and did a generic google search for “learn c#”.  Like everything you google; there are countless results, and if your not really sure what you are looking for, the first result is as good a start as any other.  The first link happened to be a Microsoft Website. Here I found a page with a few good looking links:

  • Introduction to the C# Programming Language
  • Getting started with Visual C#
  • Introduction to the C# Language

Clicking the first link I saw “Introduction to the C# Programming Language” I was quickly greeted by a video tutorial!!  This was great! Apart from I didn’t have any of the tools that the video was talking about and so, pausing the video for a short period, returning to google I found that there are numerous different ways to start out writing C# code.  Like Java, you can start by typing all the code in notepad (or any other basic text editor), saving the files with the correct extension and using command line to compile all your classes and run your application.  This is great if you want to learn the language without any help from an IDE.  I am a little lazy on that front and so, I decided to see what IDEs exist, preferably without any cost.

What I found was there are in fact many different IDEs that support C# coding. Some of which are Open-Source and others proprietary.

The two main Open-Source IDEs that I found were #develop (short for SharpDevelop) and Mono; which is cross-platform! Mono will allow you to develop C# on Linux, Windows and MAC OSX. Then you have Microsoft’s Flagship IDE which has numerous different versions from their free to use “Educational / Trial” version branded “Express” to their fully fledged team developers version branded “Ultimate”. Now being part of the University I am part of the MSDN Academic Alliance (MSDNAA) which gives you completely free access to all of Microsoft’s products, including Visual Studio Ultimate.  Visual Studio was my chosen option.

Once I had Visual Studio downloaded and installed I went back to the video tutorial I found earlier and worked through creating my first C# application. Ok, it was nothing special just a simple “Hello World” but we have to start somewhere.

So fast forward a few weeks and here I am; having bought a few C# books, read online tutorials and written a few desktop/console applications.  I believe I have started to get to grips with both the IDE and the language.w

So Java programmer to C# programmer.  What I have found is that there are many directly transferable language features from Java to C#, some of which are slightly different but mostly the same.  Some of these are:

Most of the Java keywords are the same in C#. (C# does however have a few extras)

  • Main Method (however C# starts with a capital M
  • No multiple inheritance (however, the C# syntax is less verbose)
  • String are Immutable
  • Class Constructors
  • Exception Handling
  • Arrays (however C# doesn’t allow the square brackets on the variable name) IE: int iArray[]
  • Variable Declaration/Initialization including Primitive types (mostly)
  • Auto Boxing

There are some really neat features which C# offers, which there are no direct Java equivalent, to name a few:

  • Delegates & Events (java could implement this type of thing using Call Backs)
  • Value Types
  • Anonymous methods
  • Pass by Reference
  • Overflow detection (can be automated in a compile property)
  • Nullable types (with a coalesce type feature using the ?? syntax)
  • Partial Classes
  • Verbatim Strings (great for file IO)

However, if you are a die hard Java programmer there are some features which are not found in C#.  Though this being said, C# doesn’t leave you empty handed.  There are additional features which allows you to perform everything and more that you were able to do in Java.

In conclusion, the past few weeks have been very interesting.  The similarities between the two languages are broad, which almost makes the change seamless.  One of the major differences is the IDE.  Visual Studio is hands down the most feature full IDE I have ever used.  It has literally got a button for everything.  So if you are a trained or trainee Java programmer you need not worry about not being trained in another language, your Java knowledge will enable you to pick up another language (especially C#) very quickly, due to the similarities between the languages.