LINQ is one of Microsoft’s .NET Framework’s most distinct language features. When it was first introduced to languages such as C#, it required heavy changes to the language specification. Yet, this addition was extremely powerful and probably unequalled by other languages / platforms, such as Java, Scala, etc. Granted, Scala has integrated XML in a similar fashion into its language from the beginning, but that is hardly the same accomplishment. Nowadays, Typesafe developers are developing SLICK - Scala Language Integrated Connection Kit, which has similar ambitions, although the effort spent on it is hardly comparable: one “official” Scala developer against a big Microsoft team. Let alone the potential of getting into patent wars with Microsoft, should SLICK ever become popular.
What does Java have to offer?
Currently, I guess that QueryDSL would come closest to LINQ in the Java world. As can be seen here, it offers querying many backends using a single querying API. See a previous blog post about a comparison between QueryDSL and jOOQ. There are many other attempts of bringing LINQ-like API’s to the Java world, as the following Stack Overflow question shows:
http://stackoverflow.com/questions/1217228/what-is-the-java-equivalent-for-linq
Here’s another newcomer project by Julian Hyde, that I’ve recently discovered:
https://github.com/julianhyde/linq4j
He tried his luck on the lambda-dev mailing list, without any response so far. We’re all eagerly awaiting Java 8 and project lambda with its lambda expressions and extension methods. But when will we be able to catch up with Microsoft’s LINQ? After all, jOOQ, QueryDSL, linq4j are all “internal domain specific languages”, which are all limited by the expressivity of their host language (see my previous blog post about building domain specific languages in Java).
Java 9 maybe? We can only hope!



August 3rd, 2012 at 13:36
you can use Clojure, Scala or Groovy if you need syntactic sugar. Ex. DSLs, Linq style queries can do with Scala, Closures (Java8 Will have it) and all the goodies. So you can do the brute force in Java and the elegant stuff in those languages that integrate very well with Java and the JVM.
August 3rd, 2012 at 21:08
I guess, I could. Then again, why would it be so simple for languages like the ones you mentioned, while it’s so hard for Java to advance?
August 6th, 2012 at 09:24
Even though that was probably a rhethorical question: Java’s stability is only matched by COBOL’s. And that’s one of the main reasons why Java is so successful in enterprise environments, where applications tend to get very old.
This leads to (at least) two constraints for the development of the Java language: If it can be done as a library instead of a language enhancement, don’t add it to the language.
Second, if it needs to be done in the language, try to get it right with the first try. This in itself is already a daunting task, made even more difficult, because language features like to come in bundles (e.g. generics and co-variants). Obviously this needs a lot of time and a lot of thinking.
Being an enterprise developer myself, I am very happy with this conservative and careful way of adding new features to the language.
August 6th, 2012 at 09:30
Yes, given the history of Java’s being reluctant to adding new language features, this was indeed a rhethorical question. Yet, as the upcoming changes in Java 8 proove (lambda expressions, extension methods), these things are not impossible even in conservative environments. You mentioned generics and co-variants, which were quite a bit of a change to the language as well.
August 9th, 2012 at 09:32
[...] stands for Scala Language-Integrated Connection Kit, which is more or less the Scala equivalent for LINQ-to-SQL. Note that I say LINQ-to-SQL, not LINQ in general, as Scala already has sufficient means of [...]
September 12th, 2012 at 06:50
There is no such feature in java. By using the other API you will get this feature.
Like suppose we have a animal Object containing name and id. We have list object having animal objects. Now if we want to get the all the animal name which contains ‘o’ from list object. we can write the following query
from(animals).where("getName", contains("o")).all();Above Query statement will list of the animals which contains ‘o’ alphabet in their name.
More information please go through following blog.
http://javaworldwide.blogspot.in/2012/09/linq-in-java.html
September 12th, 2012 at 07:24
You might be interested by LambdaJ:
http://code.google.com/p/lambdaj/
They have solved this using Proxy objects, making method calls such as “getName()” compile-time safe. Another library that looks just like yours is Coollection:
https://github.com/wagnerandrade/coollection
March 22nd, 2013 at 10:22
[...] See also my previous blog post on the subject [...]