From the course: Functional Programming with Java

Unlock the full course today

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

Immutability in functional programming

Immutability in functional programming - Java Tutorial

From the course: Functional Programming with Java

Start my 1-month free trial

Immutability in functional programming

- [Instructor] The first major concept of functional programming is immutability, and it's a concept that may surprise a lot of people at first. You see, most programmers learned early on that you could assign a value to a variable. For example, we can define a variable called X and store the value five in it, and then later on in the program, we can change the value of that variable to some completely different number, and later on, we can change its value again and so on, so forth. However, in functional programming, this is actually not allowed. When we say that X is equal to five, we mean that for the rest of the program, X will only ever be five. There's no way we can change it. In short, immutability means that we need to treat most of the values in a program as constants, and this can either mean that we use Java's final keyword to make sure that we don't change a given value, or we can simply learn to write our code in such a way that our programs don't have any modifications.…

Contents