From the course: Java Object-Oriented Programming

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Exploring encapsulation in Java string class

Exploring encapsulation in Java string class - Java Tutorial

From the course: Java Object-Oriented Programming

Exploring encapsulation in Java string class

- With the good foundation of encapsulation, we can begin to explore how the Java programming language, uses encapsulation in some of its built-in classes. Exploring more examples will help you better understand this object oriented principle, and recognize the scenarios it should be used in. One common Java class that uses encapsulation, is the string class. To find out more about the string class, we'll click into it using our IDE. I'm on a Mac, so I'll do Command Click, but it may be different on your machine. This class is pretty large at over 3000 lines, but we'll break it into parts and work through it, to see how it uses encapsulation. A string is made up of characters, and those character values actually live in the form of bytes and a byte array. This is all hidden away from us and the way we use strings in everyday programs. This means, even if things inside the string class change, it won't affect the rest…

Contents