Alex Miller lives in St. Louis. He writes code for a living and currently work for Terracotta Tech on the Terracotta open-source Java clustering product. Prior to Terracotta he worked at BEA Systems and was Chief Architect at MetaMatrix. His main language for the last decade has been Java, although Alex have been paid to program in several languages over the years (C++, Python, Pascal, etc). Alex has posted 43 posts at DZone. You can read more from them at their website. View Full User Profile

Is LINQ leaving Java in the dust?

  • submit to reddit

Interesting story today asking whether LINQ has given .NET an edge over Java. LINQ is best-known as a way to embed SQL-like statements directly in code. However, it's really a much deeper technology that allows you effectively build DSL-like constructs in libraries that work as if they are part of the language. And that is undeniably powerful.

From what I've seen, the C# code using LINQ also seems to be relatively readable (due to the DSL-like nature of it) and that is a big win from both the power and complexity standpoints.

So, then we have the question of Java, which does not (currently) have the ability to weave structures into the language as elegantly as LINQ. I think the closures work could make that possible in Java 7, but we're talking probably 2010 before Java 7 is in common use.

From a language feature perspective, C# and LINQ are evolving faster and adding more important features than Java.

We have to take a step back though and consider some other things. C#/.NET are not driven by standards or a loose coalition of competing/cooperative companies; they're driven solely by Microsoft. And Microsoft is happy to break backwards compatibility and force platform upgrades as the sole provider of the technology. Things are a bit more bohemian in the Java world and the JCP may be the tortoise to Microsoft's hare in this regard.

But I wouldn't count Java out.

The addition of annotations, static imports, and generics (even crippled generics) has opened some interesting opportunities and I think we've only recently started to see people target and push those features to their fullest. I suppose the poster-child for this in the context of LINQ must be Quaere, which aims to do much the same as LINQ by building an internal DSL. Guice is another good example of pushing these features to their limit.

You might also point to the possibility of dropping into Groovy and using builders or other DSL-friendly tools there. Or moving slightly farther afield, use JRuby or Scala to develop the data access parts where you need more flexibility.

Between a quickly-evolving .NET with a limited community vs a more slowly-evolving Java with a rich community, gimme the Java world any day.

But, I'd like to hear what you think. Are C#/.NET innovations changing your mind? Are they just a call for improvement in the Java world? What can we learn from each other?

Published at DZone with permission of its author, Alex Miller.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Honey Monster replied on Sun, 2008/02/10 - 11:23pm in response to: Anonymous Coward

FYI, LINQ does handle groupings and even complex query building naturally. There is both a SQL-like syntax and a methods-based syntax. The first is actually just a shorthand for the latter:

var q = from c in db.Customers where c.City=="London" group c by c.ZipCode

is equivalent to

var q = db.Customers.Where(c => c.City=="London").GroupBy(c => c.ZipCode)

Both will return a list of "groups" each with a Key property holding the zipcode. The individual customers for each zipcode can be accessed by enumerating over the group (it's an enumeration of "Customers"). I don't see any complex workarounds. Also (when performed against the database) it will retrieve all of the customers from London at once (building a query with a where clause) and perform the grouping on this set. Can you explain how this could possibly perform better?

You also misunderstand type inference. C# is still very much a statically typed language. When the compiler encounters var s = "Hello World"; it simply infers that the type of s is string just as if you had written string s = "hello World";


George Jiang replied on Wed, 2008/11/05 - 7:25pm in response to: Casper Bang

Java 7 in common use in 2010?

 We just got on Java 5 this year, which was released in 2004.

 When will Java 7 be released???

Timo Westkämper replied on Mon, 2010/01/11 - 2:34pm

Here is another LINQ for Java option : Querydsl

 Querydsl supports JPA/Hibernate, JDO, SQL and Java Collections.

Henk De Boer replied on Mon, 2010/01/11 - 3:16pm in response to: George Jiang

When will Java 7 be released???

It's planned near the end of 2010, but a release somewhere in h1 2011 is maybe more realistic judging from the immense amount of work that still needs to be done.

Yogesh Kumawat replied on Thu, 2014/04/10 - 1:41am

 We have to cheat a phase abet nonetheless besides judge few else objects. C#/.CHIC are hardly driven by norms or a lax faction of competing/helpful companies; they're driven exclusively by Microsoft.   Mens Knitwear

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.