How to Import Classes in Java


The class is the unit used to build all applications in the Java programming language. Different classes, or sets of classes, are generally stored on separate computer files. That allows for more modular program structures -- with the consequent benefits of maintainability and reusability -- and for the use of class libraries across many applications. A Java program can use classes defined in other files by "importing" them into its context.

  • Identify the name of the package that contains the Java class(es) you need. Java packages are similar to libraries in other programming languages. A good resource for finding which package contains a given class in the standard Java Platform is Oracle's "API Specification" Web document (see Resources).

  • Import one class at a time by including a fully-specified "import" statement at the beginning of your Java program. For example, "import;" imports only the InetAddress class.

  • Import a family of related classes by including a single wildcard "import" statement at the beginning of your code. For example, "import*;" imports all classes that share the "" prefix, such as InetAddress, Proxy and URL.

Related Searches


Promoted By Zergnet



Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!