

In text block using line-terminator is can be simply written as, String text = """ "elit, sed do eiusmod tempor incididunt ut labore " + Example:- String text = "Lorem ipsum dolor sit amet, consectetur adipiscing " + Generally, we split a long string into smaller substring and then using + operator convert them into multiple lines. Or a concatenation of string literals: "line 1\n" + Is equivalent to the string literal: "line 1\nline 2\nline 3\n" A text block consists of zero or more content characters, enclosed by opening and closing delimiters. It may be used to denote a string anywhere that a string literal could appear, but offers greater expressiveness and less accidental complexity. These are, Escape character Description \ line-terminator \s Insert spaceĪ text block is a new kind of literal in the Java language. To support text block features two escape characters are introduced in Java15 version. Output:- D:\Java\Program New Escape characters It should be written as, ("She said \"Hello!\" to me.") ĭ:\Java\Program ("D:\Java\Program") // error Program1:- Display ‘K’ with in single quote and double quote. The file is located at C:\KnowProgram\Java Simple programs It contains two backslashes, this means after reading the first \ the compiler read the next \ as a new character. The backslash escape character \\ is used to represent ‘\’.

The carriage return \r moves the output point back to the beginning of the line without moving down a line. It is an old technique and used to indicate a page break. The \f escape sequence is a form feed character. The \b escape character moves the cursor one character back with or without deleting the character. Whearas \n escape character is used to insert one line between the text. The \t escape character is used to insert one tab space (generally 5 space) between the text. Escape character Description Unicode value \b Backspace \u0008 \t Horizontal tab \u0009 \n New line \u000a \f Form feed \u000c \r Carriage return \u000d \" Double quote \u0022 \' Single quote \u0027 \\ Backslash \u005c Java Escape Sequence Example Java supports following escape characters. For example, if you want to put quotes within quotes you must use the escape sequence, \”, on the interior quotes. When an escape sequence is encountered in a print statement, the compiler interprets it accordingly. ("Know n Program") īut if we place \ before ‘n’ then its meaning is changed and now its represents a new line, ("Know \n Program") For example, if we use just ‘n’, then it is treated as a character ‘n’. When we place \ before a character then it is not considered as a regular character some special functionality will be added. The escape sequence changes the original meaning of a character. Every escape character must start with \ following by a single character In Java, the escape sequence is a character preceded by a backslash (\) and it has special meaning to the compiler, JVM, Console, and Editor software.
