SPARK-3926 [CORE] Result of JavaRDD.collectAsMap() is not Serializable

Make JavaPairRDD.collectAsMap result Serializable since Java Maps generally are
Also, `private[java]` methods here will become public from Java's POV.  We can't use Scala package-private access modifiers when implementing Java API classes.