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

What does the import keyword mean in java

王林
王林Original
2019-11-18 11:38:029839browse

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;

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

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

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{...}

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;
}

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

import java.util.*;

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

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

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();

8. Subpackage cannot be imported

import java.*.*;

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!

Statement:
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