Though there is nothing wrong with the code but maybe something wrong in the way you have tried to execute. Follow these steps:
Step 1:
Start spark daemons .
Step 2:
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
Step 3:
Now have look at the result when you run the code.