\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{tarinya} \pdfinfo{ /Title (oo-java.pdf) /Creator (Cheatography) /Author (tarinya) /Subject (OO\_Java 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}{5173C2} \definecolor{LightBackground}{HTML}{F4F6FB} \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{OO\_Java Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{tarinya} via \textcolor{DarkBackground}{\uline{cheatography.com/25055/cs/6436/}}} \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}tarinya \\ \uline{cheatography.com/tarinya} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 8th January, 2016.\\ Updated 10th May, 2016.\\ 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}{Typ Konversion}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/tarinya_1450193804_Screen Shot 2015-12-15 at 16.35.51.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{schwarze Pfeile: expliziet \newline rote Pfeile: impliziet, evt Genauigkeitsverlust \newline alles andere impliziet} \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-Statement}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{switch (Ausdruck) \{ \newline case Wert1: \newline Anweisungen; \newline break; \newline case Wert2: \newline Anweisungen; \newline break; \newline default: \newline Anweisungen; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Wenn Ausdruck Wert1 entspricht, wird Anweisung 1 ausgeführt...} \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}{Typ Polymorphismus}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{car extends vehicle \newline @Override \newline drive()\{\} \newline Vehicle v = new Car(); \newline //calls drive of Car not Vehicle \newline v.drive();} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Klasse hat eigenen Typ plus alle Typen der Superklassen. \newline verschiedene "Brillen" \newline Dynamic Dispatch = dynamischer Typ zur Laufzeit entscheidet über aufgerufene Methoden.} \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}{Rekursion}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{public boolean groupSum(int start, int{[}{]} nums, int target) \{ \newline if (start \textgreater{}= nums.length) return (target == 0); \newline if (groupSum(start + 1, nums, target - nums{[}start{]})) return true; \newline if (groupSum(start + 1, nums, target)) return true; \newline return false;\} \newline \newline Collection\textless{}String\textgreater{} validParentheses(int nofPairs)\{ \newline Collection\textless{}String\textgreater{} list = new ArrayList\textless{}\textgreater{}(); \newline if (nofPairs == 0) \{list.add("");\} else \{ \newline for (int k = 0; k \textless{} nofPairs; k++) \{ \newline Collection\textless{}String\textgreater{} infixes = validParentheses(k); \newline Collection\textless{}String\textgreater{} suffixes = \seqsplit{validParentheses(nofPairs} - k - 1); \newline for (String infix : infixes) \{ \newline for (String suffix : suffixes) \{ \newline list.add("(" + infix + ")" + suffix);\}\}\}\} \newline return list;\}} \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}{Generics}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{allg. Form} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{class Pair\textless{}T,U\textgreater{}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{TypeBound (Bedingungen für Type)} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{class Node\textless{}T extends Comparable\textless{}T\textgreater{}\textgreater{}\{\{nl\}\}Node\textless{}Person\textgreater{}//ok Node\textless{}Student\textgreater{}//Error} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Multiple TypeBounds (mit \& anh{\"a}ngen)} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{class Node\textless{}T extends Person \& Comparable\textless{}Person\textgreater{}\textgreater{}} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{generische Methode} \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{public \textless{}T extends Person\textgreater{} T set (T element)\{...\}\{\{nl\}\}\textless{}T\textgreater{}: Bedingungen für Input\{\{nl\}\}T : Rückgabetyp} \tn % Row Count 11 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Wildcard-Typ (Nutzen: Typ{\bf{argument}} nicht relevant)} \tn % Row Count 13 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Node\textless{}?\textgreater{} undef -{}-\textgreater{} kein Lesen \& schreiben ausser: Object o = undef.getValue();} \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Lambdas}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`(p1, p2) -\textgreater{} p1.getAge() – p2.getAge()`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`p -\textgreater{} p.getAge() \textgreater{}= 18`} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`people.sort((p1, p2) -\textgreater{} \seqsplit{p1.getName().compareTo(p2.getName()));`}} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{`people.sort(Comparator.comparing(Person::getLastName).thenComparing(Person::getFirstName));`}} \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`Utils.removeAll(people, person -\textgreater{} person.getAge() \textless{} 18);`} \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{`people.sort(Comparator.comparing(p1} -\textgreater{} \seqsplit{p1.getLastName().length()));`}} \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Syntax: (Parameter) -\textgreater{} \{Body\}} \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}{StreamAPI}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{people \newline .stream() \newline .filter(p -\textgreater{} p.getAge() \textgreater{}= 18) \newline .map(p -\textgreater{} p.getLastName()) \newline .sorted() \newline .forEach(System.out::println); \newline \newline people.stream().mapToInt(p -\textgreater{} p.getAge()) \newline .average().ifPresent(System.out::println); \newline \newline Map\textless{}String, Integer\textgreater{} totalAgeByCity = \newline people.stream() \newline .collect( \newline \seqsplit{Collectors.groupingBy(Person::getCity}, \newline \seqsplit{Collectors.summingInt(Person::getAge)));}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{endliche Quelle: `IntStream.range(1, 100)`\{\{nl\}\}unendl. Quelle: `Random random = new Random(); \seqsplit{Stream.generate(random::nextInt).limit(100)`}} \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}{FileReader/Writer}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{private static void reverteText() throws FileNotFoundException, IOException\{ \newline try (FileReader reader = new FileReader("input.txt"); \newline FileWriter writer = new FileWriter("outpur.txt"))\{ \newline int value = reader.read(); \newline String text = ""; \newline while (value \textgreater{}=0)\{ \newline text = (char)value + text; \newline value = reader.read();\} \newline writer.write(text);\}\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.39356 cm} x{3.58344 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Sichtbarkeit}} \tn % Row 0 \SetRowColor{LightBackground} public & alle Klassen \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} protected & Package und Sub-Klassen \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} private & nur innerhalb Klasse \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} (keines) & innerhalb Package \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.9954 cm} x{3.9816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Datentypen}} \tn % Row 0 \SetRowColor{LightBackground} byte & 8 bit (2\textasciicircum{}7\textasciicircum{} bis 2\textasciicircum{}7\textasciicircum{}-1) \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} short & 16 bit \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} int & 32 bit \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} long & 64 bit (1L) \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} float & 32 bit (0.1f) \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} double & 64 bit \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Operator-Prio}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{+,-,++,-{}-,! (un{\"a}r)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{*, /, \%} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{+, - (bin{\"a}r)} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\textless{}, \textless{}=, \textgreater{}, \textgreater{}=} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{==, !=} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\&\&} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{||} \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.23965 cm} x{2.73735 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Rundungsfehler}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{0.1+0.1+0.1 != 0.3} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Problem: double/float & `x == y` \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} L{\"o}sung & `Math.abs(x – y) \textless{} 1e-6` \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{1.64241 cm} x{3.33459 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Integer Literal}} \tn % Row 0 \SetRowColor{LightBackground} bin{\"a}r & 0b10 = 2 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} oktal & 010 = 8 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} hex & 0x10 = 16 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} opt. & 1000 = 1\_000 \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Arithmetik}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{1 / 0 -{}-\textgreater{} ArithmeticException: / by zero \newline 1 / 0.0 -{}-\textgreater{} Infinity \newline -1.0 / 0 -{}-\textgreater{} -Infinity \newline 0 / 0.0 -{}-\textgreater{} NaN} \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}{Arithmetik Overloading}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{int operate(int x, int y) \{ ... \} \newline double operate(int x, double y) \{ ... \} \newline double operate(double x, double y) \{ ... \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{operate(1, 2); -{}-\textgreater{} meth 1 \newline operate(1.0, 2); -{}-\textgreater{} meth 3 \newline operate(1, 2.0); -{}-\textgreater{} meth 2} \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}{Overloading}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/tarinya_1452702762_Screen Shot 2016-01-13 at 17.32.23.png}}} \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}{Bedingungsoperator}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{max = left \textgreater{} right ? left : right;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{wenn left\textgreater{}right wird max = left, sonst max=right} \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}{Package prio}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{own class (inc. nested class)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{single type imports -\textgreater{} import p2.A;} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{class in same package} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{import on demand -\textgreater{} import p2.*} \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Enum}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{public enum Color \{ \newline BLUE(1), RED(2); \newline private final int code; \newline private Color(int code) \{ \newline this.code = code;\} \newline public int getColorValue() \{ \newline return 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}{Methodenreferenz}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`people.sort(this::compareByAge)`\{\{nl\}\}`int compareByAge(Person p1, Person p2)\{return p1.age - p2.age;`\}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`people.sort(Sorter::compareByAge)`\{\{nl\}\}`{\bf{static}} int compareByAge(Person p1, Person p2)\{return p1.age - p2.age;`\}} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`Sorter sorter = new Sorter();\{\{nl\}\}people.sort(sorter::compareByAge);`} \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Serialisieren}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{OuputStream fos = new \seqsplit{FileOutputStream("serial.bin");} \newline try (ObjectOutputStream stream = new ObjectOutputStream(fos))\{ \newline \seqsplit{stream.writeObject(person);} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{needs Serializable interface \newline serialisiert alle direkt \& inderekt referenz. Obj} \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}{Input/Output}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{try (BufferedInputStream inputBuffer = new {\emph{bis}}(new \seqsplit{FileInputStream(pathSource));} \newline BufferedOutputStream outputB = new {\emph{bos}}(new \seqsplit{FileOutputStream(pathTarget)))} \{ \newline byte{[}{]} byteBuffer = new byte{[}4096{]}; \newline int value = \seqsplit{inputBuffer.read(byteBuffer);} \newline while (value \textgreater{}= 0) \{ \newline outputB.write(byteBuffer, 0, value); \newline value = inputBuffer.read(byteBuffer);\}\} \newline catch (FileNotFoundException e) \{ \newline System.out.println("File not found: "+e); \newline \} catch (IOException e) \{ \newline \seqsplit{System.out.println("reading} Error:"+e);\}} \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}{String Pooling}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{String a = "OO", b = "Prog", c = "OOProg"; \newline //true \newline a == "OO"; c == "OO" + "Prog"; (a+b).equals(c); \newline //false \newline a + b == c;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{String Literals gepoolt. True F{\"a}lle -{}-\textgreater{} es werden keine neuen Objekte erstellt \newline Integer-Pooling -128 bis 127} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.28942 cm} x{2.68758 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Collections}} \tn % Row 0 \SetRowColor{LightBackground} Array & `int{[}{]} intArray = new int{[}3{]};` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} List & `List\textless{}T\textgreater{} al = new ArrayList\textless{}\textgreater{}();` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Set & `Set\textless{}T\textgreater{} hs = new HashSet\textless{}\textgreater{}();` \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Map & `Map\textless{}U,T\textgreater{} hm = new HashMap\textless{}\textgreater{}();` \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`Iterator\textless{}T\textgreater{} it = a.iterator(); while(it.hasNext()) \{..\}`} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{`Collections.sort(Object} o)` & needs Comparable on o \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`for (Map.Entry\textless{}Character, Double\textgreater{} entry: map.entrySet())`} \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{LIST/SET: add(), remove() \newline LIST: get(index) \newline MAP: put(key, value), remove(key),getKey()} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.54924 cm} x{2.19696 cm} x{1.8308 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Interface vs. Abstract Class}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Methoden} & implizit public, abstract & evt abstract, nie private \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{Variablen} & KONSTANTEN (impl. public static final) & normal, Constructor mit super() \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \seqsplit{Vererbung} & `implements a,b` & `extends a` \tn % Row Count 8 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{5.377cm}}{Abstract Method (in abs. cl.): \newline `public abstract void report();` kein Rumpf\{\} \newline in interface: `void report();` \newline I. Methode mit Rumpf: `default void report()\{...\}` \newline `interface I1 extends I2,I3` \newline `class C2 extends C1 implements I1, I2` \newline wenn I1\&I2 nun gleiche Methoden haben (signatur) -{}-\textgreater{} C2 muss ine der beiden überschreiben. Zugriff m{\"o}glich mit \{\{nl\}\}`I1.super.{\emph{methode}}(); I2.super.{\emph{methode}}();`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Unchecked vs Checked Exceptions}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Unchecked}} & {\bf{Checked}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Error & Try/catch oder Methodenkopf \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} RunTime-\{\{nl\}\}Exceptions & m{\"o}gl. catch-Block:\{\{nl\}\}`e.printStackTrace()` \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{-\textgreater{} RunTime, NullPointer, IllegalArgument, IndexOutOfBounds} \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{eigene exception \newline `class myE extends Exception \{ myE() \{\}` \newline `MyE(String message) \{` \newline `super(message);\} \}`} \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}{Junit}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{@Before \newline public void setUp() \{...\} \newline @Test (timeout = 500, expected = Exception.class) \newline public void testGoodName()\{ \newline assertEquals(expected, actual); \newline assertTrue(condition);\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{@After -\textgreater{} tearDown() \newline EdgeCases testen (Grenzwerte, null,...)} \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}{equals}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{@Override \newline public boolean equals(Object obj) \{ \newline if(this == obj) \{return true;\} \newline if (obj == null) \{return false;\} \newline if (getClass() != obj.getClass()) \{ \newline return false;\} \newline Student other = (Student)obj; \newline return regNumber == other.regNumber;\}\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{HashCode überschreiben! \newline ` x.equals(y) → x.hashCode() == y.hashCode() \newline Grund: inkonsistenz bei Hashing. obj wird nicht gefunden, obwohl in Hash-Tabelle, x.contains(y) -{}-\textgreater{} nutzt hashCode() \& equals()} \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}{HashCode()}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{@Override \newline public int hashCode() \{ \newline return 31{\emph{ firstName.hashCode() \newline + 31 }} lastName.hashCode(); \newline \}} \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}{Funktionsschnittstelle}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{@FunctionalInterface \newline interface Comparator\textless{}T\textgreater{} \{ \newline int compare(T first, T second); \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{genau eine Methode -{}-\textgreater{} java.util.function} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.78712 cm} x{2.18988 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{RegEx}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Pattern pattern = Pattern.compile("{\emph{reg}}")} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} vor ? optionaler Teil & ({[}0{]}?{[}0-9{]}|2{[}0-3{]}) \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} ()\{\}*+?|\textbackslash{} als norm text & * \textbackslash{}( \textbackslash{}\textbackslash{} ... \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} Gruppennamen & (?\textless{}NAME\textgreater{}) \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Matcher matcher = pattern.matcher(string);\{\{nl\}\}if (matcher.matches())\{String one = matcher.group("NAME")\}} \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}