Java: Package statement and import statement

Source: Internet
Author: User

One, the package statement:

 1, storage directory for class with package name     If a class has a package name, it cannot be stored arbitrarily, or the virtual machine cannot load such a class.     Program If the package name is used: Package Tom.kepler; (packet name is the path to the Java file). Then the directory where the files are stored is: ... \tom\kepler; and compiled bytecode files are also in this directory (in fact, as in other cases, If the. java file is compiled with the command line, the. class file is generated in the folder where the. Java is located, and if compiled with the eclipse compiler. java files under the SRC folder,. class files under the Bin folder).  2, running the main class of the package name     As mentioned above, the directory where the files are stored is ... tom\kepler; then you have to go to the \tom\kepler directory to run the main class, such as file location: E:\Java\ Javaproject\example\tom\jiafei that's going to example. Run the main class:e:\java\javaproject\example> Java Tom.kepler. The main class name; that is, the runtime must write the full name of the main class (the package name. Main class name).   Import Statements:  1, import statements     When a Java program requires another class object as a local variable in its own member or method, the two classes are in the same package (under the same folder) of course, no problem, However, if you are not under the same package, you will need to import the classes in the other package using an import statement.      Java.lang         includes all basic language classes     javax.swing         included Graphics, text, window GUI classes in the abstract window toolset     java.io         include all input and output classes     Java.util     &NB Sp   include app classes     java.sql         include operations database classes     java.net        include all classes that implement network functions   if you want to introduce all the classes in a package, use the wildcard symbol: * To replace: import java.util.*; Java.lang contains the core class library of the Java language, which is usually not written.  2, tips run the. java file that contains the import statement and run the other. java files without having to Java tom.kepler.test like the package file.   Packages and Import statements      package is about. java files are packaged, and import is a packaged class that is imported instead of being written again in the project. So, the package is encapsulated, and import is encapsulated; it's like a reference to functions and functions.              

Java: Package statement and import statement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.