The Digital Gabeg
The Digital Gabeg

Reputation: 2786

Comparing C# and Java

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.

Upvotes: 6

Views: 4805

Answers (8)

Barry Feigenbaum
Barry Feigenbaum

Reputation: 81

As Elizabeth Barrett Browning said: How do I love thee? Let me count the ways.

Please excuse the qualitative (vs. quantitative) aspect of this post.

Comparing these 2 languages (and their associated run-times) is very difficult. Comparisons can be at many levels and focus on many different aspects (such as GUI development mentioned in earlier posts). Preference between them is often personal and not just technical.

C# was originally based on Java (and the CLR on the JRE) but, IMHO, has, in general, gone beyond Java in its features, expressiveness and possibly utility. Being controlled by one company (vs. a committee), C# can move forward faster than Java can. The differences ebb and flow across releases with Java often playing catch up (such as the recent addition of lambdas to Java which C# has had for a long time). Neither language is a super-set of the other in all aspects as both have features (and foibles) the other lacks.

A detailed side-by-side comparison would likely take several 100s of pages. But my net is that for most modern business related programming tasks they are similar in power and utility. The most critical difference is probably in portability. Java runs on nearly all popular platforms, which C# runs mostly only on Windows-based platforms (ignoring Mono, which has not been widely successful). Java, because of its portability, arguably has a larger developer community and thus more third party library and framework support.

If you feel the need to select between them, your best criteria is your platform of interest. If all your work will run only on Windows systems, IMHO, C#/CLR, with its richer language and its ability to directly interact with Windows' native APIs, is a clear winner. If you need cross system portability then Java/JRE is a clear winner.

PS. If you need more portable jobs skills, then IMHO Java is also a winner.

Upvotes: 0

Shire
Shire

Reputation: 659

Comparing and contrasting the languages between the two can be quite difficult, as in many ways it is the associated libraries that you use in association with the language that best showcases the various advantages 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 strong lead with LINQ, also a wealth of 3rd part libraries 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 testing I have done is far superior to CLR
  7. Garbage collection - Java is another clear winner here. Unmanaged code with the C#/.NET framework makes this a nightmare, especially when working 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 ALLOT 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 capabilities you get with .NET natively beats what you get with eclipse/Java out of the box. But there are lots of libraries 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 some 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 contrasting the two. Hopefully this lists is a cross section of the more commonly used features...

Upvotes: 8

Colin Mackay
Colin Mackay

Reputation: 19185

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.

Upvotes: 0

MagicKat
MagicKat

Reputation: 9821

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.

Upvotes: 0

Asmor
Asmor

Reputation: 5181

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...

Upvotes: 1

Michael Myers
Michael Myers

Reputation: 192035

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).

Upvotes: 4

gbjbaanb
gbjbaanb

Reputation: 52689

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.

Upvotes: 2

therealhoff
therealhoff

Reputation: 2375

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).

Upvotes: 2

Related Questions