tags:

views:

608

answers:

8

I learned Java in college, and then I was hired by a C# shop and have used that ever since. I spent my first week realizing that the two languages were almost identical, and the next two months figuring out the little differences. For the most part, was I noticing the things that Java had that C# doesn't, and thus was mostly frustrated. (example: enum types which are full-fledged classes, not just integers with a fresh coat of paint) I have since come to appreciate the C# world, but I can't say I knew Java well enough to really contrast the two so I'm curious to get a community cross-section.

What are the relative merits and weaknesses of C# and Java? This includes everything from language structure to available IDEs and server software.

+2  A: 

Another thing to keep in mind, you may also want to compare their respective VMs.

Comparing the CLR and Java VM will give you another way to differentiate between the two.

For example, if doing heavy multithreading, the Java VM has a stronger memory model than the CLR (.NET's equivalent).

therealhoff
+6  A: 

Hasn't this been done to death already? At the end of the day, it's not the tools that matter, but what you do with them.

Actually, if you are doing the comparison for a specific project, it hasn't been done to death.Generic comparisons (flamewars) are useless, but the two are different. Understanding the differences would be the key to knowing when to use one over the other (when both are realistic options).
therealhoff
I'm not sure what "already" means - it's not on record here yet. And if tools don't matter, does that mean you wouldn't mind writing web apps in FORTRAN?
The Digital Gabeg
Not trying to be snarky, just pointing out that tools do matter. They're not everything, but they're also not nothing.
The Digital Gabeg
+1  A: 

C# has a better GUI with WPF, something that Java has traditionally been poor at.

C# has LINQ which is quite good.

Otherwise the 2 are practically the same - how do you think they created such a large class library so quickly when .NET first came out? Things have changed slightly since then, but fundamentally, C# could be called MS-Java.

gbjbaanb
+4  A: 

One difference is that C# can work with Windows better. The downside of this is that it doesn't work well with anything but Windows (except maybe with Mono, which I haven't tried).

Michael Myers
+1  A: 

Don't take this as anything more than an opinion, but personally I can't stand Java's GUI. It's just close enough to Windows but not quite, so it gets into an uncanny valley area where it's just really upsetting to me.

C# (and other .Net languages, I suppose) allow me to make programs that perfectly blend into Windows, and that makes me happy.

Of course, it's moot if we're not talking about developing a desktop application...

Asmor
A: 

Java:

  • Enums in Java kick so much ass, its not even funny.
  • Java supports generic variance

C#:

  • C# is no longer limited to Windows (Mono).
  • The lack of the keyword internal in Java is rather disappointing.
MagicKat
A: 

You said:

enum types which are full-fledged classes, not just integers with a fresh coat of paint

Have you actually looked at the output? If you compile an application with enums in in then read the CIL you'll see that an enum is actually a sealed class deriving from System.Enum.

Tools such as Red-Gate (formerly Lutz Roeder's) Reflector will disassemble it as close to the orginal C# as possible so it may not be easily visible what is actually happening under the hood.

Colin Mackay
From the ASP.Net 3.0 spec: "Each enum type has a corresponding integral type called the underlying type of the enum type."Yes, they're classes. But you can typecast them to and from int and you can't define their members. They are simple wrapper classes - they are ints with a fresh coat of paint.
The Digital Gabeg
+4  A: 

Comparing and constrastign the langauge between the two can be quite difficult, as in many ways it is the associated libraries that you use in association wit hthe language that best showcase the various advantage of one of another.

So I'll try to list out as many things I can remember or that have already been posted and note who I think has the advantage:

  1. GUI development (thick or thin). C# combined with .NET is currently the better choice.
  2. Automated data source binding. C# has a strogn lead with LNQ, also a wealth of 3rd part libaries also gives the edge
  3. SQL connections. Java
  4. Auto-boxing. Both languages provide it, but C# Properties provides a better design for it in regards to setters and getters
  5. Annotation/Attributes. C# attributes are a stronger and clear implementation
  6. Memory management - Java VM in all the testign I have done is far superios to CLR
  7. Garbage collection - Java is another clear winner here. Unmanaged code with the C#/.NET framework makes this a nightmare, exspecially when workign with GUI's.
  8. Generics - I believe the two languages are basically tied here... I've seen good points showing either side being better. My gut feeling is that Java is better, but nothing logic to base it on. Also I've used C# generics ALOT and Java generics only a few times...
  9. Enumerations. Java all the way, C# implementation is borked as far as I'm concerned.
  10. XML - Toss up here. The XML and serialization capabilties you get with .NET natively beats what you get with eclipse/Java out of the box. But there are lots of libaries for both products to help with XML... I've tried a few and was never really happy with any of them. I've stuck with native C# XML combined with soem custom libraries I made on my own and I'm used to it, so hard to give this a far comparison at this point...
  11. IDE - Eclipse is better than Visual Studio for non-GUI work. So Java wins for non-GUI and Visual Studio wins for GUI...

Those are all the items I can't think off for the moment... I'm sure you can literally pick hundreds of items to compare and constrast the two. Hopefully this lists is a cross section of the more commonly used features...

Shire