\documentclass[10pt]{article}

\usepackage{hyperref}
\usepackage[a4paper, total={6in, 8in}, top=.75in, bottom=1in]{geometry}
\usepackage{graphicx}
\usepackage{comment}
\usepackage{url}

\usepackage[normalem]{ulem}
\useunder{\uline}{\ul}{}
\DeclareGraphicsExtensions{.pdf,.png,.jpg}
\usepackage{color}

\definecolor{pblue}{rgb}{0.13,0.13,1}
\definecolor{pgreen}{rgb}{0,0.5,0}
\definecolor{pred}{rgb}{0.9,0,0}
\definecolor{pgrey}{rgb}{0.46,0.45,0.48}

\usepackage{listings}
\lstset{language=Java,
  showspaces=false,
  showtabs=false,
  breaklines=true,
  showstringspaces=false,
  breakatwhitespace=true,
  commentstyle=\color{pgreen},
  keywordstyle=\color{pblue},
  stringstyle=\color{pred},
  basicstyle=\ttfamily,
  moredelim=[il][\textcolor{pgrey}]{$$},
  moredelim=[is][\textcolor{pgrey}]{\%\%}{\%\%}
}
\begin{document}
\title{Building Blocks -- Lexical Elements}
\author{Dr. Yvon Feaster}
\date{}
\maketitle

\section*{The Basics}
Java programs are written in {\em{Unicode}} (A system that provides a unique number for every character, regardless of the platform, program, or language being used.) Unicode provides representation for more than 120,000 characters.  The most commonly used is the 7-bit ASCII character set that makes up the first 128 characters of Unicode.  However, the Java development environment can be localized to accommodate many different locales --a country or region with distinct characteristics in culture and language. 

\subsection*{Identifier}

Identifiers are the names of classes, methods, variables, etc.  An identifier is a sequence of one or more characters. Identifiers must begin with a letter or underscore.  They consist entirely of letters, digits, and underscores.   Since java uses Unicode there is a host of characters that can be used in an identifier.  However, for this class we will stick with what is available on our keyboard.  Also, as with other languages there are reserve words, such as: class, public, static, if, else, while, etc. that can not be used as identifiers.  

Example of legal identifiers:  
\begin{itemize}
	\item P
	\item q
	\item name
	\item p77
	\item a\_long\_name
	\item HelloWorld
\end{itemize}

These are all valid identifiers.  For the purposes of this class we will use meaningful names for our classes, methods, and variable.  We will discuss more on naming conventions a little later.  

\subsection*{Primitive types and Literals}

Table~\ref{tab:data_type} provides information about the 8 primitive data types provided by Java, as well as the String data type.   The first four are integer types, float and double are Floating-point types, the others are self-explanatory. 

\subsubsection*{Literals}

\noindent Literals are values that are constant.  \\

\noindent If you declare:  char aLetter = `A'; the character literal `A' is the value given to the variable called aLetter. \\

\noindent If you declare:  int aNumber = 27; the integer literal 27 is a value given to the variable aNumber.\\

\noindent If you declare:  float aFloat = 1.2 you must put `F' or `f' at the end -  float aFloat = 1.2F\\

\noindent if you declare:  double aDouble = 1.2 you have the option of put a `d' or `D' at the end - double aDouble = 1.2d\\


\begin{table}[h]
\scriptsize
\centering
\caption{Primitive Data Type Information}
\label{tab:data_type}
\begin{tabular}{|l|l|l|}
\hline
Data Type              & \begin{tabular}[c]{@{}l@{}}Default value\\ (for fields)\end{tabular} & Details                                                       \\ \hline
byte                   & 0  & -128 to 127 a byte is 8 bits (2$^8$) - which is 256 numbers \\ \hline
short                 & 0  & -32,768 to 32,767 (inclusive) - 16 bits \\ \hline
int                     & 0  &  -2,147,483,648 to 2,147,483,647 (inclusive) - 32 bits                                                           \\ \hline
long                   & 0L   & -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (inclusive) - 64 bits                                                               \\ \hline
float                  & 0.0f  &\begin{tabular}[c]{@{}l@{}}the range is beyond the scope of this class, but suffice to say the maximum\\ value is approx. 10$^38$, with about 7 significant digits  -- a float should not \\be used for precise values such as currency\end{tabular}                                                               \\ \hline
double                 & 0.0d                                                                   & \begin{tabular}[c]{@{}l@{}}usually the default choice for decimal values, but also should not be used\\ for precise values, such as currency\end{tabular}                                                            \\ \hline
char                   & `\textbackslash u0000'                                                              & `\textbackslash u0000' (which is 0) to `\textbackslash uffff' (or 65,535 inclusive) 16 bit Unicode character                                                              \\ \hline
boolean                & false                                                                  &has only two possible values:  {\em{true}} or {\em{false}}                                           \\ \hline
String (or any object) & null                                                                       &not a primitive data type, but special support is given to Strings by the language                                                              \\ \hline
\end{tabular}
\end{table}

\noindent Java provides no unsigned integer type.  Integer literals can be written in decimals, octals, and hexadecimals. Default type for integer literals are int.  
\noindent Character literals can be written directly (e.g., a or C) or using their ASCII codes.  Non-ASCII characters can be written in their hexadecimal or octal codes.  Below is an example program that uses Unicode in the class.  

\begin{lstlisting}
class TestUniEsp \u007b
    static \u0069nt \u611b = 3;
    public static void main(String[] arg) {
    System.out.println( \u611b );
    }
}
\end{lstlisting}

In the above example \textbackslash u007b is `\{' , \textbackslash u0069 is lowercase `i' \textbackslash u611b is a Chinese char.  

\begin{itemize}
	\item decimal integer literal - begins with a nonzero decimal digit, followed by a decimal digits -  ex.  30
	\item octal integer literal - begins with a leading zero, followed by octal digits - ex 036
	\item hexadecimal integer literal - begins with a leading 0x or 0X, followed by hexadecimal digits - ex. 0x1E or 0X1e - a long would be 0x1EL
\end{itemize}

Table~\ref{tab:special_char}, show special characters that can be written by using an escape sequences.  Note:  character literals appear between single quotes, such as;  `a'  or `C' or `\textbackslash u00E6' or `\textbackslash t'

\begin{table}[h]
\centering
\caption{Special Characters}
\label{tab:special_char}
\begin{tabular}{|c|c|c|}
\hline
Escape Sequence               & Unicode              & Description     \\ \hline
\textbackslash n              & \textbackslash u000A & New Line        \\ \hline
\textbackslash t              & \textbackslash u0009 & Tab             \\ \hline
\textbackslash b              & \textbackslash u0008 & Backspace       \\ \hline
\textbackslash r              & \textbackslash u000D & Carriage Return \\ \hline
\textbackslash \textbackslash & \textbackslash u005C & Backslash       \\ \hline
\textbackslash '              & \textbackslash u0027 & Single Quote    \\ \hline
\textbackslash "              & \textbackslash u0022 & Double Quote   \\ \hline
\end{tabular}
\end{table}


String class is not a primitive in Java.  But string constants can be written as literals. (e.g., ``A string literal" = A string literal  or ``\textbackslash ``A  Quote \textbackslash " " = ``A Quote")

One last thing before we move on:   A feature with numeric literals is that it is OK to use the underscore to break up numbers.  As an example: \\


\noindent \textbf{long creditCardNumber = 1234\_5678\_9012\_3456L;}\\
\textbf{long socialSecurityNumber = 999\_99\_9999L;}\\
\textbf{float pi  = 3.24\_15F;}\\




\end{document}


