From the course: Secure Coding in Java

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Class and package accessibility

Class and package accessibility - Java Tutorial

From the course: Secure Coding in Java

Start my 1-month free trial

Class and package accessibility

- [Instructor] One of the features of Java that is often overlooked or best misunderstood is accessibility. Good software development practices from a security perspective must keep this functionality in mind. Limiting accessibility in Java is relatively straightforward. Public is just that; it's public for anyone consuming your code. Only mark things public if you expect them to be consumed and have taken adequate measures to protect that code when it is consumed. If your class or interface should not be consumed outside its containing package, it should be marked as package private. You can further protect your packages by using the package access security property. Now this isn't a touch-free setting and before you consider using it, I suggest you do some research and fully understand its impact. In addition, class methods, members, and constructors should be protected if they should not be exposed to…

Contents