Java record -20-package and import statement

Source: Internet
Author: User

Java Package and import statement

  1. Package: Used to categorize classes that complete different functions, and put them under different catalogs (packages).

  2. Naming rules for packages: Generally speaking company domain name reversal as package name. For package names, each letter needs to be lowercase.

  3. If the package is not used when defining a class, then Java will assume that the class we define is in the default packages.

  4. There are two ways to compile a Java source file with the package declaration:

    1). Compile directly and then manually build the directory structure based on the package name defined in the class, and finally put the generated class file into the directory structure (rarely used, more cumbersome).

    2). Use the compile parameter-D, as javac-d. source files. Java, so that after compiling, the compiler will automatically help us build the directory structure of the package.

  5. There are two package names, respectively, aa.bb.cc and AA.BB.CC.DD, so we call the latter the former child package.

  6. Import, import the various classes separated by the package, so that the compiler can find the required classes.

  7. Import Syntax: Import package path name. class name;

  8. Import Com.sun.*, which represents all classes under the Com.sun package.

    Import aa.bb.* does not import the class under the aa.bb.cc package, which is required to write:

    Import aa.bb.*;

    Import aa.bb.cc.*;

  9. Questions about the order of the package, import, class:

    1). The first need to define the package (packages), optional;

    2). Next, import is used, optional;

    3). Then the definition of class or interface.

  10. If two classes are under the same package, then you do not need to import and use them directly.




Java record -20-package 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.