Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it "javax" illegal(reserved) package name or not?

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)

like image 595
SathOkh Avatar asked Jul 20 '13 15:07

SathOkh


People also ask

Is package name necessary in Java?

As you (implicitly) acknowledged, you are not required to declare the name of a package in the case if the default package. Let us put that quibble aside ... The reason for this seeming redundancy is that without a package declaration, the meaning of Java1 source code would be ambiguous.

Can packages be named?

Naming ConventionsPackage names are written in all lower case to avoid conflict with the names of classes or interfaces. Companies use their reversed Internet domain name to begin their package names—for example, com. example. mypackage for a package named mypackage created by a programmer at example.com .

What is javax package used for?

Package javax.Provides interfaces for tools which can be invoked from a program, for example, compilers. These interfaces and classes are required as part of the Java™ Platform, Standard Edition (Java SE), but there is no requirement to provide any tools implementing them.

What is the default package name in Java?

lang Package. Java compiler imports java. lang package internally by default. It provides the fundamental classes that are necessary to design a basic Java program.


1 Answers

javax. is used for extensions (possibly within the JRE), so sure it is possible to define classes within those packages. IIRC, this can be disabled in untrusted contexts by adding javax. to the package.definition security property (not checked).

java. is special because ClassLoader prevents non-bootstrap class loader in those packages as an anti-Microsoft measure.

like image 71
Tom Hawtin - tackline Avatar answered Oct 16 '22 20:10

Tom Hawtin - tackline