Nora McDougall-Collins
Nora McDougall-Collins

Reputation: 531

Do Java access modifiers use permissions from the operating system or is the access controlled by Java itself?

I have found many, many resources about Java access modifiers that explain what they are and how to use them and why to use them and when to use them. But, I have found no discussion on how they work or how much Java depends on the operating system to enforce them and if so, how much the enforcement is dependent on which operating system is used. Possibly, I am using the wrong search terms.

Upvotes: 0

Views: 50

Answers (1)

markspace
markspace

Reputation: 11030

Basically it's 100% controlled by Java and the JVM, and the OS has nothing to do with it. There's no hardware intervention (for example) in controlling access to a private field. It's just the software running on the JVM doesn't let you (directly, you can do it with reflection) read the memory location of that field.

AFAIK, all Java objects are allocated on the heap which is just ordinary memory that can be read or written. Some parts of the JVM might actually be protect by the OS -- executable memory for example, or the stack. But Java is a unified memory system where all memory, all objects and their fields, go in the same OS "bucket" of memory, and that's the heap.

I think this is sometimes called a SISD model -- "single instruction single data," where the "single data" is just the heap. And yes I'm ignoring the SIMD instructions that Intel has because those instructions are relatively rare.

Upvotes: 1

Related Questions