Slashdot Mirror


Java 1.5 vs C#

SexyFingers writes "Sun released Java 1.5. The non-API stuff that they've added made it finally "catch-up" with C# - since both languages are built to support OOP from the ground-up, their constructs become almost identical as additional OOP "features" are supported. So if you're doing C# and your foundations in OOP are rock-solid, there really isn't any difference whether you're coding C# or Java."

Here's the list of enhancements to the Java Language:

  1. Generics (C# 2.0 already supports this)
  2. Enhanced For-Loop (the foreach construct in C# 1.0, duh!)
  3. Autoboxing/Unboxing (C# 1.0 already has this, everything is an object, even the primitives - not really, but they do it so well...)
  4. Typesafe Enums (again C# 1.0 already implemented this, but I think they've added a little bit more twist in Java, that its actually a better implementation)
  5. Varargs (C# 1.0's params construct, ellipsis construct in C++)
  6. Static Import (I don't know if C# 1.0 has this, or C#2.0, but C# has a construct for aliasing your imports - which is way cooler. Static Import, actually promotes bad coding habits IMHO)
  7. Metadata/Annotations (this is C# 1.0's Attributes, Sun's upturned noses just gave it a fancier name - also, C#'s implementation is better and more intuitive)

They've beefed up the API some, and integrated several packages with the regular JSDK that used to be a part of a separate package or installation ---in my NSHO, the Java API has become bloated...

At this point (even before Whidbey) the deciding factor (as always) for Enterprise work, when choosing a language platform, should be the support it has behind it, in terms of IDE, tools, api, and longevity of the vendor pushing it (forget the OpenSource crap argument, those guys are too in love with Perl, Python, and Ruby - Java could become the child nobody wants to talk about if Sun dies) - right now that's C# and the .NET Framework ---

If you ask Paul Graham though, both language would be utter crap and fit only for idiots :) http://www.paulgraham.com/gh.html [I'm exaggerating, so hold off on those flames.]

23 of 790 comments (clear)

  1. I code C# for a living by carpe_noctem · · Score: 4, Insightful

    ...and let me tell you, java doesn't have to do that much to "catch up" to it.

    --
    "Quoting famous computer scientists out of context is the root of all evil (or at least most of it) in programming." - K
    1. Re:I code C# for a living by Westley · · Score: 4, Insightful

      So if you find C# abstract, where *exactly* is Java better, as a language? Or were you actually comparing the libraries? (Which bit of C# itself took hours for you to figure out?)

      Personally I find them reasonably equivalent, but C# has a few advantages (properties, delegates, events) and the .NET library has had fewer iterations so is less internally inconsistent than the Java libraries at the moment.

    2. Re:I code C# for a living by GCP · · Score: 4, Insightful

      And I was a member of one of the JCP expert groups that brought you Java 5.

      java doesn't have to do that much to "catch up" to it.

      Stated another way, Java 5 is still behind C#, to which I would agree.

      As to how far behind, that depends on what you value. Java's event handling/callback design is atrocious compared to the convenience of delegates. I would much rather pass a single method called OnAccountOverdrawn()to the event notifier than the Java style of making the whole class an instance of some interface, implementing stubs for all the useless methods of the interface, then implementing the one useful method--which will have a useless name like DoAction() that you can't change, then passing the object that contains the DoAction() method to the event notifier.

      And for many things such as generics, autoboxing, enums, etc. (I don't recall which ones specifically), there are actual semantic differences in the virtual machine for C#, whereas Java's knockoff versions are just syntactic sugar for the writing out the equivalent source code yourself. I AM in favor of syntactic sugar, but having the actual semantics available in the underlying runtime gives you additional advantages.

      Java's great advantage is its ubiquity, which is also an impediment to improvement. Sun's position was that it was pretty much finished with language improvements after Java 1.1 and would thereafter concentrate on libraries that would run on existing JVMs. New JVMs might run the code even better, but the old JVMs would still run it.

      Microsoft knew they had to do better, or nobody would switch. They did a lot of things better, and they seem committed to doing more, even if it means obsoleting their existing VMs. They have far more control over The (One) Platform and seem quite willing to make improvements to C# and the other .Net technologies that will require a VM upgrade.

      One catgegory of improvement they seem interested in is a way to make dynamic languages, like Python or Lisp, work REALLY well. Another is support for functional languages like Haskell or OCaml that have special needs of their own.

      And if they do it well, (my speculation now), they could even add some of the attractive features of those languages, languages I like more than C#, to C#, widening the gap with Java.

      Java might have a very hard time keeping up with C# improvements while anchored to existing runtimes, and letting go of the anchor would seriously impact its ubiquity, which is one way in which Java is vastly better than C#.

      I don't think it's a given that Java is going to catch up to C#. But if Mono and/or DotGnu don't succeed, it may not matter as Windows fades away (which I believe it will).

      --
      "Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
  2. I'm confused by abrotman · · Score: 4, Insightful

    Where's the story? Or is this just one person's interpretation of Java vs. C#?

  3. flamebait by Bert690 · · Score: 4, Insightful
    It's times like this when you'd REALLY like the ability to mod the story itself as troll/flamebait!

    At this point (even before Whidbey) the deciding factor (as always) for Enterprise work, when choosing a language platform, should be the support it has behind it, in terms of IDE, tools, api, and longevity of the vendor pushing it (forget the OpenSource crap argument, those guys are too in love with Perl, Python, and Ruby - Java could become the child nobody wants to talk about if Sun dies) - right now that's C# and the .NET Framework ---

  4. Cue the zealots on both sides by JUSTONEMORELATTE · · Score: 4, Insightful

    Why again can't I mod a story as -1 Flamebait?

    --
    I'll pay you $10. Really.

  5. Why is there a C# advertisement on /.? by Cloudgatherer · · Score: 5, Insightful

    Seriously, this looks like an ad for C#, a bunch of claims with very little support/evidence for those claims.

    I've worked on C# and Java projects. As far as I'm concerned, C# = MS Java. MS could not control Java, so they abandoned support for it and built thier own "version." It's really a rinse & repeat cycle for MS: see successful software, build own version of said software to try to take over that market as well.

  6. I call bullshit by The+Bungi · · Score: 5, Insightful
    There is no apparent point to this "story". It's full of grammatical errors and obvious flamebait arguments (flamebait in the context of the slashbot groupthink). What, "C# is teh roxx0rz and Java.. well, I forgot teh point I was makeing for Java"? "The open source crap argument"? Way to go.

    Here's my theory. Along with the ubiquitous slashvertisements and the Microsoft-bash-of-teh-day barrage posts, these are a perfect opportunity to create a story that will generate 1,000+ comments and ten times those many page views and ergo ad impressions.

    C'mon, C# vs. Java? Outside of "RIAA sues 86 year-old grandma", "We hate Bush, let's talk" and "Microsoft patents KDE" there is no better source of inflammatory material in the dorkosphere.

    Sad, really.

  7. Re:Sounds a lot like religion by jayminer · · Score: 5, Insightful

    I code C# for a living, so according to your definition, sold (or more appropriately rented) my soul to the devil. (This does not change the fact that I personally prefer free/open source technology. My PDA, my media players, my home operating system are all free/open source based.)

    Java is not any more closer than C# to open source technologies. Sun doesn't like open source, just as Microsoft.

    It's a very well known fact that Java has been a base (or in other words "the" figure) for Microsoft while developing C#, but that does not imply that "Java is good, C# is bad" or vice versa.

    I would be happier personally to code in Java, but professional life yields to disqualify who resists new technology.
    Your choice of programming language is not your religion, and it can change continuously through your life. Just like your operating system.

  8. Important differences between Java and C# by daveho · · Score: 5, Insightful

    While neither Java nor C# is truly free of being controlled by an Evil Corporation(tm), Java at least has multiple vendors, runs on a wide variety of platforms, and has an open standardization process.

  9. With C#, stuck in windoze by JPyObjC+Dude · · Score: 5, Insightful
    so if you're doing C# and you're foundations in OOP is rock-solid, there really isn't any difference whether you're coding C# or Java.

    He kind of forgot that there are many programmers and customers who DON'T want to deploy their systems on win32. With Java apps, you don't have to. In fact you can choose almost any operating system and hardware. Anybody who chooses C# over Java for enterprise deployments is truly a MicroWeenie.

    I much prefer my 8 processor HP UX box any day :]

    1. Re:With C#, stuck in windoze by pesc · · Score: 5, Insightful

      You are right. One main feature that Sun designed for Java was WORA (Write Once Run Anywhere). M$ thought this sucked. They tried to destroy that feature and got sued over it. So the invented C# instead. C# isn't WORA, it is WORM (Write Once Run on Microsoft). With C#, you are locked in again. That's the whole point with C#.

      --

      )9TSS
  10. Re:APIs by AKAImBatman · · Score: 5, Insightful

    Let me know when stuff like an XML Parser and MD5 are native in Java.

    They ARE.

    XML package
    MD5 and SHA support

    The former has been in Java since 1.3, and the later since 1.1(!).

    Honestly, Java has every feature and the kitchen sink in its core APIs. And if a feature isn't there, it's very easy to write a library to add it. That's why programmers like Java so much.

    Any other features you'd like me to find for you?

  11. Re:Mistake by Sanity · · Score: 4, Insightful
    Java was a fairly nice middle-ground betweeen high and low level programming, and what appears to be an effort to become a high level language is rather ominous for those who are interested in testability and performance in Java.
    Generics improve testability because they largely eliminate runtime ClassCastExceptions. I haven't seen any evidence to show that any of these features impose a performance penalty. Most just make the developers life easier by saving them from repeating common code patterns.
    This, BTW, is why you don't want your language to be controled by a company which in turn has a marketing-driven bottom-line.
    Yeah, because hardly any companies are driven by their bottom lines...
  12. Re:Flaws in both Languages by scovetta · · Score: 4, Insightful

    You use PHP/Perl on a server? For something other than adding phpbb to your homemade website? Sorry, but PHP/Perl serves a purpose, and so do Java/C#, and they two are almost mutually exclusive.

    For enterprise-grade web-applications (not hacks), it's .NET or Java. For real applications, it's either .NET, Java, or C++.

    End of story. Don't argue with me, just accept it.

    --
    Wer mit Ungeheuern kämpft, mag zusehn, dass er nicht dabei zum Ungeheuer wird. --Nietzsche
  13. Re:Flaws in both Languages by nat5an · · Score: 4, Insightful
    Who modded the parent up? The post is woefully inaccurate.

    1. What exactly does it mean if a language is "open source?" Surely, the specification is available for free. If you wanted to, you could write a lexer/parser/compiler without paying anything to Microsoft/Sun. Do you mean that the tools provided by the companies aren't open-source?

    2. C# doesn't "require" a virtual machine any more than Java "requires" a virtual machine. One could write a native compiler for both. Additionally, in fact, Microsoft's .NET implementation does just-in-time compilation of the .NET assembly generated by the C# compiler (the bytecodes, basically), so it doesn't actually run inside of a virtual machine, nor is it interpreted. Since Sun's javac is supposed to generate portable bytecodes to run on different architectures, they decided to use a VM to avoid having to write a thousand different JIT compilers.

    Neither of these are inherent weaknesses in the specifications of the languages, they're implemetation details. Since this story is supposed to be about new language features in Java, I don't see how bitching about Microsoft/Sun's implementations is really relavent.

    --
    Head down, go to sleep to the rhythm of the war drums...
  14. Re:Java 1.5 vs c# 2.0? by Anonymous Coward · · Score: 4, Insightful

    Comparing an unreleased version of C# to the available version of Java is just stupid. Further, with no mention of the provided API any discussion is a waste of time. While JAVA offers a bloated API, it is extensible and great for programming, unlike dot NET 1.1 which seems to be an attempt to build OO on top of a procedural framework that doesn't provide the programmer with the same level of flexability. The other thing to consider is that dot NET means normally a purchase of Visual Studio, while JAVA normally means a free download of the JSDK and JCreator. Also IMHO Java doc is much better then the stuff that comes with dot NET. The rest is rant......

    Comparing a released software product that is available almost for free to an unreleased product that costs hundreds of dollars is just dumb. Where is the story here?

  15. Ravioli Code by Ian+Bicking · · Score: 5, Insightful

    I think the problem you are seeing is Ravioli Code; a (perhaps excessive) reaction to spaghetti code. Also Java (and probably C#) programmers seem to take Patterns too seriously as well, patterns should be descriptive, not prescriptive.

    1. Re:Ravioli Code by metamatic · · Score: 4, Insightful

      Similarly, object orientation should be used as a tool, not enforced as a religion. If an object-oriented API to some functionality is the cleanest and most useful, implement that way; otherwise, don't. If the best way to build something is using functional programming, do that; don't try and force the code into an object-oriented paradigm.

      --
      GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
  16. Re:Meanwhile, C++ goes nowhere by cpghost · · Score: 4, Insightful

    C++ is a great language, but it's choosy about its friends. It takes some time to master all (well most) advanced aspects, but as soon as you do, nothing beats a good C++/STL combo.

    What I don't like about C++ standard, is the lack of a decent socket library that would be part of the i/o streams. There are non-portable classes for this of course, and everyone could roll their own, but it's not in the C++ standard (yet).

    IMHO, one of Java/C# biggest advantages over C++ is this particular aspect. Not that it would convince me though to switch away from C++ to Java, which simply doesn't cut it yet.

    For fast prototyping, I'd stick to Python, but when performance really matters, C++ is still king!

    --
    cpghost at Cordula's Web.
  17. Re:Too bad we can't mod articles by Slime-dogg · · Score: 5, Insightful

    I wouldn't give Java the credit for C#. If anything, it was Delphi that C# was built upon. The only thing that C# "borrowed" from Java is the idea of a VM, and even that functions in a different way than the Java one.

    --
    You need to restart your computer. Hold down the Power button for several seconds or press the Restart button.
  18. Welcome stranger! by Oestergaard · · Score: 4, Insightful

    Welcome to planet earth - we also have a language called 'C++', but it is rather different from what you describe.

    Here, we have compilers that can do bounds checking - avoiding buffer overflows, if you decide to use them.

    However, the template feature of our C++ is so powerful, that when used together with structs and classes, one can produce beautiful code that is extremely powerful, yet so simple that it is easy to ensure it is not susceptible to said buffer overflows (or memory leaks or the thousand other plagues of much of the software that surrounds us).

    This is why there is actually not anything fundamentally wrong with our C++. We are some who want template namespaces though, but outside of little issues (that do have workarounds) like that, the only things we really want is additions to the (already powerful) standard library, the STL.

    One problem remains with our C++ though. We live on a planet inhabited mainly by clueless morons, people who do not like to learn, people who refuse to accept that maybe others have seen farther than themselves. This is why we, too, have a lot of problems with software in general - buffer overflows as you mention, among many other problems.

    I am sure we can arrange for you to get a copy of our C++ standard - that will allow a clever individual, such as yourself, to write software without the problems we discussed. I would then suggest that we join our efforts, in teaching the unwashed masses how to actually use the language properly, so that we will not have to re-do all software in the world (both ours and yours) by ourselves.

    Deal?

  19. Re:Java 1.5 vs c# 2.0? by swilver · · Score: 4, Insightful
    C's implementation of abstracting machine code is just a compiler hack, the underlying machine code has not changed. The only benefits are some compiler errors and warnings and not performance and storage efficiency that real machine code can offer.

    Seriously, I couldn't care less about better performance. I care about being able to avoid probably 75% of all casting that goes on in our 10.000+ source file project and being able to specify our API even tighter and catch more problems before it hits our customers.

    I just wish Sun had done this 3 years ago, but better late than never.