tags:

views:

268

answers:

2

It's been a couple of years since I last worked with Java. Can you tell me what problems can be solved more elegantly in Java?

I am aware of the following benefits of Java:

  • Java 'runs everywhere',
  • Java has support for units and measures
  • (supposedly) better latency in Java
  • J2EE (I don't think there is an equivalent in .Net)
  • different approach to generics (with odd circular definitions such as "Enum>", see Ken Arnold)

What about generics - are there elegant Java examples that cannot be represented in C#? Or other APIs or libraries?

Thanks,

Jiří

P.S. some general links:

+6  A: 

Java generics are very different to C# generics. And yes, there are places where that means it can be more elegant - usually in terms of wildcarding and variance. On the other hand, wildcarding is generally poorly understood (and I very definitely include myself in that camp) and the whole business of type erasure means that in general I far prefer .NET generics.

A rather different place where Java "wins" IMO is its enum support. C# enums are basically named numbers - Java is much more object oriented. A similar effect can be mostly achieved in C# using nested classes, but more framework support (an equivalent to EnumSet) and switch support would be welcome.

I also like the ability to restrict visibility to a package (namespace) in Java - although this is the only side of Java's access rules that I prefer to C#.

Having used both Java and C# pretty extensively for a number of years, my own feeling is that on the language level C# is far, far ahead of Java. Really, good cross-platform support and a large existing codebase are the only two significant advantages Java has over C# and .NET at this point.

Jon Skeet
enums... of course they gave themselves plenty of versions to mull over that particular problem didn't they? :)
U62
A: 

What does "better latency" even mean in this context?

Other than that, I agree with Jon Skeet. On the whole, C# is lightyears ahead of Java. There are a few tricks in Java that are neat (enums for example), but they're very much the exception, not the rule.

jalf
Thanks for the replies guys - I am just googling EnumSets... Under "latency", I meant the speed of reply to an incoming request (e.g. HTTP request over LAN)-jiri
That has nothing to do with the language though. In networking, latency is measured in milliseconds. In code, it is measured in nanoseconds, or at most microseconds. Any language you care to mention can handle a HTTP request in less time than it takes your network card to receive a packet.
jalf