8

I have found information that java.* and javax.* are illegal(reserved) package names(in the book "OCA Java SE 7 Programmer I Study Guide"). When I try create package "java" and run class from it, I receive:

Exception in thread "main" java.lang.SecurityException: Prohibited package name: java

but when I run class from "javax" package I receive no errors. On docs.oracle.com I've found only information:

Packages in the Java language itself begin with java. or javax.

so... is it "javax" illegal name or not? Maybe it's illegal only on Java EE, or older versions of Java?(I've tried it on JDK 1.6.0_43 and 1.7.0_25)

4

1 回答 1

3

javax.用于扩展(可能在 JRE 中),因此确保可以在这些包中定义类。IIRC,这可以通过添加javax.package.definition安全属性(未选中)在不受信任的上下文中禁用。

java.之所以特殊,是因为ClassLoader防止这些包中的非引导类加载器作为一种反微软措施。

于 2013-07-20T15:41:43.493 回答