\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{EthanHann} \pdfinfo{ /Title (java-basics-to-intermediate.pdf) /Creator (Cheatography) /Author (EthanHann) /Subject (Java Basics to Intermediate Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{D6882F} \definecolor{LightBackground}{HTML}{FCF7F2} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Java Basics to Intermediate Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{EthanHann} via \textcolor{DarkBackground}{\uline{cheatography.com/34848/cs/10942/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}EthanHann \\ \uline{cheatography.com/ethanhann} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 19th February, 2017.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{p{0.59501 cm} x{1.87657 cm} x{2.10542 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Primitive Data Types}} \tn % Row 0 \SetRowColor{LightBackground} {\emph{type}} & {\emph{size}} & {\emph{range of values}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{byte}} & 8-bit {\emph{signed}} 2's comp & (-128 -\textgreater{} 127) \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{short}} & 16-bit {\emph{signed}} 2's comp & (-32,768 -\textgreater{} 32,767) \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{int}} & 32-bit {\emph{signed}} 2's comp & (-2\textasciicircum{}31\textasciicircum{} -\textgreater{} 2\textasciicircum{}31\textasciicircum{}-1) \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{long}} & 64-bit {\emph{signed}} 2's comp & (-2\textasciicircum{}63\textasciicircum{} -\textgreater{} 2\textasciicircum{}63\textasciicircum{}-1) \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} {\bf{long}} & 64-bit {\emph{unsigned}} & (0 -\textgreater{} 2\textasciicircum{}64\textasciicircum{}-1) \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{float}} & \seqsplit{single-precision} 32-bit {\emph{signed}} & (-3.40282347 x 10\textasciicircum{}38\textasciicircum{} -\textgreater{} 3.40282347 x 10\textasciicircum{}38\textasciicircum{}) \tn % Row Count 15 (+ 3) % Row 7 \SetRowColor{white} {\bf{double}} & \seqsplit{double-precision} 64-bit {\emph{signed}} & \seqsplit{(-1.79769313486231570} x 10\textasciicircum{}308\textasciicircum{} -\textgreater{} \seqsplit{1.79769313486231570} x 10\textasciicircum{}308\textasciicircum{}) \tn % Row Count 19 (+ 4) % Row 8 \SetRowColor{LightBackground} {\bf{char}} & 16-bit {\emph{unsigned}} Unicode character & (0 -\textgreater{} 65,535) \tn % Row Count 22 (+ 3) % Row 9 \SetRowColor{white} {\bf{boolean}} & {\emph{size not defined}} & true / false \tn % Row Count 25 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Hello World}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{public class HelloWorld \{\{nobreak\}\} \newline \{ \newline public static void main(String{[}{]} args) \{\{nobreak\}\} \newline \{ \newline \seqsplit{System.out.println("Hello} World!"); \{\{nobreak\}\} \newline \} \newline \} \{\{nobreak\}\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Declaring and Initalizing}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Integers}} \newline % Row Count 1 (+ 1) `int a, b;` \textless{}-{}- Declare two integer variables \newline % Row Count 2 (+ 1) `a = 100;` \textless{}-{}- Initialize 'a' with a value of 100 \newline % Row Count 3 (+ 1) `b = 18;` \textless{}-{}- Initialize 'b' with a value of 18 \newline % Row Count 4 (+ 1) `int c = a + b;` \textless{}-{}- Declare {\emph{and}} initialize c with the value of a plus b \newline % Row Count 6 (+ 2) {\bf{Double}} \newline % Row Count 7 (+ 1) `double a, b;` \newline % Row Count 8 (+ 1) `a = 1.57;` \newline % Row Count 9 (+ 1) `b = 9.8765;` \newline % Row Count 10 (+ 1) `double c = a + b;` \newline % Row Count 11 (+ 1) It is the same for every {\bf{primitive}} data type.% Row Count 12 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.58726 cm} p{0.66832 cm} p{0.4177 cm} x{1.50372 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{5.377cm}}{\bf\textcolor{white}{Operations on Number Variables}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Integer}} & {\emph{sign}} & + - & +99 -or- -99 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} & {\emph{add}} & + & 5 + 3 = 8 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} & {\emph{subtract}} & - & 5 - 3 = 2 \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} & {\emph{multiply}} & * & 5*3 = 15 \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} & {\emph{divide}} & / & 5/3 = 1 {\emph{no fractional part}} \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} & {\emph{remainder}} & \% & 5 \% 3 = 2 \tn % Row Count 10 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{Floating-Point Numbers}} & {\emph{add}} & + & 3.141 + 2.0 = 5.141 \tn % Row Count 12 (+ 2) % Row 7 \SetRowColor{white} & {\emph{subtract}} & - & 3.141 - 2.0 = 1.111 \tn % Row Count 14 (+ 2) % Row 8 \SetRowColor{LightBackground} & {\emph{multiply}} & * & 3.141 * 2.0 = 6.282 \tn % Row Count 16 (+ 2) % Row 9 \SetRowColor{white} & {\emph{divide}} & / & 3.141 / 2.0 = 1.5705 \tn % Row Count 18 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.8354 cm} x{1.00248 cm} x{1.21133 cm} x{1.12779 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{5.377cm}}{\bf\textcolor{white}{Boolean Operations}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Values}} & {\bf{Literals}} & {\bf{Operations}} & {\bf{Operators}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\emph{true}} & true & and & \&\& \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} {\emph{false}} & false & or & || \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} & & not & ! \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{4}{x{5.377cm}}{} \tn % Row Count 5 (+ 0) % Row 5 \SetRowColor{white} {\bf{a}} & {\bf{b}} & {\bf{a \&\& b}} & {\bf{a || b}} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} false (0) & false (0) & false & false \tn % Row Count 8 (+ 2) % Row 7 \SetRowColor{white} false (0) & true (1) & false & true \tn % Row Count 10 (+ 2) % Row 8 \SetRowColor{LightBackground} true (1) & false (0) & false & true \tn % Row Count 11 (+ 1) % Row 9 \SetRowColor{white} true (1) & true (1) & true & true \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.71009 cm} x{1.29487 cm} x{1.08602 cm} x{1.08602 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{5.377cm}}{\bf\textcolor{white}{Comparison Operators}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Operator}} & {\bf{Meaning}} & {\bf{true}} & {\bf{false}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} == & equal & 2 == 2 \{\{nobreak\}\} & 2 == 3 \{\{nobreak\}\} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} != & not equal & 3 != 2 & 2 != 2 \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \textless{} & less than & 2 \textless{} 13 & 2 \textless{} 2 \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} \textless{}= & less than or equal & 2 \textless{}= 2 & 3 \textless{}= 2 \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} \textgreater{} & greater than & 13 \textgreater{} 2 & 2 \textgreater{} 13 \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} \textgreater{}= & greater than or equal & 3 \textgreater{}= 2 & 2 \textgreater{}= 3 \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}----} \SetRowColor{LightBackground} \mymulticolumn{4}{x{5.377cm}}{Examples: \newline {\bf{Check if a number is a multiple of 2}} \newline `(x \% 2 == 0)` returns true if x is a multiple of 2 \newline \newline {\bf{Check months}} \newline `(month \textgreater{}= 1) \&\& (month \textless{}= 12)` returns true if month is between 1 and 12} \tn \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Printing and Parsing}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Printing to console}} \newline % Row Count 1 (+ 1) `System.out.print(String s);` {\emph{print s}} \newline % Row Count 2 (+ 1) \seqsplit{`System.out.println(String} s);` {\emph{print s followed by newline}} \newline % Row Count 4 (+ 2) `System.out.println();` {\emph{print a newline}} \newline % Row Count 5 (+ 1) {\bf{Parse command-line args}} \newline % Row Count 6 (+ 1) `int Integer.parseInt(String s);` {\emph{convert s to an int value}} \newline % Row Count 8 (+ 2) `double \seqsplit{Double.parseDouble(String} s);` {\emph{convert s to a double value}} \newline % Row Count 10 (+ 2) `long Long.parseLong(String s);` {\emph{convert s to a long value}}% Row Count 12 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}