From the course: Learning JVM Languages: JVM, Java, Scala

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Functional vs. imperative programming

Functional vs. imperative programming

- [Instructor] This is the second video of this section, Functional versus Imperative Programming. In the previous video we installed Scala and looked at the REPL shell. In this video, we're going to take a look at the differences between functional and imperative programs with the help of a code example. At its heart, Java is an imperative language. In an imperative language, it's normal to have mutable variables and classes that keep internal states. In Java, a normal Plain Old Java Object, POJO, is an excellent example of the imperative programming paradigm. A standard POJO has variables that can be freely changed by calling the setter methods. Any code that can reach a POJO instance can modify its variables. This can lead to both subtle and hard-to-find bugs, especially where multiple threads try to alter a variable at the same time. In functional programming, code is written in such a way that existing variables are not modified while the program is running. Values are specified…

Contents