\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{{[}deleted{]}} \pdfinfo{ /Title (java-f-r-beginner-02-syntax-and-simple-arrays.pdf) /Creator (Cheatography) /Author ({[}deleted{]}) /Subject (Java für Beginner \textgreater{} \#02 Syntax \& Simple Arrays 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}{1037A3} \definecolor{LightBackground}{HTML}{F0F2F9} \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 für Beginner \textgreater{} \#02 Syntax \& Simple Arrays Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{{[}deleted{]}} via \textcolor{DarkBackground}{\uline{cheatography.com/69240/cs/17461/}}} \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}{[}deleted{]} \\ \uline{cheatography.com/deleted-69240} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 15th October, 2018.\\ Updated 15th October, 2018.\\ 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}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Konditionen (if, else, if-else)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Konditionen sind zum "Überprüfen der Wahrheit" von einer Abfrage. \newline % Row Count 2 (+ 2) Primitive Abfrage-M{\"o}glichkeiten: \newline % Row Count 3 (+ 1) {\bf{\textgreater{}}} gr{\"o}{\ss}er als \newline % Row Count 4 (+ 1) {\bf{\textgreater{}=}} gr{\"o}{\ss}er oder gleich als \newline % Row Count 5 (+ 1) {\bf{\textless{}}} kleiner als \newline % Row Count 6 (+ 1) {\bf{\textless{}=}} kleiner oder gleich als \newline % Row Count 7 (+ 1) {\bf{==}} ist gleich \newline % Row Count 8 (+ 1) {\bf{!=}} Ist nicht gleich \newline % Row Count 9 (+ 1) \{\{bt\}\} \newline % Row Count 10 (+ 1) {\bf{Aber Achtung: }} Bei Strings sowie anderen Objekten sollte die `.equals({\emph{x}})` Methode genutzt werden. Weil `==` und `!=` schauen, ob es die gleiche Instanz ist. Sobald es eine andere Variabler-Halter ist, ist es nicht mehr die gleiche Instanz. \newline % Row Count 15 (+ 5) Und diese Abfragen kommen innerhalb von Abfrage-Bl{\"o}cken, welche so aussehen: \newline % Row Count 17 (+ 2) `if({[}Abfrage{]})\{` \newline % Row Count 18 (+ 1) `~// Code falls {[}Abfrage{]} true` \newline % Row Count 19 (+ 1) `\}` \newline % Row Count 20 (+ 1) An das ende eines Abfrage-Blocks, k{\"o}nnen weitere Abfragen mit ({\bf{\} else if({[}Abfrage{]})\{}}) oder ein Block der beim Gegenteil ausgeführt wird ({\bf{\} else \{}}) angehangen werden. \newline % Row Count 24 (+ 4) Dies sieht dann wie folgt aus: \newline % Row Count 25 (+ 1) `if({[}Abfrage{]})\{` \newline % Row Count 26 (+ 1) `~// Code falls {[}Abfrage{]} true` \newline % Row Count 27 (+ 1) `\} else if({[}Abfrage2{]})\{` \newline % Row Count 28 (+ 1) `~// Code falls {[}Abfrage2{]} true` \newline % Row Count 29 (+ 1) `\} else \{` \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Konditionen (if, else, if-else) (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`~// Code falls alles was an mir dran ist falsch war` \newline % Row Count 2 (+ 2) `\}` \newline % Row Count 3 (+ 1) \{\{bt\}\} \newline % Row Count 4 (+ 1) Abfragen k{\"o}nnen auch verknüpft werden. ({\bf{Logische Operatoren}}) \newline % Row Count 6 (+ 2) {\bf{\&\&}} Beides muss true ergeben \newline % Row Count 7 (+ 1) {\bf{||}} Eines der beiden muss true ergeben \newline % Row Count 8 (+ 1) Beispiel: \newline % Row Count 9 (+ 1) `if(age \textgreater{} 18 \&\& money \textgreater{} 500)\{` \newline % Row Count 10 (+ 1) `~// Code falls "age" \textgreater{} 18 ist {\bf{und}} "money" gr{\"o}{\ss}er als 500 ist ` \newline % Row Count 12 (+ 2) `\}`% Row Count 13 (+ 1) } \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}{Switch-Case}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Switch-Case Statements testen eine Variable auf einen gewissen Wert gegenüber einer Liste von M{\"o}glichkeiten (cases). \newline % Row Count 3 (+ 3) Syntax: \newline % Row Count 4 (+ 1) `{\bf{switch}}({\emph{expression}})\{` \newline % Row Count 5 (+ 1) `~{\bf{case}} {\emph{value1}}:` \newline % Row Count 6 (+ 1) `~~//Code` \newline % Row Count 7 (+ 1) `~~{\bf{break;}}` \newline % Row Count 8 (+ 1) `~{\bf{case}} {\emph{value2}}:` \newline % Row Count 9 (+ 1) `~~//Code` \newline % Row Count 10 (+ 1) `~~{\bf{break;}}` \newline % Row Count 11 (+ 1) `~{\bf{default}}:` \newline % Row Count 12 (+ 1) `~~//Code falls kein {\bf{case}} zugeschlagen hat` \newline % Row Count 14 (+ 2) `~~{\bf{break;}}` \newline % Row Count 15 (+ 1) `\}`% Row Count 16 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Oft genutzt für {\bf{Enums}} oder eine IDs.} \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}{While}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Eine While-Schleife führt ihren Code-Block solange aus, bis ihr Statement false ergibt. \newline % Row Count 2 (+ 2) Syntax: \newline % Row Count 3 (+ 1) `while({\emph{Statement}})\{` \newline % Row Count 4 (+ 1) `~//Code` \newline % Row Count 5 (+ 1) `\}` \newline % Row Count 6 (+ 1) Beispiel, welches "321" ausgibt \newline % Row Count 7 (+ 1) `int i = 3;` \newline % Row Count 8 (+ 1) `while(i \textgreater{} 0)\{` \newline % Row Count 9 (+ 1) `~System.out.print(i);` \newline % Row Count 10 (+ 1) `~i-{}-;` \newline % Row Count 11 (+ 1) `\}`% Row Count 12 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Ein nutzen dieser Schleifen sind: Iteratoren, Game-Schleifen. \newline \newline Bei jeder Schleife gibt es 2 Stichw{\"o}rter: \newline {\bf{break;}} Geht aus der Schleife raus. \newline {\bf{continue;}} Geht zur n{\"a}chsten Schleifen-Iteration über. (Überspringt den folgenden Code)} \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}{Primitive Arrays}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Eine Array ist eine {\bf{Ansammlung}} von Objekten, auch genannt eine Liste. \newline % Row Count 2 (+ 2) Syntax: \newline % Row Count 3 (+ 1) `{\emph{Typ}}{[}{]} {\emph{name}} = \{{\emph{...}}\};` \newline % Row Count 4 (+ 1) Beispiel: \newline % Row Count 5 (+ 1) `int{[}{]} zahlen = \{1, 2, 3\} // Erstellt eine int{[}{]} mit der Gr{\"o}{\ss}e von 3 sowie den angegebenen Zahlen` \newline % Row Count 8 (+ 3) `int{[}{]} nichtGesetzteZahlen = new int{[}5{]}; // Erstellt eine {\emph{int{[}{]}}} mit der gr{\"o}{\ss}e 5, welche keine gesetzten Zahlen hat` \newline % Row Count 11 (+ 3) Operationen: \newline % Row Count 12 (+ 1) {\bf{arr{[}}}{\emph{index{\bf{}}{]} }} Gibt den Wert an der Stelle {\emph{index}} \newline % Row Count 14 (+ 2) {\bf{arr{[}}}{\emph{index{\bf{}}{]} = }}{\emph{x{\bf{}}; }} Setzt den Wert an der Stelle {\emph{index}} auf {\emph{x}} \newline % Row Count 16 (+ 2) {\bf{arr.length}} Gibt die L{\"a}nge der Array% Row Count 17 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Arrays starten bei 0!} \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}{For-Schleife}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Es gibt 2 Typen for For-Schleifen: \newline % Row Count 1 (+ 1) "{\bf{For-Each}}" Geht eine Array durch \newline % Row Count 2 (+ 1) Syntax: \newline % Row Count 3 (+ 1) `for({[}Typ{]} {[}Name{]} : {[}Array{]})\{` \newline % Row Count 4 (+ 1) `~// Code` \newline % Row Count 5 (+ 1) `\}` \newline % Row Count 6 (+ 1) Bsp: \newline % Row Count 7 (+ 1) `for(int i : zahlen)\{` \newline % Row Count 8 (+ 1) `~// Code` \newline % Row Count 9 (+ 1) `\}` \newline % Row Count 10 (+ 1) {\bf{"For-i"}} Schleift solange bis eine Zahl einen Wert erreicht hatSyntax: \newline % Row Count 12 (+ 2) `for({[}Intialisierung{]}; {[}Abfrage{]}; {[}Mathe{]})\{` \newline % Row Count 13 (+ 1) `~// Code` \newline % Row Count 14 (+ 1) `\}` \newline % Row Count 15 (+ 1) Bsp: \newline % Row Count 16 (+ 1) `for(int i = 0; i != 3; i++)\{` \newline % Row Count 17 (+ 1) `~// Code` \newline % Row Count 18 (+ 1) `\}`% Row Count 19 (+ 1) } \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}{2D Primitive Array}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{2D Arrays sind Arrays, welche Arrays halten. Das klingt erst einmal kompliziert, ist es aber nicht, wenn man es sich wie `reihen` und `spalten` vorstellt. (x und y) \newline % Row Count 4 (+ 4) Syntax: \newline % Row Count 5 (+ 1) `{[}Typ{]}{[}{]}{[}{]} {[}Name{]} = \{ \{...\}, \{...\} \};` \newline % Row Count 6 (+ 1) Bsp: \newline % Row Count 7 (+ 1) `int{[}{]}{[}{]} zweiDee = \{ ` \newline % Row Count 8 (+ 1) `~\{1, 2, 3\} // 1 "Reihe"` \newline % Row Count 9 (+ 1) `~\{4, 5, 6\} // 2 "Reihe"` \newline % Row Count 10 (+ 1) `\}` \newline % Row Count 11 (+ 1) Bei diesem Beispiel w{\"a}re {\bf{'zweiDee{[}0{]}{[}1{]}' == 2}}. Weil man bei Arrays mit 0 anf{\"a}ngt, ist die {[}0{]} die erste Reihe, und die darauffolgende {[}1{]} die 2. Spalte.% Row Count 15 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Wird manchmal für 2D Spielefelder wie in TicTacToe verwendet (oA.)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}