In java, you hard-code batchSize(5) while in JS you do a limit() so it is still not the same logic. You potentially return a lot more documents in the Java version. A batchSize(5) is really bad if you a lot of documents because it involves overhead at every 5 documents returned. A higher batchSize() is better. The best is to not change it.
Before redoing the test make, modify the code to print the size of the result set. Also print the first and last document to make sure we get the same result.