tags:

views:

624

answers:

7

I code C# all day, but recently made a jump to Java for hobby stuff, like writing for the BlackBerry and Android platforms. All this time I assumed that as far as language features go, Java and C# were twins of each other.

Anyway, I discovered that Java is the equivalent of C# 1.1 or something like that. In Java, I have to write twice the code that I would in C#. Are features like object initializers, lambda, properties for god's sake, ever coming to Java? I tried to wade through the JSR stuff, but couldn't find anything.

Has Java simply not kept up? Or am I simply not using it as it is intended?

+7  A: 

I would say, yes, Java has not kept up. Microsoft took a long hard look at Java (and C++) and figured out what annoyances they had, and what features were missing, and fixed many of those in subsequent releases of C#.

Also, the Java designers seem to try to keep their language and parsers as simple as possible, whereas the C# designers have no fear of syntactic sugar: properties, delegates, lambdas and LINQ are all examples of this. And as you already noticed, a spoonful of syntactic sugar makes the language go down much easier.

Thomas
+10  A: 

I think you're right, Java does not have a lot of the convenient new features that C# has introduced. A lot of the new C# features are just compiler tricks to (properties, object intitializers, extension methods) that you can accomplish by hand in C# or Java.

The Java people probably haven't introduced these new features because they probably prefer to keep the language as simple and backwards-compatible as possible.

I do have to say I prefer writing C# these days.

Andy White
+6  A: 

The older a popular language is, the bigger its code base becomes, and changes to the languages are made in a more conservative manner, in order not to break existing code base, which would be expensive to fix.

Java is one of the older languages. C# is relatively new and can afford to be changed more radically. Compare with C and C++, which did not change for a decade.

If you really want new language features for your new code, try another JVM-based language that interoperates with Java (Groovy, Scala, Clojure).

Alex B
Unless the old language is VB6! If you have any existing VB6 programs, well Microsoft have some nice new languages for you to rewrite your apps in. Maybe you'll finish before your organisation goes bankrupt and your competitors have innovated your products into irrelevance.
MarkJ
+6  A: 

Java has certainly fallen behind, although I'd say that it's closer to C# 2.0 than C# 1.1 - it has generics, for example, even though they're somewhat different to those in C#.

I was disappointed to hear that many of the proposed language features have been dropped for Java 7 (particularly closures), but then Project Coin came along - so at least we might have some small features to look forward to.

I can't see Java catching up to C# in language terms any time soon - they have more language baggage which makes it harder to change the language for one thing. Trivial though it may sound, checked exceptions add an extra "axis" to method signatures which make some things (like closures) trickier than they would be otherwise.

(And of course C# 4.0 is hoving into view too...)

Jon Skeet
+1  A: 

And that's not to Swing vs WPF which are like chalk vs caviar.

sipwiz
+4  A: 

Indeed you're right. But, I think the focus of language improvements has pretty much shifted to new JVM languages, such as Groovy and Scala.

And perhaps it's a good thing, as Java has a significant user base, which, unfortunately, hardly can agree about which features, if any, and in what form should be added to the language. For instance, take look at this poll. On the other hand, Sun has promised improvements to the JVM that would facilitate development and execution of dynamic JVM languages, such as invokedynamic instruction, JSR 292.

To me this is a decent compromise.

javashlook
+5  A: 

I think part of the issue is economic. It's no accident that Java came along when Sun was a leading player in the marketplace. Their stock was at an all-time high in Mar 2000, fueled by all the servers that dot-com companies were buying.

When the bubble burst, and all those servers hit the market, it took a long time for the glut to be worked through. Sun hasn't recovered from it. The increase in power of commodity servers has eroded the edge that specialty RISC chips and Solaris once had. You can't be a great military power unless you're an economic power; being an innovator on this scale requires cash, too.

They've lost a lot of talent (e.g., Bill Joy) that used to fuel the company.

Sun is, at its bottom, a hardware company. The strategy with Java, especially on the server side, was that it would help drive hardware sales.

I think the pace of change for Java has suffered because of all this.

Microsoft continues to develop C# because the revenue continues to pour in, Anders is still with them, and they're a software company that ultimately makes money from the product. That's why they're ahead now.

duffymo
Microsoft develop their languages because it's all "developers developers developers". if you're trying to sell operating systems, the most important thing to do is make software developers want to develop software for your operating system.
MarkJ
If Microsoft's twin cash cows, the operating system and Office, are ever supplanted I'll bet that "developers" will go on the back burner, too. Does the cash drive the strategy, or the other way 'round? You need both.
duffymo
My point was it's not the revenue from C# that drives its development, it's the revenue from the cash cows. That's not totally clear to me from the wording of your answer - they make "money from the product" - which product? +1 anyway
MarkJ
"the product" in this case being the software they sell. You're correct, it doesn't distinguish between OS, Office, and C#.
duffymo
@duffymo; I've read it two times, really great, everybody in this topic have to pay attention your words.
sirmak