From the course: Java 8 Essential Training

Unlock the full course today

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

Understanding encapsulation

Understanding encapsulation - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Understanding encapsulation

- Java is an object-oriented language and one of the most important principles of object-oriented programming is encapsulation. Encapsulation means that you're packaging complex functionality to make it easy to use. When you first Java applications, most new programmers will put all of their code into the main method, and I've been doing that so far in this course. But you quickly find out as your applications get larger and more complex, that putting all of the code into one place makes it very difficult to manage. So instead you want to break the code out into individual classes, grouping the functionality as the logic dictates for your application. This gives you some great advantages. For example, not all functionality should be available to all parts of an application. And encapsulation lets you restrict access as needed. Each class can be placed in a particular package, and within the class, methods can be marked as public, private, or protected, so only those parts of the…

Contents