What are the main differences between C# and Java? [duplicate]
Possible Duplicate:
What are major differences between C# and Java?
I believe it was Eric Sink that said "C# is Java done right". I am pretty familiar with Java, and thought I could try开发者_StackOverflow社区 to learn some C#.
As I understand it, these two OO-languages are very similar, so what are the actual differences (if any)?
Having used both extensively for various projects both commercial and hobby, I prefer the expansive open source community around Java, but the tools and (these days) quicker language advancement around C#.
Pro C#
Java got a 5 year head start on C#, during which it tried a bunch of groundbreaking stuff and gave C# some mistakes to learn from and some best practices to adopt. You can viscerally feel the difference that this makes in the class library design, in the way generics are implemented, and just in general polish.
When you add to this the fact that C# introduces a new crop of powerful, carefully chosen, and well-integrated language features every couple of years (LINQ, closures, type inference, the dynamic
variable type, generic support for co- and contra-variance, etc.), it really tends to be a joy to use.
I'm actually surprised to find myself saying this, but you can count on Microsoft to bring in some of the best features from languages as diverse as Haskell, JavaScript, and Python directly into C#. All signs point to this trend continuing.
Pro Java
Java, on the other hand, had a 5 year head start (plus even more if you consider how long it has taken Microsoft to begin to come around to doing things more openly) on building a community around it. This gives rise to the fact that NUnit is a port of JUnit, NHibernate is a port of Hibernate, and in general N* is a port of J*.
You usually end up getting very similar sets of incredible tools from each language's respective community, but a lot of stuff existed (and thus matured) in Java before it existed for .Net.
Summary
Both are worth knowing, and there are tons of things to learn from both. They both have solid communities with slightly different takes on the world. I recommend knowing both and watching them closely going in to the future.
Have a look at
Comparison of Java and C Sharp
Java vs C#/.NET
I can't believe this hasn't been mentioned yet...
Java runs on many different devices (Win, *nix, Mac, cellphones, pas, etc. including x86, arm, and some embedded devices whose opcode is bytecode)
C# runs on 1 (well 4 if you count 2k,xp,win7 beta and win7 as 'different') os on 1 architecture.
Someone will mention mono at this point. Mono is a mistake; a lagging-far-behind implementation of .net that MS hasn't sued anyone over, but claims they can. It is not complete, (will never be) and generally lags real .net by at least a major version.
Java runs on relatively more platforms than C# (or .NET)
精彩评论