包和导入之间有什么区别? [英] What's the difference between a package and an import?
问题描述
包和导入之间有什么区别?请举个例子.
What's the difference between a package and an import? Please give an example.
为什么我们不能只使用 import java.util.*;
?
它不是自动授予所有其他访问权限吗?
Why can't we just use import java.util.*;
?
Doesn't it give access to all the others automatically?
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexMatches
{
public static void main( String args[] ){
// String to be scanned to find the pattern.
String line = "This order was placed for QT3000! OK?";
String pattern = "(.*)(\\d+)(.*)";
// Create a Pattern object
Pattern r = Pattern.compile(pattern);
// Now create matcher object.
Matcher m = r.matcher(line);
if (m.find( )) {
System.out.println("Found value: " + m.group(0) );
System.out.println("Found value: " + m.group(1) );
System.out.println("Found value: " + m.group(2) );
} else {
System.out.println("NO MATCH");
}
}
}
推荐答案
程序包名称是用户定义的,它是您提供的,
package name is user defined its what you give,
例如:包装测试;
import软件包用于获取Java中已经预定义的软件包,以在您当前的软件包中使用
import package is used to get already predefined packages in java to be used in your current package
例如:如果您想在测试包中使用"util"包,
Ex: if you want to use "util" package in your test package,
包装测试;
java.util.Scanner;
java.util.Scanner;
此处util是java预定义的程序包,而Scanner是util程序包中的类.
Here util is java predefined package and Scanner is the class present in util package.
这篇关于包和导入之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!