Home > Java > JavaBase > What does the import keyword mean in java

What does the import keyword mean in java

王林
Release: 2019-11-18 11:38:02
Original
9845 people have browsed it

What does the import keyword mean in java

The import keyword is used to import packages, because in actual development, you cannot put all classes in the same default package. The function of packages is to sort Java classes. Java classes with different business logic are placed in the same package, such as tool kits and entity packages.

So, if you want class A in package a to call class B in package b, you need to import package b.

Use the import keyword

1. Display the imported classes or interfaces under the specified package

import java.util.Scanner;
Copy after login

2. Write the declaration and source file of the package between

package com.demo.util;
import java.util.Date;
public class Demo{...}
Copy after login

3. If you need to introduce multiple classes or interfaces, write them in parallel

package com.demo.util;
import java.util.Scanner;
import java.util.Date;
public class Demo{...}
Copy after login

4. If the imported class is under the java.lang package, such as: System String Math and other classes do not need to display the declaration

package com.demo.util;
public class Demo{
	//直接使用
	Math.PI;
}
Copy after login

5. .* represents all classes or interfaces under a certain package, such as java.util.*;

import java.util.*;
Copy after login

6. import static Represents the static attribute or method of importing the specified class

//到如System类的static方法或者属性
import static java.lang.System.*;
Copy after login

7. To handle the import and use of classes with the same name, you need to add the package name in front of it before use. For example, the Date class exists under both util and sql packages

//显示声明或使用
java.util.Date date = new java.util.Date();
Copy after login

8. Subpackage cannot be imported

import java.*.*;
Copy after login

Recommended tutorial: Java tutorial

The above is the detailed content of What does the import keyword mean in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template