No, this is not possible in a totally reliable way; however, it may be practical to implement in many cases.
Due to the flexibility of Java class loaders, the classes defined under a particular package may not be known at runtime (e.g. consider a special classloader which defines classes on-the-fly, perhaps by loading them from the network, or compiling them ad-hoc). As such, there is no standard Java API which allows you to list the classes in a package.
Practically speaking, however, you could do some tricks by searching the classpath for all class and JAR files, building a collection of fully-qualified class names, and searching them as desired. This strategy would work fine if you are sure that no active classloader will behave as described in the previous paragraph. For example (Java pseudocode):
Map<String, Set<String>> classesInPackage = new HashMap();
for (String entry : eachClasspathEntry()) {
if (isClassFile(entry)) {
String packageName = getPackageName(entry);
if (!classesInPackage.containsKey(packageName)) {
classesInPackage.put(packageName, new HashSet<String>());
}
classesInPackage.get(packageName).add(getClassName(entry));
} else if (isJarOrZipFile(entry)) {
// Do the same for each JAR/ZIP file entry...
}
}
classesInPackage.get("com.foo.bar"); // => Set<String> of each class...