Java Modifiers


With the variety of programming languages out there, and each one of them may have a slightly different implementation on their syntax and behavior. It is kind of hard to remember them all, so it will be very helpful to have some quick cheat sheet that will provide guideline to some of the basic concepts.  I’m a big believer in bite size instruction,  with simple and precise information.

In the Object Oriented world, the concept of modifier and their behavior is one of the core understanding needed in order to architect your application securely.  You provide access to object members with a modifier, that is basically your security policy, which dictate who can access them.  For example, for your private variables, you don’t want any one to put their hands on them.

In Java, there are 4 modifiers, public, private, protected, but wait there is a 4th one? Yes, there is, which is no modifier, what does it mean when you don’t provide a modifier.

Here is a summary table of the access policy:

This should be quite self explanatory, but if you are not familiar with the Java programming language, and would like to get more details, here is a link to the full explanation from Oracle.