O'Reilly logo

Java Security, 2nd Edition by Scott Oaks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Java Language Security Constructs

In this chapter, we’re concerned primarily with how Java operates on things that are in memory on a particular machine. Within a Java program, every entity -- that is, every object reference and every primitive data element -- has an access level associated with it. To review, this access level may be:

private

The entity can only be accessed by code that is contained within the class that defines the entity.

Default (or package)

The entity can be accessed by code that is contained within the class that defines the entity, or by a class that is contained in the same package as the class that defines the entity.

protected

The entity can only be accessed by code that is contained within the class that defines the entity, by classes within the same package as the defining class, or by a subclass of the defining class.

public

The entity can be accessed by code in any class.

The notion of assigning data entities an access level is certainly not exclusive to Java; it’s a hallmark of many object-oriented languages. Since the Java language borrows heavily from C++, it’s not surprising that it would borrow the basic notion of these access levels from C++ as well (although there are slight differences between the meanings of these access modifiers in Java and in C++).

As a result of this borrowing, the use of these access modifiers is generally thought of in terms of the advantage such modifiers bring to program design: one of the hallmarks of object-oriented ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required