NAMES(4)
Meaning of PackageNames:
- if package name a simple name. then it denotes a package that exists at compile time otherwise error.
- if a qualified name, Q.id, then Q is a package that has id as a member package of Q, i.e a subpackage, that exists at compile time otherwise a compile time error results.
Meaning of PackageOrTypeNames:
- if a simple name. then it denotes a TypeName if the name Q occurs in the scope of a type named Q, else a PackageName.
- let qualified name be Q.id. if member id of a type or package exists, then a TypeName, otherwise, a PackageName.
Meaning of TypeNames:
- if simple name. if name consists of a single identifier, then the identifier must exist in the scope of exactly one visible declaration of a type with this name, or a compile time error occurs. The meaning of a type is a type.
- if qualified name of the form Q.id. if id names exactly one type that is a member of the type or package denoted by Q, then the qualified type name denotes that type. A compile time error occurs if id does not name a member type within Q, or is not accessible in Q or id occurs more than once in Q, then compile time error occurs.
Meaning of ExpressionNames:
1. simple name or single identifier. There must be exactly one visible declaration denoting either a field, parameter or local variable in scope at the point at which the identifier occurs.
If declaration declares a final field, the name’s meaning is its value, otherwise meaning of the expression name is the variable declared by the declaration.
If the field is an instance variable, the expression name must appear within the declaration of an instance method, constructor, instance initializer or instance variable initializer. If within a static method, static initializer or initializer for a static variable, then a compile time error occurs.
2. qualified, of form Q.id. in this situation, the expression name, Q.id has already been classified as package, type or expression name.
- if Q is a package name, then a compile time error occurs.
- if Q a type name naming a class type, then
- there must be exactly one accessible member that is the field id otherwise a compile time error occurs.
- otherwise if the single accessible member is not a class variable (i.e declared stastic) then a compile time error occurs.
- otherwise if the class variable is declared final, then Q.id denotes the value of the class variable. The type of the expression Q.id is the declared type of the class variable after capture conversion. Note that Q.id should not appear in a context that requires a variable.
- otherwise, Q.id denotes the class variable. The type of the expression Q.id being the declared type of the class variable after capture conversion. This clause also covers the enum constants since these always have a corresponding final class variable.
- if Q is a type name that names an interface type
- there must be exactly one accessible member of the interface type, the field named id.
- otherwise Q.id denotes the value of the field. The declared type being the type of the field after capture conversion. If Q.id appears in a context that requires a variable and not a value, then a compile time error ensures.
- if Q is an expression name, let T be the type of the expression Q:
- T must be a reference type
- there must be exactly one accessible member of the type T named id.
- otherwise if this field is any of the following:
- a field of an interface type, or
- a final field of a class type (either a class or an instance variable)
- the final field length of an array type
Then Q.id denotes the value of the field. The declared type being the type after capture conversion. If the context requires a variable, a compile time error.
- otherwise Q.id is a variable, id, (class or instance variable). The type of the expression Q.id is the type of the field member after capture conversion.
MEANINGS OF METHOD NAMES
A method name appears only in a method invocation expression or as an element name in an element-value pair for annotations. Determination of the meaning of a name classified as a method name is as follows:
1. Simple Method Names: a simple method name appears as the element name in an element-value pair. The identifier in an element-value pair must be the simple name of one of the elements of the annotation type identified by TypeName in the containing annotation, otherwise a compile time error occurs.
Otherwise, a simple method name appears in the context of a method invocation expression.
2. Qualified Method Names: a qualified method name can only appear in the context of a method invocation expression. If given Q.id then Q has already been classified as a package name, a type name or an expression name. if Q is a package name, then compile time error results, otherwise id is the method name to be used for method invocation. If Q is a type name, then id must name at least one static method of the type Q. if Q is an expression name, then let T be the type of the expression Q; id must name one method of the type T.
ACCESS CONTROL: accessibility is a feature of the java programming language whereby access to details of entities in the language is allowed or otherwise disallowed. If allowed, the entity is said to be accessible.
Note: a. accessibility depends on type and declaration modifiers.
b. means of access to members of package and reference types are
– qualified names,
- field access expressions
- method invocation expressions
the three means above are called constructs for qualified access.
Access control applies to:
- qualified access
- the invocation of constructors by class instance creation expressions
- explicit constructor invocations
Determining accessibility:
- package is always accessible
- if a class or interface type is declared public, thus provided it is observable in its compilation unit, it may be accessed by any code, otherwise, where not public, access is from within the package in which it is declared.
- an array type is accessible if and only if its element type is accessible
- a member (class, interface, field or method) of a reference (class, interface or array) type or a constructor of a class type is accessible only if the type is accessible and the member or constructor is declared to permit access:
o if declared public (note: all members of interfaces are implicitly public)
o if declared protected, thus access is permitted for one of the following situations:
§ where access occurs from within the package containing the class in which the protected member or constructor is declared.
§ Access conforms to the section “details on protected access” (immediately below.)
§
o If declared private, access is permitted only within the body of the top level class that encloses the declaration of the member or constructor.
o Otherwise, there is default access (or package-private.) where access occurs only from within the package in which the type is declared.
Details on protected access: a protected member or constructor of an object may be accessed from outside the package (like public) in which it is declared only by code that is responsible for the implementation of that object, otherwise access is defined as:
An example:
package api_package;
public class T {
String monkey;
protected T(){ super();}
protected void throway(){}
}
public class S extends T {
String jungle;
S(){super();} //access permitted to T's constructor
//access to T's member, throway permitted from
//within this subclass.
void getFromT(){
throway(); //from T
jungle = monkey; //monkey from T
new T(); //anonymous class instance creation expression,
//allowed from protected superclass, T.
}
}
You can make up examples for all other modifiers or study that on the jls. Happy coding.
FULLY QUALIFIED NAMES AND CANONICAL NAMES: just read the jls. I can’t be rewriting what has already been written down. Redundancy in writing, methinks.

No comments:
Post a Comment