009-Use of package and import

Disclaimer: All my articles are the compilation of online teaching videos, including Mad God Talk, Shang Silicon Valley, Dark Horse Programmer, etc., used as reference materials, without any commercial use, please refer to the majority of netizens, please do not spray ,Thank you. (Note that due to the website, some code characters may have problems. It is recommended that when reading the code, it is best to look at the corresponding picture below)

1. Keyword——package

1. The package statement is the first statement in the Java source file, indicating the package where the class defined in the file is located. (If the statement is defaulted, it is specified as an unnamed package). Its format is: package top-level package name. sub-package name;
2. The package corresponds to the directory of the file system. In the package statement, use "." to indicate the level of the package (directory);
3. The package is usually identified by lowercase words. Usually use the inversion of the company's domain name: com.atguigu.xxx

Second, the role of the package

1. Packages help manage large-scale software systems: divide classes with similar functions into the same package. For example: MVC design pattern
2. Packages can contain classes and sub-packages to divide project levels for easy management
3. Solve the problem of class naming conflicts
4. Control access permissions
Example: A shipping software system includes: a set of domain objects, GUI and reports Subsystem
009-Use of package and import

Three, MVC design pattern

MVC is one of the commonly used design patterns, which divides the entire program into three levels: view model layer, controller layer, and data model layer. This design pattern that separates program input and output, data processing, and data display makes the program structure flexible and clear. At the same time, it also describes the communication mode between the program objects and reduces the coupling of the program.
1. Model layer model mainly deals with data
 Data object encapsulation model.bean/domain
 Database operation class model.dao
 Database model.db
2. Control layer controller handles business logic
 Application interface related controller.activity
 Storage fragment controller.fragment
 Display the list of adapter controller.adapter
 Service related controller.service
Extracted base class controller.base
3. View display data on the view layer
 Related tools view.utils
 Custom view view.ui
009-Use of package and import

Fourth, the main package introduction in JDK

 java.lang—contains some core classes of the Java language, such as String, Math, Integer, System and Thread, which provide common functions.
 java.net—contains classes and interfaces for performing network-related operations.
 java.io ---- Contains classes that can provide multiple input/output functions.
 java.util-Contains some utility classes, such as a collection framework class that defines system characteristics, interfaces, and uses functions related to date and calendar.
 java.text----contains some classes related to java formatting
 java.sql----contains related classes/interfaces of java for JDBC database programming
 java.awt----contains abstract windows Toolset (abstract window toolkits) multiple classes, these classes are used to build and manage the graphical user interface (GUI) of the application.

Five, keywords-import

1. Function: In order to use Java classes defined in different packages, the import statement is needed to import the required classes or all classes (. )






under the specified package level. The import statement tells the compiler where to look for classes. 2. Syntax format: import package name. class name; 3. For example: import java.util.Scanner; Note:  Use import in the source file to explicitly import the class or interface under the specified package  The location is in the package declaration between the declaration and the  If you need to import the plurality of classes or interfaces, then a plurality of parallel import statements to explicitly  example: can java.util manner, disposable import all the class or interface package util
 If the imported class or interface is under the java.lang package or under the current package, you can omit this import statement.
 If you use a class with the same name under a different package in your code, you need to use the entire class The method of name indicates which class is called
 If the class under the java.a package has been imported, if you need to use the class under the sub-package of package a, you still need to import
 The use of import static combination: call the specified class or interface Static properties or methods

Guess you like

Origin blog.51cto.com/12859164/2546685