Test 3 - Free Java SE 25 certification Mock test - Exam Code 1Z0-831-Oracle certified Java SE 25 Professional
Text handling is a quiet source of lost marks on the Oracle 1Z0-831 exam and that's exactly what this free Java SE 25 mock test is designed to target. The questions are all about String, StringBuilder and text blocks (the three tools you're expected to be able to use fluently when you're manipulating text in modern Java).
Start with string immutability. You'll be looking at code where methods such as replace, trim, strip and toUpperCase appear to be changing the value and you'll have to work out what the original variable actually still holds. There's a number of questions around string literals, the string pool and the new keyword, asking when == will return true and when you actually do need to use equals. Others look at the difference between strip and trim, the difference between isBlank and isEmpty and what repeat, chars and lines return.
StringBuilder questions are all about mutation. You're going to be looking at a series of chained calls to append, insert, delete, deleteCharAt, reverse and setLength and you need to track what the buffer contains after each step. Index based methods are a classic place for the exam to trip you up with an off by one so you need to be very careful with your counting and you need to know which of the calls will throw a StringIndexOutOfBoundsException.
Text blocks get a full going over. They're bounded by triple quotes, the incidental indentation is stripped off according to the position of the closing delimiter and the least indented line in the block. You'll be expected to know how trailing spaces are stripped, how the backslash at the end of a line prevents a newline, and how escape sequences (e.g. \s and \n) work. The related questions look at the formatted and the String.format family and compare the output of a text block with that of an equivalent concatenated string.
Each explanation shows the exact characters that are produced (including whitespace) which is where most people go wrong. You'll also see which of the methods return a new object and which modify the receiver (that distinction is what determines the answer in many cases). Be very aware of method chaining. A long chain of method calls is very easy to misread so break each step out onto its own line, write the intermediate value next to it and only then pick your answer.
You should be able to take a snippet of string code and instantly know whether it will compile, whether it will mutate anything and what it will print. That confidence is what frees you up to go on to the harder topics (streams, concurrency etc). Time yourself doing the test, note every mistake and go back and rework the weak spots until the behaviour is absolutely automatic.
