Slashdot Mirror


C# From a Java Developer's Perspective

Microsoft's C# has raised eyebrows, interest and debate since its official announcement last year. The prolific Carnage4Life (Dare Obasanjo) has completed a detailed comparison of C# and Java, outlining the things that are identical, similar, nearly the same, or completely different between the two languages. If you're considering learning or applying either one, you might benefit by reading this paper first. There are some other excellent comparisons to be found linked from the Open Directory Project as well. Update: 11/20 03:35 GMT by T : Note: here's a mirror; interested readers who mirror the mirror get good seats in heaven.

25 of 507 comments (clear)

  1. The lesser of two evils by Walter+Bell · · Score: 5, Insightful

    Disregarding the fact that Java and C# are both "closed" languages controlled by large corporate entities with their own self-interests in mind, they both do an admirable job of bridging the gap between general purpose scripting languages and C++. Having used C# and Java on Win32 extensively in the past year, I have become accustomed to the automatic garbage collection, quick execution speed, and logically consistent design of both languages. The Windows compilers / runtime engines for both languages are quite amazing, and something for the fledgling gcj to aspire to.

    Although C# does deliver superior integration with Windows and .net (which is good for MS-only developers and bad for multiplatform programmers like myself), I'd have to pick Java if it was up to me just because of its sheer elegance. It seems like Sun did a better job designing a general-purpose language (applet "security" extensions aside), and Microsoft just tried to copy Java but add in proprietary extensions to hook C# into Windows. Thus, some of the C# features seem to be "bolted on", whereas most of Java came across as being very natural to me.

    Just my 2c...

    ~wally

    1. Re:The lesser of two evils by Steveftoth · · Score: 5, Insightful

      If c# takes off for windows programming I think it will be because people will be able to build responsive GUI programs with it. The largest problem with Java is people's conception that it is SLOW. Java coders know that is not true in general. However, AWT and Swing are slower then they need to be because of their cross-platform compatability. If you can build a responsive GUI program in less time using C# then I think it will be the language of choice for many coders. C++ takes more time to get all your bugs out, Java gets rid of the possiability for many bugs, (while introducing others, but there are less overall) and reduces time of coding.

      Also, you'll be able to use all the newest 'must have features' that MS tries to shove on the consumer in C#.

      For now, I'll stick with Java because it's libraries are much better. Not just the ones that Sun wrote, but more importantly, the ones that other people have written.

  2. Re:Non Portable by PylonHead · · Score: 2, Insightful

    An observation that I respect and agree with. But there are already many, many people coding websited in ASP/COM/SqlServer.

    They have already sold their souls, and have nothing to lose.

    --
    # (/.);;
    - : float -> float -> float =
  3. C# and .NET vs. Java Enterprise APIs and tools by MarkWatson · · Score: 4, Insightful
    Good summary of similarities and differences between Java and C#.

    I spend most of my time in the Java world (I have written 5 Java books, the latest of J2EE, and almost all of my consulting is done with Java.)

    That said, C# and Visual Studio.Net are very cool.

    Since Java is not my language of choice (hey, I would use Common LISP more if there were more consulting jobs requiring LISP!), I would not be too bothered if I had to use C# and the .Net stuff.

    Really, what really matters is finding interesting jobs to do, not the development platform.

    I also have high-hopes for interop between the Java J2EE world and .Net using SOAP. (I am working on SOAP support for Common LISP in my spare time so Lis can play nice with .Net and J2EE.)

    Best regards,

    Mark Watson

  4. Come on now: Have you ever really used C#? by ergo98 · · Score: 5, Insightful

    Seriously though, have you? From your vague, unsubstantiated, no example posting it sounds like you use and know Java, therefore you can proclaim yourself knowledgable about C#. Your claims about the "bolted on" aspects of C# are particularly suspicious given the "hooks" into Windows are simply objects instantiatable from the .Net Framework (they're not "bolted on": Just like Java you include the unit and create objects from it). If anything C# takes some of the goofy aspects of Java, such as the interoperation with properties via methods, and cleans them up to make an abstract behind the scenes property handling system (ripped straight from Delphi's object pascal I would guess).

  5. Standardization? by mugnyte · · Score: 3, Insightful

    Language improvements have historicially opened the door to new productivity - in real terms - of apps getting cranked out. Higher and higher encapsulation in text or GUI worlds...but they don't all stick to the wall.

    One cannot always tell beforehand how big the impact will be. Small movements have exploded once given a niche to fill... and then die once it was swallowed up by a new contender.

    If the benefit of C# is only whats in this article, then I'm not convinced its going to change the world. I'll keep to my "unsafe" code blocks and maintain interoperability with non-Gatesian worlds.

    I'll wait for at least a committee for standardization to form for this mess.

  6. C# is really kinda cool stuff by CDWert · · Score: 2, Insightful

    Language wars abound, and I have no interest in propogating another.But truth is Java has become bloated far beyond its original design as a tv box controller. The best comparison I heard was Java was C without the corners, just like basic is fortran without the corners. C# seems more to me like the best of Java and C++ without many of the sharpest corners. I work in a split development world 1/2 *nix and 1/2 Win32 , none of us slashdotter want to acknowlege it but most of the desktop world is on windows, so to write a Win32 app your most viable options have been C, VB or some other monstrosity on a Win32 box like Java, have you ever tried to run a half a million line Desktop Java app on windows. Or to throw a Java app together in a nice pretty IDIOT proof installer so that the person who thinks a CDROM is a coffe cup holder can install it with one of the nice pretty MS installers, Java in those aspects , well...it sucks
    ....
    Of all the MSVC programmers I worked with once they all had a good chance to work with C# they said theyll never write another line of C++ again. For the windows platform it may indeed be great stuff, the one thing that piques my interest is its cross plattform future. MS included help files and other pices parts refrence Linux, no whether its MS or someone like Ximian with their mono project. The C# stuff is definatley cool. native speed and you can writer in any of the dot net languages you want VB C# and yes TCL and PERL have ports to the Dot NET runtimes, heres the deal even M$ says it, from a performance standpoint on a Win32 machine they will all run the same the language choice will be a matter of style.

    Some slashdotters out ther perpetually bash MS and I do too from time to time, I run Linux at work and home, but the fact is Im in computers to make money PERIOD, If I could make a living out of racing my motorcycles full time Id never touch a computer again other than to surf for parts or events.

    To the ends of making money at computers, C# will do great I am sure , the coders I know that have actually worked with it on a daily basis love it, and to all the NAYSAYERS out there that say "Oh just another MS product to have bugs" sure probably but the wholde of the VS 7 IDE and tools are written in C# , Im sure by the time its released it'll be pretty good. And best of all it will make ME MONEY, I write desktop apps , if its quicker and easier.more interoperable, which it is it has full inheretence.Im all for it. The fact that 3rd parties are already vigilantly porting the runtime to *nix systems tells you its not another Bob

    MS languages for the most part run superbly on MS systems, they suppert both sides of the enviroment. Guess what C# is another example, in XP there are already kernel optimization routines for the DotNET stuff,

    If you HAD to program and app for a MS system in a MS language, which would you preffer, C++, VB, VFP, well..... Or C# that even C++ programmers who use it on a regular basis say , (and from experience it does) rocks as far as MS languages go.

    --
    Sig went tro...aahemmm.....fishing........
  7. Ouch! by pi+radians · · Score: 3, Insightful

    Hey, I take offence to that!

    I've been forced to write sites in ASP/SQLServer on a number occasions because thats what the client asks for (they figure if its all IIS and VBScript it'll run better, I know, dumb). So before you decide to look down upon someone using C# or VB or anything else, realize that there are a number of factors that go into what technology is used.

    (I wish I could say my morals could standup to such a request, but low and behold, I want money too.)

    Seriously, why do you expect someone to only code in a certain language? I feel that the more you know, the better a job can get done. Just because its a MS language doesn't mean that it is useless. You should do what's best for the client.

    --

    sin(6cos(r)+5A)
  8. C# doesn't make any sense... by burtonator · · Score: 1, Insightful

    I don't know why anyone would be excited about C# unless they were also excited about Windows (I don't have to explain to anyone here why windows isn't too exciting).

    C# basically is a clone (some would say rip-off) of Java with none of the benefits.

    The Java world is actually doing very well now. We have a lot of solid Open Source projects (Jakarta, Tomcat). The standards that do exist are very robust (Servlet, standard API, etc) and there is a lot of brainshare here.

    There are tons of JVMs available. Can I run C# on Linux? FreeBSD? Solaris?. And if so can I port this code to another alternative non-MS platform? Linux and FreeBSD have had modern JVMs for a while now.

    We are also making significant progress on Java integration with GNU/Linux (AKA not the proprietary SUN Java VM but a Free Software VM meeting the same spec level).

    GCC 3.x will include support for 1.2 class JVMs (except for AWT but we are working on this). This means that all newer modern GNU/Linux machines will be able to execute Java code.

    I liken this to the proprietary SSH vs OpenSSH relationship. There is the proprietary Java VM from SUN which can be used on Windows, Solaris, etc. The Free Software community now has GCC (with GCJ), Jikes RVM, Manta (all OSS VMs), that they can use and still remain free (all of these examples are under the GPL)

    No thank you. I will stick with Java.

    Kevin

  9. Power of Java, Functionality of Windows by ClubStew · · Score: 5, Insightful

    I admit that Microsoft is once again trying to dup Java, but, if you like Java and wish to work with platform-dependant API's that do more with Windows than Java, C# is your answer!

    As the article mentions, C# has almost the exact same syntax and keywords that Java has (plus PERL's foreach operator...kudos). There is almost no learning curve. You can leverage the functionality of Windows with C# however, and it has great XML support; so, if you've worked with the MSXML parser, you'll have no problems working with XML in C#.

    C# deserves a little more credit than many give, at least if you're working in a strict Windows environment. It's worth a look.

    That's all I have to say, but I'll pile on the on wood for the flames that will arise!

  10. Re:Why do I get the sinking feeling by spongman · · Score: 3, Insightful
    since the C# language has been submitted to the ECMA group it's likely that implementations will appear for non-Microsoft platforms.

    in fact, one such port seems to be coming along very nicely.

  11. Big companies... by Eusebo · · Score: 4, Insightful
    I work for a rather large international bank and I can say we've been moving away from Microsoft as fast as you can say "dot net". From what I've seen this is true of many of the other firms in the financial sector as well. I suspect a large part of the reasoning is not the superiority of Java, but rather is the "anything but Microsoft" syndrome in effect. I seriously doubt that C# will be considered here as a replacement for Java any time soon.

    I have a feeling that C# will be adopted by Microsoft's technology partners, but why would any firm that has spent time and money moving away from Microsoft products go running back because of a new product offering? Its not the products we're trying to get rid of, its the company.

    --
    It is quite simple
    Haiku should not be funny
    Try a Senryu
  12. I'm impressed by C# -- the language by GCP · · Score: 5, Insightful

    I've been a fan of Java since it was still in alpha, in early '95. I even wrote a piece of the Swing API. I'm still a Java fan (and developer), but sadly not for GUI apps. MS ("we own the client") and Sun ("we're not going to let this become just a better way to write Windows apps") collaborated to kill Java as a viable way to produce commercial-grade consumer GUI apps.

    We need a modern, productive system for producing new high-performance GUI apps: apps that look and feel as if they'd been written in C++ -- without the crashes and slow dev cycle. I'd give up some of the flexibility of C++ (you can write drivers, create an OS, build a browser, it's a dessert topping AND a floor wax) for something truly optimized for what matters most in creating superb GUI apps quickly and well.

    I've had high hopes for Eiffel and some others to evolve into the successor to C++ for GUI apps, but it never happens. The inertia of programming languages is immense.

    The next to step up to bat is C#. I like the language a lot and think it lends itself to great dev systems. I'm suspicious of the bytecode aspect, though. ("Faster than compiled!", "It actually is compiled!", etc. Yeah, so why isn't Solaris written in Java?) I'm afraid that aspect will still require that "serious" apps be written in C/C++.

    I like even less that it may remain Windows-only. If it does remain Windows only (for all practical purposes), I suspect the blame will belong just as much to MS haters dismissing it primarily out of bigotry as to MS for optimizing it for their own platforms.

    I'd like to see the open source community look at it with the same eyes as if it had come out of some smelly hacker's basement.

    --
    "Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
  13. Multiplatform increasing in importance by GunFodder · · Score: 4, Insightful

    It sounds like C# has some nice features that Java doesn't, but I have my doubts that Microsoft will make it multiplatform. And that is becoming more important as the range of computing devices widens.

    Servers tend to run Unix or legacy OSes. Embedded devices run Palm OS or a free Unix like Linux or BSD. Phones run all kinds of custom software. The only platform that Windows rules is the desktop, and that market segment just shrunk for the first time in history. How can C# dominate if it only runs on one type of device?

  14. my $0.02 by vscjoe · · Score: 5, Insightful
    I think from the level of people who make decisions about what programming languages to use on commercial projects (this includes me), the technical distinctions between Java and C# are of little concern: the languages are so similar that they are basically interchangeable. What matters is who supports it, what libraries are available, how mature are the implementations, whether it's a single-vendor or mult-vendor solution, how well it integrates with the platform, and how many programmers are available.

    For pure Windows programmers, C# wins there and will probably be picked up by lots of VB and VisualC++ programmers. But people who live in that world are already not using Java. For everybody else, Java seems to win hands down. I think C# will neither be a complete failure nor will it do much harm to Java.

  15. Re:Some more information by jeffy124 · · Score: 2, Insightful

    Declaration:

    public class Direction {
    public final static int NORTH = 1;
    public final static int EAST = 2;
    public final static int WEST = 3;
    public final static int SOUTH = 4;
    }

    Usage:

    int wall = Direction.NORTH;

    The java method will compile/run a tad faster, due to the lack of an entirely new type.


    That's because javac will translate the Direction.NORTH into a static constant 1 during compilation. The only problem that causes is it means you have to recompile everything that uses Direction's constants if the enumeration changes.

    I dont know how C# handles it's enum construct - I've never used it (C# that is).

    --
    The One Rule Of Chess You'll Ever Need: Don't play someone who carries a kit in their bookbag.
  16. Re:Non Portable by brsett · · Score: 2, Insightful

    I guess by inference you are saying that Java then is portable, which is a statement my experience directly contradicts. I have no axe to grind with Sun, and I have no real problems with Java, but I haven't experienced the cross platform nirvana it purports. Certainly the threading characteristics for PCs, Sparcs, and Macs are not very similar, especially when you use native threads (enabled by the jvm options). And the awt implementations are not portable, nor are all the applet apis (though in all fairness those could be bugs that I've seen). But much more damning then any of that, is the object reclamations system, garbage collection works completely different depending on the platform, which while not neccesarily a portablility killer, definitely impacts system tuning.

    And of course all the third party database bridges are native apps (at least if they go fast), so you are intrinsically dependent on a chunk of code that doesn' claim, or even want to be portable if you are doing any enterprise development.

    Again, I have no real problems with java, but to me it is still "Write once, Test anywhere", and I'm not sure if there is any move to make the JVMs more similar (or even if that is a good idea). But what do I know, I'm just a crazy C++ hack :-).

  17. Re:It doesn't matter how good it is by brsett · · Score: 2, Insightful

    Yes, but don't standards usually try to codufy existing practice and divergent implementations. WHats the point of standardising something that is intrinsically standardized -- because there is a single reference implementation. I have no problem with MS (other than their crappy API's and hungarian notation), but it seems that they are using standardization as a marketing ploy (of course they are a much better marketing company than a technical company, but I digress), it serves no real purpose. But ANSI doesn't cost me any money, so let the corporate boys fund it, good for me.

    (I would also like to point out that MS is notorious for ignoring ANSI standards *cough* C++ *cough*, so what an interesting point that they finally "seen the light" -- but let's give them the benefit of the doubt).

  18. Re:Why do I get the sinking feeling by vanza · · Score: 4, Insightful

    But will they be standardizing the libraries or just the language (and the CLR for that matter)?

    The beauty of Java is that you write your code once to a set of libraries that are available on a lot of platforms. Even if you had to recompile the code on each platform, there would be no problems because there's a standard library to which you code.

    But, if only C# the language is sent to the ECMA, won't we have another C/C++/ with different features? The code you write will still be specific to the libraries you choose to use (and thus the platforms those libraries are available).

    --
    Marcelo Vanzin
  19. So how exactly... by Anonymous+Brave+Guy · · Score: 3, Insightful

    ...do you use a language that won't even properly exist until February next year, when Visual Studio.NET will actually be released?

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  20. Re:Why do I get the sinking feeling by spongman · · Score: 3, Insightful
    i believe that the language and core runtime features are being standardized. as for the rest of it (ASP.NET, ADO.NET, WinForms/GDI+, XML/WebServices, etc...) even though they may not be an open standard as such, Microsoft's implementation and specification will serve as standard enough for others to provide compatible implementations on other platforms (eg: Mono), in exactly the same way as has happened for Java.

    Microsoft has historically been pretty good at keeping their SDKs backwardly compatible and I don't see any reason why they would break the compatibility of future .NET runtimes (the non-ECMA bits). Some would say that they'd do that just to break the 3rd party implementations, but in reality they'd lose more by pissing off their own developers than they'd gain.

  21. Re:Would you trust a Microsoft apologist? by ergo98 · · Score: 2, Insightful

    Actually I'm hardly an MS advocate. For one I think they have a ridiculously lax attitude towards security (how many times do buffer overflows have to occur before someone says "Uh, maybe we should audit the IIS code where non-trivial stack variables are used....". I also am actually pushing at my company AGAINST a .NET initiative, or rather for at least seriously evaluating J2EE as a primary competitor.

    Having said that regardless of my approach for them, I'm not a zealot. That means that I'm not an AC wanker running around trying to expose MS employees because someone says something good about MS (and regardless of your religious zealot opinion a lot of things MS does and has done ARE quite impressive).

    BTW: I suspect you're just a Sun employee anyways.

  22. Laundry list of corrections by coonsta · · Score: 4, Insightful

    I think this is a bit Java biased, in that it uses some very precise wording and fails to mention a lot of relevant features of C# until the appendix-like section D. And it contains some outright mistakes.

    My corrections:

    A.2: Java doesn't have an "unsafe" keyword; C# and Java have a "volatile" keyword that is strangely missing. And don't you think it's strange that he doesn't equate C#'s "extern" with Java's "native"? They're approximately the same.

    A.5: Neglects to mention here that C# has square *and* jagged arrays, it is stuck in section D.

    A.10: The phrase "both languages have an inheritance hierarchy where all exceptions are derived from a single Exception class" is a tautology, because "all exceptions" *are* exceptions because they extend Exception! Whereas if he meant to say "all objects that can be thrown are instances of types derived from a single Exception class" he would be wrong, because in Java these all derive from java.lang.Throwable.

    The sentence two sentences after that one, starting "Finally, both languages..." does not make sense.

    B.8: The last statement in this paragraph is incorrect. Isn't it possibly in Java to simply write ArrayList.class, if java.util.ArrayList has been imported? Likewise in C#, where if System.Collections has not been using'ed it is necessary to write typeof(System.Collections.ArrayList).

    C.1: This really should mention delegates here. It was inner classes v. delegates that heated up the Sun vs. J++ debate. Thus C# doesn't suffer a "lack" of inner classes, rather it suffers an ideological difference with Java, don't you think? And likewise, Java doesn't suffer a "lack" of delegates.

    C.3: The criticism that, for example, it is possible to overload "", and this makes overloading bad, and C# has overloading, hence C# is bad-- is nonsense! In C# it is illegal to overload, for example "", or "==" but not "!=".

    It also says "()" (I assume meaning cast) and "[]" can not be overloaded. This is again very precise and misleading language. They can not be overloaded, because custom conversions and indexers can be used instead!

    It also fails to mention that "&&", etc. will call "&". The blanket statement that "&&", "||", etc. "can not be overloaded" is very misleading.

    C.4: You can "fall through" in C#, with goto. Except unlike Java, in C# it is explicit (and more flexible).

    Fails to mention Java's limited range of "switch" statements, whereas e.g. C# can switch on a ulong.

    C.5: Seems to miss the distinction between *assemblies* and *modules*.

    C.6: Some of these criticisms are unfair, e.g. that Java has thread-safe collections. In C#, a reference to a synchronized wrapper can be kept and the un-thread safe reference be let go out of scope!

    Not mentioning boxing and unboxing here is a failure: one of the chief gripes with Java's collections is that it is necessary to wrap the primitive types in their class equivalents.

    C.7: Java has a labeled goto of sorts-- break and continue. Thus some of the criticisms of the weakness of languages with goto may also be applied to Java.

    C.8: Is this section intended to confuse? The fact that marking a method final in Java means that subclasses cannot contain a method with a similar signature is a *coincidence* arising from the fact that (a) final means methods can not be overridden and (b) Java does not have new/reintroduce semantics and relies instead of the name and parameters. Thus C#'s final achieves exactly the same as Java's in terms of dynamic linking and dispatch-- that a particular method can not be overridden.

    D.3: Should probably mention that .NET has an attribute for marking enumerations as able to be used in bitwise combination, whereas this is always possible (whether correct or not) in a Java pseudo-enumeration with int members. On the other hand, the "workaround" in Java makes this impossible-- you can't "or" objects.

    Well, that's my $0.02. Apart from those glaring problems, the discussion is not bad.

  23. C# may be very good for Java by bigbird · · Score: 2, Insightful
    1. It may force Sun to be more proactive on Java features such as parametrised types. Competition is good.

    2. Many VB and C++ developers will move to C#. They will then be in an ideal position to transition to Java with little effort if they have a requirement for cross-platform apps.

  24. while this seems to have by rutledjw · · Score: 2, Insightful

    dissolved into a flame war, I think that the ending evaluation is that C# will be doomed to 2nd or 3rd place unless they can address multi-platform use. If that happens, well then the gloves are OFF.

    MS needs to hurry however, as Java continues to gain in acceptance (regardless of it's problems) in more mainstream sw arenas (Oracle, IBM). Let's not forget that technical superiority alone does NOT a successful product make. There are plenty of SmallTalk coders who think Java should have gone STRAIGHT to the junk heap.

    I, like many others, do not particularly care for MS. I feel they provide low-quality product and user clever marketing combined with arm-twisting to maintain market dominance in the areas they control.

    That said, as a Java programmer I'd really like to see some competition with Java. Who knows, Sun just may open in up to ensure that MS can't get a foothold!

    --

    Computer Science is Applied Philosophy