API / Apache FreeMarker Interview questions
What is the difference between the?? and! operators?
Both deal with missing values, but they answer different questions.
| Operator | Purpose | Returns | Example |
| ?? | Tests whether a value exists | A boolean | <#if user.middleName??> |
| ! | Supplies a default when a value is missing | The value itself, or the default | ${user.middleName!"N/A"} |
They are often combined: ?? is used inside an <#if> to decide whether to render a whole block, while ! is used inline to keep a single interpolation from failing. For a nested path where any segment could be absent, wrapping the path before applying either operator, such as (user.address.city)!"Unknown", protects the whole chain rather than just the last property.