Home Thought Leadership Our Tech Blog CSharp / Java comparison

Our Tech Blog

CSharp / Java comparison

All,

Here is a link to the most complete document I have yet to find on how Java and CSharp compare syntactically.

CSharp Java comparison

However, like all such documents, there are some errors. These are:

  • The ‘IDisposable’ implementation is flawed.
    • The the StreamWriter is not Disposed.
      Calling ‘close’ on it isn’t enough and will leave the underlying FileStream Windows Kernal objects hanging.
    • GC.SuppressFinalize(this) is improperly placed.
      This should be the first method called in the IDisposable.Dispose() method, as this will unhook the current object from the GC finalization queue, which may be important if the application is multithreaded and/or is a GC generational collection is executed during the run time of the objects disposal.
    • lock(this) is unneeded
      Placing a Monitor lock against the Dispose is an unneeded performance hit.  The CLR treats disposal in a special manner.  Is this instance Checking the ‘disposed’ field and then setting to true ASAP would suffice.  Also, allowing a working thread to dispose a disposable class when their could be other working threads that require access to the object is a bad .NET programming practice.
  • Mono Project
    • Mono is actually fully ’sponsored’ and supported by Novell.  Although in truth, Mono and Ximian are majority owned by Novell.
  • Extensions (this is a partial error in the document)
    • Simply create your classes within the namespace you wish to extend.  However this is not a global thing as with the Java features. This was an intentional design decision by the CLR team

Related posts

3 Comments

  1. Posted October 15, 2008 at 2:55 pm | Permalink

    Looks like a good C# 2.0 to Java 1.4 comparison. There’s clearly some stuff that’s out of date in terms of C# features not available in Java. And there probably should be a dedicated section for features in Java that aren’t in C#. But a very good overview.

    That being said, it’s the C# 3.0 stuff that I find most exciting about C#. A lot of the C# 3.0 features mirror things that are going on in the Groovy language (built on top of Java). Things like lambdas, extension methods, automatic properties, object initializers, collection initializers, anonymous types, etc. While these features still don’t offer the full power of LISP macros (by exposing the full AST directly to the programming language for dynamic alteration), they do offer a lot of that capability along with the benefit of having a much cleaner syntax than LISP. Both LINQ and Grails are tremendous examples of this (though it seems that LINQ also has some language level support, unlike things in Grails that were done entirely on top of the Groovy language).

    So let me ask this. In the .NET landscape, are most companies using C# 3.0 (which I guess means .NET 3.5) already or is there some resistance to upgrading? The answer is probably “it depends”, but some insight on when people might upgrade up would be useful.

  2. Posted October 15, 2008 at 2:58 pm | Permalink

    “… And there probably should be a dedicated section for features in Java that aren’t in C…”

    See: Wishlist

    The idea behind C# 3.0 is to merge the language into the functional language paradigm (e.g. OCaml, Haskell etc). As I haven’t ever used or encountered LISP, I can’t really comment on it. Also, C# was always intended to have the features that appeared in C# 3.0, which now also appear in Groovy - however they are by no means new idea’s, so the feature comparison is a good one (although C# isn’t a dynamic langauge!)

    Also, another thing with C# 3… please do not confuse Linq with Grails. Linq is a functional technology to allow the the developer to leverage method chain type collection querying. The SQL-like syntax (which is sugar) is a way to reduce confusion and complexity and give developers a more SQL-like feel to collection querying. DLinq or Linq-To-SQL is a technology that leverages the Linq AST/expression-tree functionality to query a database using Linq. Linq-To-SQL is a confusing title and should really be ‘Query a DB using the SQL like Syntactic sugar of C# that in-turn gets converted to Method Chains for the actual work using parts of ADO.NET’… but I don’t think that would have been a good product name .

    So:

    List eg = new List();
    eg.Add(”Energy”);
    eg.Add(”Duck”);
    eg.Add(”Aardvark”);
    eg.Add(”Beach”);
    eg.Add(”Cherry”);

    // This: (Syntax Sugar)
    List rs1 = (from t in eg
    where t.Contains(’e')
    orderby t descending
    select t).ToList();

    // Compiles to: (Method Chain)
    List rs2 = (eg.Where(t => t.Contains(’e')).OrderByDescending(t => t)).ToList();


    As to uptake of C# 3.0 and .NET 3.5. If you develop with C#, the transition isn’t so hard as you can target different framework versions (2.0, 3.0 and 3.5). However, with VB.NET you don’t have that freedom - it’s all or nothing. In my oppinion though, because .NET 3.5 is simply .NET 2.0 with a few extra DLL’s I really don’t see why people don’t just upgrade… Backwards compatability issues? which ones? there are none -> unless you count the new DLL’s.

  3. Posted May 7, 2009 at 3:40 pm | Permalink

    For clarification, Grails is an open source web application framework that allows developers to write code in either Groovy or Java. It’s completely different from LINQ, and is the most promising web framework I’ve stumbled upon to date.

Post a Comment

Your email is never shared. Required fields are marked *

*
*