The standard types of scoping provided by Java -- public, packaged, protected, and private -- are usually all you need. Occasionally, however, standard scoping is insufficient. While C++ permits you to establish a friend relationship between a class and other classes or functions (see the Sidebar, "What is C++ friendship?"), Java does not provide this capability. Mark Roulo presents an approach for building very specific relationships between a class and other functions, classes, and packages in Java. Using this approach, you can grant access to a class's methods with fine-grained control. (1,500 words)
Java Reflection provides a lot of information about a given class at runtime; you can easily know all its super classes, implemented interfaces, methods, constructors, fields, and so on. But in some cases, you may want to know all the classes implementing a given interface, or subclassing a given class. This tip, based on lessons learned from Java Tip 105, shows you how to retrieve all the classes from a package inheriting or implementing a given class or interface. (1,200 words)
Top-level nested classes (static inner classes) act like top-level classes except they use the enclosing class as a namespace. This tip suggests designing supporting classes as top-level nested classes inside the primary class. This approach makes the coupling between the primary and the supporting classes clear and leads to an implementation that is easier to understand, use, and maintain. (1,100 words)