24

C# has a good momentum at the moment. What are the features that you would need to have in order to switch (or return) to Java?

It would also be quite useful if people posted workarounds for these for the current Java versions, e.g. Nullables being wrapped around custom classes, to make this a much more interesting wiki.

8
  • 31
    This should be a community wiki Oct 20, 2009 at 14:24
  • 3
    by reading all answers it seems java don't stand anywhere infront of .Net, closures, clr, lambdas, anonymous functions... omg Oct 20, 2009 at 15:03
  • 3
    But isn't 'syntactic sugar' giving you a productivity gain really? Even if it is just for prototyping!
    – NT_
    Oct 20, 2009 at 15:57
  • 1
    @jsight - I haven't used any others, but NetBeans and Eclipse are usability hell. VS is magnificent, for C# at least.
    – Joren
    Oct 20, 2009 at 19:06
  • 7
    The syntatic sugar argument can be made for everything beyond the most primitive implementation of a turning machine.
    – Jherico
    Oct 20, 2009 at 23:16

24 Answers 24

33

As a .NET/C# developer here are the missing features that annoy me. This list in no particular order - just as thoughts come to mind:

  1. The Java library is too small. For common things I have to choose between 5 competing open source products because the base library is lacking in so many ways.
  2. This is an Object Oriented programming language right? Why in the heck do primitive types not inherit from "object"?
  3. Pointers
  4. Lambdas
  5. Closures
  6. Partial Classes and to a lesser extent partial Methods
  7. Real support for Generics
  8. Using statements and Dispose - this was a real WTF for me. You really have to explicitly close connections in try/catch blocks. Poor Java guys!
  9. Yield return would be nice
  10. Unsigned integers - again WTF? I have to use number types larger than I need for what purpose again?
  11. In Java you can return from final blocks of try/catch. A co-worker confused the hell out of me for hours by introducing a bug this way. This behavior should be prohibited as in C#.

I rarely have to use Java and when I do, I have all sorts of WTF moments.

Edit: I Removed for-each comment based on the fact it is no longer a missing Java feature since 1.5.

