Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How can I display the possible commands for an imported Java package?

For example, when import javax.swing.*, is there any way to display what all is imported here? Ideally I'd like to do it within the code, using a simple System.out.println() to display all the functions that are imported with the *. Thanks in advance.

1 Answer

Relevance
  • Anonymous
    1 decade ago
    Favorite Answer

    You can't do this with code.

    Packages do not exist in Java when the code is executed. Packages are a mechanism for programmers to structure their programs and organise them logically but when the Java Virtual Machine loads a Java program it does not separate out the classes into packages in the same way.

    There are some very complicated long winded attempts out there at providing this functionality but it requires restructuring your design and causing considerable impact on your program so it isn't advised, Java just isn't designed to provide this information, it's more hassle than its worth. The Java API documentation [1] lists all the classes and methods that are available in the standard java packages.

Still have questions? Get your answers by asking now.