Though there is nothing wrong with the code but maybe something wrong in the way you have tried to execute. Follow these steps:
Start spark daemons .
Now create a java project and copy the same code again.
After this right click on project-->buildpath-->configure buildpath-->external library-->external jars
Choose all the jars from /usr/lib/spark/jars folder and Apply
Now have look at the result when you run the code.