Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

A colleague (a .NET fan) argued that (in context to Java vs .NET comparison), while there are different arguments for Java and for .NET, and to determine which one is the better choice is a business or personal decision depending on many factors, but from programming language point of view, .NET's C# is clearly a more powerful programming language than Java

To summarize, everything that can be written in Java can be written in C# just as easily or easier, but the reverse is not true. Many features such as lambda expression, and linq is impossible (or very hard in Java), and C# also has syntactic sugar that makes things a lot easier, such as extension method, automatic properties, etc. But there is almost no feature that can be done in Java but impossible or very difficult in C#?

So, in any possible situation C# is equal or more powerful than Java. Is my colleague's assertion correct? If not, what are some examples of coding that is clean and easy in Java but messy, difficult or impossible in C#?

Note: I don't think this is a subjective/argumentative question. I am not looking for arguments that Java is a better choice, or .NET is. I am just asking for evaluation based on facts and concrete examples. For example (made-up example): in .NET iterating on a list will need a dirty workaround and takes dozens of lines, while in java it's just a few clean line

share|improve this question

closed as not constructive by gnat, Doc Brown, James Anderson, Joris Timmermans, S.Robins Apr 26 '12 at 7:59

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. If this question can be reworded to fit the rules in the help center, please edit the question.

Impossible to answer objectively. Programming languages are highly subjective. Not only for different people, but for different situations and projects. –  System Down Apr 26 '12 at 6:30
-1 for obviuosly not reading the FAQ for what questions not to ask here. –  Doc Brown Apr 26 '12 at 6:47
This might be slightly more answerable if you could clarify if you're talking strictly about Java-the-language vs. C#-the-language or about Java-the-platform vs. .NET-the-platform. For example, I personally am a huge fan of Java-the-platform, but would like it if Java-the-language had a few of the great features of C#-the-language. –  Joachim Sauer Apr 26 '12 at 7:14
@System Down, you're wrong. It is perfectly possible to compare the languages objectively. The whole CS is all about this sort of things. You can easily compare the semantics of the languages, measure objectively the complexity of doing the same typical tasks, etc. –  SK-logic Apr 26 '12 at 7:39
@Pieter B, syntax-sugar level features are not harming the robustness at all. Significantly altered semantics might be a problem, especially when given to a bunch of mediocre programmers, but in the C# case it is nothing but a couple of nice thin syntax sugar layers over exactly the same semantics as in Java - i.e., a language is pretty much a Java superset. You can code in in in a boring, "robust" Java style, or you can choose to implement some critical features efficiently using more advanced techniques. In java you've got no choice at all. –  SK-logic Apr 26 '12 at 7:52

3 Answers 3

First, let me note that I am a C# fan myself. Personally, I mostly agree with your colleague, but one should be very careful when stating absolutes.

Second, even if it was clear which language was more powerful, it doesn't necessarily mean it's the better language. More features can mean longer learning curve and more “gotchas”.

The actual cases of things you can do in Java that you can't do in C# (or at least some of them):

  • Create anonymous classes
  • Use wildcards in generic types. (C# has generic interface co- and contra-variance, but it behaves quite differently)
  • Create enums with fields, constructors and methods
share|improve this answer
There are a few things that C# does that Java doesn't: value types (Java has primitives, but no user-defined value types), generics support value types (Java can only use the wrapper classes of primitives in generics), reified generics (actually different code for different generic arguments, especially important with value types), partial classes (I still don't get their use, but Jon Skeet said they are useful, so who am I to argue ;-). –  Joachim Sauer Apr 26 '12 at 8:36
@JoachimSauer, yeah, I know and the OP seems to know that too. But the question was specifically asking for things that are objectively better in Java, not the other way around. –  svick Apr 27 '12 at 14:53

Java is multiplatform, C# is far from that. So while there is Mono, any given situation where you're not working in a Windows environment C# isn't even there to contend Java.

share|improve this answer
I am not looking for arguments about which platform is better, but more about examples of codes that is easier/shorter/less complex in Java as compared to C# –  Louis Rhys Apr 26 '12 at 7:22
You can't compare the two without looking at the bigger picture: Java; less features, multiplatform more secure, C#; more features. –  Pieter B Apr 26 '12 at 7:46
Why not? The purpose here is to just compare the programming languages, not to decide which one to use in a project. –  Louis Rhys Apr 26 '12 at 7:52
@sk-logik What platforms are you referring to? –  Max Apr 26 '12 at 8:15
@Max, ever heard of iOS? –  SK-logic Apr 26 '12 at 10:20

Depends on how you measure.

Programmer-wise you can do some more things in C# that is harder to do in Java.

Deployment-wise you can deploy Java programs to more platforms than you can C#. Our main target is one of those, so Java is much better than C# for us.

Plenty of other criteria exist. Be certain how you measure.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.