The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

mgambini (2) [Avatar] Offline
#1
Hi,

I'm reading this interesting MEAP. But I got a little surprised about this sentence on page 3 (1.1.1 - Java's missing modularity), which could be a little questionable: "Every class inside the JAR is externally accessible, no matter how internal its intended use".
I think it should be more correct saying that if you don't want to expose non-public APIs you must impair your application's logical structure by lumping unrelated classes in to the same package (which of course could be splitted among different JARs). Or you just intended that by reflection you can change visibility scope of your code?

Best regards,
Marco
holly.cummins (16) [Avatar] Offline
#2
Re: Errata on JAR encapsulation
Hi Marco,

Thanks for the interesting question. You're right that classes can be declared package-private, and only accessed from within the same package, and inner classes can also be declared fully private, and only accessed from within the parent class. So there are ways to restrict the visibility of classes, as you suggest.

What section 1.1.1 is trying to say is that jars themselves don't provide any protection to classes. So classes provide a way of grouping and also a way of encapsulating, and then packages provide a way of grouping and also a way of encapsulating, but then when you get to jars you get the grouping but not the encapsulation. Any encapsulation, even of classes, would have to rely on the lower-granularity mechanisms provided by packages or classes. I suppose a more correct sentence would be "Every class inside the JAR which isn't protected by its class or package is externally accessible, no matter how internal its intended use", but I think then the sentence becomes a bit long!
mgambini (2) [Avatar] Offline
#3
Re: Errata on JAR encapsulation
Hi Holly,

I agree with you about the point: JAR provides the grouping but not the encapsulation feature. But that sentence seems to me an oversimplification, technically not right. A part from that, I appreciated the book contents.

Marco