From the course: Java SE 17 Developer (1Z0-829) Cert Prep

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Text blocks

Text blocks

- Sometimes, when we're putting literal text into a piece of program code, we actually require text that runs over multiple lines. This is often used for something like embedding program code like JavaScript or SQL. Now, we can simply concatenate multiple lines, but it is rather ugly. So, for example, if we're trying to embed some JavaScript, we might want to say let x = 10, and then we'd have to manually put the newline into one string and concatenate with the rest of the source code for our JavaScript that is meant to be on the next line. This works, but it's very ugly and clearly, if we try to edit this, we will have some trouble. Each time that we try to change anything, we will have to make sure the newlines are in the right place, we concatenate, and we include the closing and reopening quote marks on each of the lines. So this is very ugly and very time-consuming. The feature known as text blocks will simplify this idea. What we'll do, we'll introduce and terminate the multiple…

Contents