Java literals

To understand literals, let's take an example to assign value to a variable.


\begin{lstlisting}
boolean flag = false;
\end{lstlisting}

Here, $\lstinline{boolean}$ is a data type. $\lstinline{flag}$ is variable. $\lstinline{false}$ is literal. A Literal is the source code representation of a fixed value. Values like $1.5, 4, true, '\symbol{92}u0050'$ that appear directly in a program without requiring computation are literals.

In the above example, $\lstinline{flag}$ is a variable. Since it's a boolean type variable, it may store either false or true. For the compiler to understand it, it requires computation. However, literals like $-5, 'a', true$ represents fixed value.



Subsections