17
  • 7
    Would you mind explaining 12? I've not done anything major with C# but how does it foreach differ from Java for(Object : collection)? Oct 20, 2009 at 15:01
  • 20
    The Java library is too small? That's news to me :) Oct 20, 2009 at 22:57
  • 3
    Ma teacher told me that Pointers are baaad ;) Oct 21, 2009 at 0:40
  • 10
    Please don't mix pointers into my higher level language. Oct 23, 2009 at 18:36
  • 7
    Very true, Java has some short comings. But it's always easier to be the guy learning from someone's mistakes (C#) than the guy first implementing the language. Let's be honest C# is a port of Java to .NET. We could talk about how insanely ugly Visual Basic is. Apr 28, 2010 at 11:24
20

In my experience, Java vs. .Net is more of a business decision than a technical one. Shops with MS experience trend towards .Net and shops with Java experience trend towards Java & OSS. I've seen little evidence of people switching based upon language features. On the other hand, I've seen shops heavily tilt towards one platform b/c of one or two key employees they wanted to hire being knowledgeable in that area.

9
  • 13
    I work on .NET projects and still use lots of OSS. I don't think it should be attached to just the java side.
    – Mike Two
    Oct 20, 2009 at 14:30
  • 1
    @Mike - You are, of course, correct that there are .Net projects that use lots of OSS (I'm on one now... not as much OSS as most Java projects that I've been involved with, but definitely a significant amount). Having said that, as a general rule (lots of exceptions), I've seen much less in .Net projects than in Java. For example, I've seen server side guys in .Net who have never even heard of a logging framework (they reimplemented their own... badly). I've yet to meet one in the Java world thats not familiar with at least 1.
    – jsight
    Oct 20, 2009 at 15:10
  • 1
    @John - I think in some ways, you have proven my point. Java w/ generics was released in September of 2004. C# with generics was released w/ Visual Studio 2005 in October of 2005. There was never a time when C# had generics and Java didn't.
    – jsight
    Oct 20, 2009 at 15:13
  • 2
    The single feature that unambiguously determines that .NET is unusable for us, is that we do not deploy on Windows. Oct 20, 2009 at 15:28
  • @jsight - I agree. It is true that you are more likely to find OSS in a Java shop. I just thought your answer made it sound like you would only find OSS on a java project. I still voted for your answer because I agree that it is more of a business decision in most cases. Admittedly I'm picking on a detail that does not detract from the quality of the answer.
    – Mike Two
    Oct 20, 2009 at 15:29
16

in no particular order:

  • function pointers (delegates); the whole passing interfaces around thing is stupid
  • real generics; what's the point of having type safe generics if the compiler can't even hold the meta data through a unit's compilation?
  • ui speed; all the self-drawing ui libraries are very slow compared to native controls wrapped in "managed" libraries, not to mention that microsoft's self-drawn ui is hardware accelerated through direct3d
  • an yield return construct; c# is so user friendly in this it's crazy
  • operator overloading
  • linq; just cuz its so addicting
  • properties; more synctatic sugar you get addicted to
  • better interop with native code; c#'s p/invoke and native com support makes interop so easy compared to jni -.-
  • first class value types; this goes hand in hand with real generics, having generic lists that never box/unbox in c# is part of why c# is faster than java.

and i'd say this is the most important one:

  • a responsive, informative debugger; nothing can even come close to visual studio right now
2
  • 4
    About debugger and visual studio in general - try IntelliJ Idea (it's opensource now), VS is nothing but a fancy notepad compared to this program. I agree that self-drawing UI is slow, but it's the best solution for cross-platform development. Oct 21, 2009 at 0:37
  • 4
    @Piligrim: Are you really trying to say the .NET/C# debugger is out of date? Have you used it? Oct 23, 2009 at 18:40
13

Just going off the cuff, I think the biggest thing Java 7 needs that everyone is lamenting the lack of is closures.

3
  • Let's hope that they will consider them. Any ideas on how to influence such decisions?! :)
    – NT_
    Oct 20, 2009 at 16:02
  • I hope they don't. If you want closures use Groovy or what have thee. I would like them to add CICE+ARM Oct 20, 2009 at 16:13
  • 4
    Adding closures to our existing code base would be far better than rewriting everything just to take advantage of one language feature.
    – MattC
    Oct 21, 2009 at 13:37
13

I'm a C# programmer and about one year ago I had to participate in the development of an application in Java. What I missed the most was:

  • Visual Studio (Eclipse is nice, but VS is VS, especially Team Edition)
  • Comparing strings with ==
  • Properties
  • Basic types as first-class objects (e.g. not "int" type vs "Integer" class)
  • Anonymous methods (a workaround can be made by using anonymous classes but it is not the same)
  • LINQ

And there was one single Java feature that I missed when I went back to C#: explicit exception declaration in method signatures.

DISCLAIMER: I am speaking about a somewhat old project, I don't know if some of these features are present in current versions of Java.

6
  • 1
    +1 - I missed the same aspects.
    – Daniel May
    Oct 20, 2009 at 14:41
  • Explicit exceptions (checked versus unchecked) is a big issue of debate. Many loathe checked exceptions. Could you tell more about why you missed them? I'm curious to hear it from one who tried both seriously. Oct 20, 2009 at 20:36
  • I missed them because it forced me to write self-documented code. When you deal with exception management code, you always know in advance which exceptions you can encounter, which reduces the risk of application-wide-unexpected-exceptions. In .NET, you can only hope that the developer of the library you are using was kind enough to document all possible exceptions thrown by the public members.
    – Konamiman
    Oct 21, 2009 at 7:10
  • 2
    The point of the .NET way is that you shouldn't have to document the exceptions. All exceptions thrown are by definition unexpected. I'm not saying it's better or worse than Java, just that when used correctly it makes sense. Oct 22, 2009 at 10:42
  • 1
    Having to write in java after having developed in C# is one of the worst things that can happen to a programmer. Its like being asked to drive a sub $20k car when you were used to driving a Tesla.
    – morpheus
    Nov 2, 2015 at 18:22
11

Less heinous XML parsing and manipulation tools. Doing anything with XML in Java sucks.

3
  • 3
    Ahhh. so true! When you can, use JSON instead. Oct 20, 2009 at 23:05
  • 4
    Since when is JSON easy to generate in Java?
    – Matt Ball
    Oct 21, 2009 at 21:30
  • Jackson makes it pretty easy.
    – MattC
    Oct 12, 2012 at 19:28
10

I'll also give one answer the other way around. C# needs an enumeration implementation like Java has. Java's enumerations rock!

Let me add anonymous overrides to this list also. Sorry to go off topic, but C# needs the ability to anonymously override methods. I have been switching back and forth between Java and C#, and I have to say for unit testing legacy code, there is nothing better than anonymous class overriding.

6
  • 2
    C# enumerations are completely type safe base types, Java enums full fledges classes with a nice const preset syntax. C#'s enums will be far more performant as they are completely value based.
    – Dykam
    Oct 20, 2009 at 14:31
  • What? Why is the Enumerator class better? All I've experienced of it is just a verbose way of doing it the C# way. Oct 20, 2009 at 14:51
  • 3
    The enumeration class in Java allows you to have methods and treat it just like any other class. This is really useful for giving functionality to your enumeration. It also makes a really easy singleton. Oct 20, 2009 at 15:01
  • 1
    @John:it's benefit is small. enumerations in c# is as fast as an integer variable (it's integer by default but you can define it as a byte for example)
    – sirmak
    Nov 20, 2009 at 19:18
  • @Dykam man if you are worried about performance at that level aren't you more concerned with all C#'s basic types being objects? Or, if you assume the compiler is smart enough to optimize one, why not the other?
    – Bill K
    Sep 10, 2010 at 21:46
9

I would need function pointers of some sort. The ability to use delegates in C# is so useful. There are so many times in Java where I want to create a map of delegates or function pointers as the solution, but I can't. I know you can simulate a similar thing in Java, but having the abstraction as part of the language is a huge plus!

4
  • 4
    Anonymous delegates and lambdas would be fantastic - an anonymous classes like "new Delegate() { public void Invoke(String s){ return s+s; } }" just isn't usable compared to "s => s+s". Oct 20, 2009 at 14:45
  • 1
    This is as far as I can see syntactic sugar around existing facilities? Is this right? Oct 20, 2009 at 15:27
  • 2
    I don't think it need function pointers. What it needs is (mostly) the current semantics without all the boilerplate. Oct 20, 2009 at 15:30
  • You could simulate this with classes and interfaces, but it is more cumbersome, isn't it?
    – NT_
    Oct 20, 2009 at 16:03
9

Momentum. I have done a lot of development on both platforms. I'm enjoying the .NET side more because of the way the C# language is evolving. Java's evolution seems to be more a reaction to C# than an actual vision. So I think the best thing for Java to do is ignore .NET and create something new of its own.

5
  • Curious about the down vote. I think you're well within your rights to disagree and vote down. Not required to comment, but just wondering.
    – Mike Two
    Oct 20, 2009 at 15:40
  • How can you say that when C# was largely inspired by Java? At worst, it is co-evolution, isn't it?
    – NT_
    Oct 20, 2009 at 16:06
  • 2
    @ _NT - Agreed that it started that way, but then C# seemed to take the lead in terms of speed of evolution. It was first with generics and attributes just to name 2. So I think it is more in the driver's seat. C# is now influenced by many other languages and programming paradigms such as functional programming and dynamic languages. Those influences are not from Java anymore. After the initial release of C# I can't think of a feature that Java added before C#. But of course the core part of C# is inspired (or even copied) from Java.
    – Mike Two
    Oct 20, 2009 at 16:17
  • 1
    Java's evolution now might be reactionary to C#'s, but I beg to differ that this was the case a couple of years ago. Apr 28, 2010 at 11:11
  • @Richard - I didn't say it has always been reactionary. Clearly it can't have been for it's entire lifetime.
    – Mike Two
    Apr 28, 2010 at 11:49
8

Another one I would like is some equivalent to LINQ. I noticed how much I actually depend on the ability to use LINQ when I tried to do a top coder competition and realized they only support .NET 2.0. Once you get used to using LINQ to solve problem and make it part of your regular programming vocabulary it is very difficult to not see problems in that light. It is akin to using generics and then not being able to use generic.

1
7

I think, choice between Java and C# is not a question of language features, but a question of platform and ecosystem choice.

So, I doubt that any new syntactic sugar in Java or C# can lead to a significant amount of switchers between the platforms.

After all, JVM world has Scala and many language-sensitive developers are using it in some way.

5

I think, you should consider swithcing this holywar from "Java vs C#" to "JVM vs CLR", because JVM is (in the last years — mostly) not only Java, but also Scala, Groovy, Clojure, JRuby, Jython, and dozen of JVM-languages.

4
  • 1
    Doesn't this apply to CLR languages too?
    – NT_
    Oct 20, 2009 at 14:48
  • 1
    I found another one: jabaco.org Oct 20, 2009 at 15:44
  • 1
    @nt I mean, the author tries to compare [probably] the best clr language with [IMHO] not the best jvm language. Which is not really "fair", I suppose.
    – George
    Oct 26, 2009 at 8:19
  • Agree with folone. Clojure and Scala are far better than Java, and I would argue that Clojure is far more powerful than C#. Apr 28, 2010 at 11:10
3

Properties!

Anonymous objects are nice too

5
  • Java HAS properties already (but they probably are not what you think of :) ) Oct 20, 2009 at 15:31
  • 1
    I don't really get properties As I understand they have to be declared public in first place right? if you declare your attributes as public in Java you'll get the same result public String name; employee.name I know you can also "add" actual code in the get/set but that's discouraged.
    – OscarRyz
    Oct 21, 2009 at 1:27
  • 2
    @Oscar - Properties are simply syntactic sugar for get/set methods (and don't have to be public). It is not like declaring a variable public as the property can do stuff (just like any other method). I use to be dead against them but after using them for a bit they do make the code a little bit more readable. Oct 21, 2009 at 8:55
  • 3
    No, you can have any access modifier on C# properties. You can also have different access modifiers for the get and set parts of the property. E.g. a public getter but a private setter. Not sure why you say adding code in getters/setters is bad, there are plenty of examples where this is a good idea (authentication, logging). In C#, if you don't need to add any custom code, you can use automatic properties, e.g. public String name { get; set; } .No more complex than a public variable, and if you need to add code to it later, you can expand it.
    – JonoW
    Oct 21, 2009 at 8:56
  • 1
    In general, the need for properties implies you might be programming better. Not always, but I can tell you for certain that if you always add setters whenever you create a property you are doing it very wrong. Getters--meh, sometimes you need them.
    – Bill K
    Sep 10, 2010 at 21:41
2

Continuations, like Scala (on top of the rest) would be good too, for agents development.

2

Support to run over CLR (and vice versa perhaps for JVM) without IKVM and other such layers.

2

Let's be clear that we need to distinguish between Java and the JVM. I actually switched from C# to Java, but I admit it was not because of Java's amazing language features! In my very humble opinion, C# is the better language, and CLR is the perhaps a more elegant VM. However, even with Mono, you're not writing applications that run everywhere!

I think the greatest argument for Java is the amazing community it has. This is where the cutting edge technology is being developed, not at Sun (now Oracle). The Java community has consistently been the leader in developing Enterprise technologies. For instance, how long did it take Microsoft to provide a DI Framework? Where's AOP in .NET? When I start a .NET project, my foundation is Spring.NET, a Java port. When I need ORM, it's NHibernate. Need a testing framework? NUnit. I realize there are other OSS projects for the .NET platform, but their numbers and support from Microsoft are laughable compared to the Java community.

1

on the other side, has .net got enterprise open projects like Terracotta (semi commerical), Infinispan, Compass ? no. ncache (commerical), lucene.net are far behind them. Especially Terracotta is unique, it can improve some of your app x100, it's simply perfect and free (partitioning is commerical). If we implement a high load app in both .net with anything and java with terracotta + hibernate + terracotta-hibernate-integration, java app will probably far more performant than .net one. Ther're some ports to .net like nhibernate, log4net, lucene.net, but all of them are trying to catch java versions. And entity framework is a disaster, they have to start with nhibernate as the base or get some lessons from them.

.net is only working on windows (mono is far from enterprise, there isn't any enterprises using it), how much money does myspace.com spent for their 4000 windows web server licences ? 1 million ?

You can't install a simple plugin to VS (and can't do some other things) if don't buy professional edition,

Some windows instance types in amazon web services are nearly x2 price of the linux ones.

if you look at ohloh.net open source java project counts (with language comparison tools), you'll see that java has x5 more volume than c#.

also Java has %20 share on worldwide while c# has %4.x (source:tiobe.com)

Look at the top web sites; only microsoft and myspace are using .net. google, amazon, ebay, linkedin, alibaba, twitter (switched to scala from rails)... many of them are using java and many others are using php, ruby (facebook, yahoo,..)

As a language Java is far behind c#, but Scala (runs on jvm) is as good as c# and it's performance is nearly same as java and also it can use all jdk and other java code as his library.

I'm not saying java is better, but I'm saying java is as valuable as .net, too.

1

A native 'decimal' type for Java replacing the BigDecimal class would be nice. But Java thread-safe collections are nice.

Perhaps the question is not so much what Java 7 needs to persuade developers to use it, but more a case of what makes developers want to move from Enterprise/server-side java language to a different C# desktop Windows-only oriented world?

For most developers, the language isn't difficult to pick up be it Java or C#. I develop in Java, but Linq didn't take long to understand and use.

I think the choice of Java or C# depends on what motivates you personally -perhaps money? in which case either language will do whether they have certain features or not.

Ste

1

They should start by fixing the Calendar/Date related classes, even that seems too much to ask.

0

A simple way to map values in your model to the UI (like bind in Java/FX)

0

I think it depends on bussiness decisions, not the languages themselves. But I really really really love C# lambdas and curry :D :D

http://mikeomatic.net/?p=82

0

a map({codeblock}) which runs over anything iterable would be nice. And filter too. And being able to return multiple values easily from a method.

(a,b,c) = getThreeValues();

(would assign the individual variables a, b and c).

Actually I just think they should have Haskell as a supported scripting language on the JVM :D

0

linq, lambda, anonymous types

0

I don't see any point in "luring" anyone anywhere. They solve different problems and you should use whichever one suits you.

Java has less "Language" and less structures to trip up new people, it's platform independent and it doesn't change too fast allowing old code to stick around for a LONG time (Good for some large companies).

C# has tight desktop integration and a slew of nice features that make it more fun to program. It has .net integration. It has pointers, closures, etc which make it harder for n00bs (a valid language target, hence Basic) but more fun for experienced programmers--I haven't convinced myself that these features make you more productive, but in some situations they can make your code a lot nicer! Also if you need pointers, you need pointers.

I don't see a whole lot of overlap in target audiences. Why change a language to attract programmers when it's healthier for the entire industry to have two healthy languages each targeted at solving different problems attracting different developers?

1
  • Because being a "n00b" language as you call it, will actually hurt Java not help it in any way. Lack of modern features do make Java easier to learn, but also make Java applications harder to write (due to the lack of modern features). It's like Pascal vs C in the old days, Pascal was used for learning (by n00bs) but C kept gaining ground because it was more "powerful", until Pascal faded away. Sep 10, 2010 at 22:14

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