I wrote this example piece of java code for running sparse linear regression after providing a much shorter Scala version in a Spark forum answer - link broken (new link). The OP asked if I could provide the same code in Java to which I thought "nope I'm too busy to do that". Then I wondered how much effort, and how many lines of code, it would actually take. The answer is ... a lot!