Alex Rivera | Logout

Java and C#, how close are they?

Asked 2010-04-12T21:17:02.153
47

I've been using C/C++ and Python, but I now I see that a lot of new programming books use Java or C# as examples.

I don't think I'll use Java or C# for the time being, but I guess I have to study one of the languages (or both of them) in order to read/understand the books.

  • How similar Java and C#? If I learn Java, is learning C# almost free? Or vice versa?
  • If I have to choose only one of the two languages, which would be better? Which has wider coverage in terms of programming language?
Edit
Report

2 Answers

57

You are asking several questions at once. Let me address them separately:


How similar Java and C#?

Both C# and Java drew from C/C++ (and Objective C, and others) to define their syntax. And both of them are compiled to an intermediate language.

This common origin makes the languages look similar in many levels, to the point that code in either language can be confused with the other by beginners; and also makes the runtime environment somewhat comparable. However, there are substantial differences in both design principles and how each language evolved that make working with each quite different; here are the most prominent ones:

On the syntax level, Java was influenced by Smalltalk, while C# tried to stay closer to C/C++ (eg: compare Java's extends and implements with C#'s : notation) and took a vague inspiration from VB on those concepts that weren't mappable to C/C++ (example: property syntax).

On the features level, C# 1 was definitely close to Java. Among the few differences they had, I'd highlight C#'s support for "unsafe" code (including pointers) and for delegates; and Java's controversial throws. This makes sense, since one of the goals of C# was to become an alternative to Java.

Many language features differ heavily on implementation details. For example, enums are very C'ish on C#, but are full objects in Java; or generics are implemented on the IL-level in C#, but in Java are dealt with via type erasure (neither is really close to C++'s templates besides syntax).

On the API level, they are worlds apart. C# relies on the .Net Framework, which was built on Microsoft's experience with the Visual Studio family of products (and thus is significantly Windows-oriented), while Java's Class Library was built, IIRC, from scratch, and heavily evolved over time (on these Swing days, does anyone remember

answered 2010-04-12T23:07:20.897
1

If you want a brutally subjective answer.

I have just finished a degree in Computer Science in England, I chose a university that taught C# as opposed to Java.........reason being, so I could easily walk straight into a highly paid job as a software developer with a company that simply only wants people who know the "new" technologies.

These are companies such as Investment Banks, tech startups, IT Consulting firms.

So if you want to pick one to learn......

Think about the end goal.....if it's cash and modern knowledge...follow C#.

....and if it's anything else, follow C#

P.S. Java is terrible - I had to say it.

answered 2010-04-21T17:35:20.677

Your Answer