Database Reference
In-Depth Information
System.out.println("Total purchases: " + numPurchases);
System.out.println("Unique users: " + uniqueUsers);
System.out.println("Total revenue: " + totalRevenue);
System.out.println(String.format("Most popular
product:%s with %d purchases", mostPopular, purchases));
}
}
As can be seen, the general structure is similar to the Scala version, apart from the extra
boilerplate code to declare variables and functions via anonymous inner classes. It is a
good exercise to work through both examples and compare the same lines of Scala code to
those in Java to understand how the same result is achieved in each language.
This program can be run with the following command executed from the project's base
directory:
>mvn exec:java -Dexec.mainClass="JavaApp"
You will see output that looks very similar to the Scala version, with the results of the
computation identical:
...
14/01/30 17:02:43 INFO spark.SparkContext: Job finished:
collect at JavaApp.java:46, took 0.039167 s
Total purchases: 5
Unique users: 4
Total revenue: 39.91
Most popular product: iPhone Cover with 2 purchases
Search WWH ::




Custom Search