\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{Kunanon S (son9912)} \pdfinfo{ /Title (java-oop-concept.pdf) /Creator (Cheatography) /Author (Kunanon S (son9912)) /Subject (Java + OOP concept 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}{004D40} \definecolor{LightBackground}{HTML}{F7F9F9} \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 + OOP concept Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Kunanon S (son9912)} via \textcolor{DarkBackground}{\uline{cheatography.com/43384/cs/12920/}}} \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}Kunanon S (son9912) \\ \uline{cheatography.com/son9912} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 25th September, 2017.\\ Updated 29th September, 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}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Hello World!}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Start your Java day with Hello World program \newline % Row Count 1 (+ 1) `public class HelloWorld \{` \newline % Row Count 2 (+ 1) ` public static void main(String{[}{]} args) \{` \newline % Row Count 3 (+ 1) ` // Prints "Hello, World" to the terminal window.` \newline % Row Count 5 (+ 2) ` \seqsplit{System.out.println("Hello}, World");` \newline % Row Count 6 (+ 1) ` \}` \newline % Row Count 7 (+ 1) `\}` \newline % Row Count 8 (+ 1) When you want to run the program, choose this class as main class.% Row Count 10 (+ 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}{Run your code}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Compile from single class}} up HelloWorld class \newline % Row Count 1 (+ 1) \{\{fa-terminal\}\} `javac HelloWorld.java` \newline % Row Count 2 (+ 1) \{\{fa-terminal\}\} `java HelloWorld` \newline % Row Count 3 (+ 1) {\bf{Compile from multiple classes}} and choose main class \newline % Row Count 5 (+ 2) \{\{fa-terminal\}\} `javac *.java` \newline % Row Count 6 (+ 1) \{\{fa-terminal\}\} `java HelloWorld // HelloWorld is your preferred main class`% Row Count 8 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.73232 cm} x{1.51041 cm} x{2.33427 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Variables}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Type}} & {\bf{Default Value}} & {\bf{Memory Allocation}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} byte & 0 & 8 bits \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} short & 0 & 16 bits \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} int & 0 & 32 bits \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} long & 0L & 64 bits \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} float & 0.0F & 32 bits (decimal) \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \seqsplit{double} & 0.00D & 64 bits (decimal) \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \seqsplit{boolean} & False & varies on impliment \tn % Row Count 10 (+ 2) % Row 8 \SetRowColor{LightBackground} \seqsplit{String} & NULL & depends on character count \tn % Row Count 12 (+ 2) % Row 9 \SetRowColor{white} char & \textbackslash{}u0000 & 16 bits (unicode) \tn % Row Count 13 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.34379 cm} x{3.63321 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operators}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Operand}} & {\bf{What they do}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} = & Assign value \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} == & Check value/address similarity \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \textgreater{} & More than \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} \textgreater{}= & More than or equals \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} \textgreater{}\textgreater{}\textgreater{} & Move bit to the right by \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} ++ & Increment by 1 \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{inverse of these operands still working the same. \newline For example : != is not equal} \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}{Defining variable}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Defining new variable attributes}} \newline % Row Count 1 (+ 1) `int x = 12;` \newline % Row Count 2 (+ 1) `int x; // will be defined as 0` \newline % Row Count 3 (+ 1) {\bf{Define by creating new instances}} \newline % Row Count 4 (+ 1) `String x = new String;` \newline % Row Count 5 (+ 1) {\bf{Type Casting (decreasing bit use)}} \newline % Row Count 6 (+ 1) Expanding data types will not require type casting. Narrowing does. \newline % Row Count 8 (+ 2) `double x = 10; // Expanding data types` \newline % Row Count 9 (+ 1) `int y = (int) 10.222222; // Narrowing data types`% Row Count 10 (+ 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}{Conditions}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{If statement}} \newline % Row Count 1 (+ 1) \{\{fa-chevron-circle-right\}\} `if (statement) \{\}` \newline % Row Count 2 (+ 1) {\bf{If - else statement}} \newline % Row Count 3 (+ 1) \{\{fa-chevron-circle-right\}\} `if (statement) \{\} else\{\}`% Row Count 5 (+ 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}{Switch}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{switch (num) \{ \newline case 1: doSomething(); \newline break; \newline default: doThis(); \newline break; \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}{Loop}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-chevron-circle-right\}\} `for (int i: someArray) \{\}` \newline % Row Count 2 (+ 2) \{\{fa-chevron-circle-right\}\} `while (something) \{\}` \newline % Row Count 4 (+ 2) \{\{fa-chevron-circle-right\}\} `do \{something\} while (true)`% Row Count 6 (+ 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}{Prime number function}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{if (n \textless{} 2) \{ return false; \} \newline for (int i=2; i \textless{}= n/i; i++) \newline if (n\%i == 0) return false; \newline return true;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-comment-o\}\} returns a boolean} \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 Pool - Optimizations}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{String pool is created to make the same value string use the same address. By doing that, it will save memory and time for compiler to do stuff \newline % Row Count 3 (+ 3) {\bf{Basic testing}} \newline % Row Count 4 (+ 1) `String s1 = "Hello World";` \newline % Row Count 5 (+ 1) `String s2 = "Hello World;` \newline % Row Count 6 (+ 1) {\bf{Check it using "=="}} \newline % Row Count 7 (+ 1) \{\{fa-chevron-circle-right\}\} `System.out.println(s1 == s2);` \newline % Row Count 9 (+ 2) \{\{fa-terminal\}\} `True` \newline % Row Count 10 (+ 1) {\emph{"==" will check its address}} \newline % Row Count 11 (+ 1) {\bf{Allocate a new address using `new`}} \newline % Row Count 12 (+ 1) `String s1 = "Hello World";` \newline % Row Count 13 (+ 1) `String s2 = new String;` \newline % Row Count 14 (+ 1) `s2 = "Hello World";` \newline % Row Count 15 (+ 1) `System.out.println(s1 == s2);` \newline % Row Count 16 (+ 1) \{\{fa-terminal\}\} `False` \newline % Row Count 17 (+ 1) {\bf{Allocate new address by changing its value}} \newline % Row Count 18 (+ 1) `String s1 = "Hello World";` \newline % Row Count 19 (+ 1) `String s2 = "Hello World";` \newline % Row Count 20 (+ 1) `s2 = "Hello Thailand";` \newline % Row Count 21 (+ 1) `System.out.println(s1 == s2);` \newline % Row Count 22 (+ 1) \{\{fa-terminal\}\} `False`% Row Count 23 (+ 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}{Naming Grammars}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Naming should be regulated for easier recogition from others \newline % Row Count 2 (+ 2) Use Upper Camel Case for {\bf{classes}}: `VelocityResponseWriter` \newline % Row Count 4 (+ 2) Use Lower Case for {\bf{packages}}: `com.company.project.ui` \newline % Row Count 6 (+ 2) Use Lower Camel Case for {\bf{variables}}: `studentName` \newline % Row Count 8 (+ 2) Use Upper Case for {\bf{constants}}: `MAX\_PARAMETER\_COUNT = 100` \newline % Row Count 10 (+ 2) Use Camel Case for {\bf{enum class}} names \newline % Row Count 11 (+ 1) Use Upper Case for {\bf{enum values}} \newline % Row Count 12 (+ 1) Don't use '\_' anywhere except constants and enum values (which are constants).% Row Count 14 (+ 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}{Receiving user input}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{There is normally 2 ways to receive user keyboard input \newline % Row Count 2 (+ 2) {\bf{1. java.util.Scanner}} \newline % Row Count 3 (+ 1) `Scanner x = new Scanner(System.in);` \newline % Row Count 4 (+ 1) `String inputString = x.next(); // for String type input` \newline % Row Count 6 (+ 2) `int inputInteger = x.nextInt(); // for Integer type input` \newline % Row Count 8 (+ 2) {\bf{2. String{[}{]} args}} {\emph{from public static void main()}} \newline % Row Count 10 (+ 2) {\emph{NOTE: args is already in a array. It can receives unlimited amount of arguments.}} \newline % Row Count 12 (+ 2) `String inputString = args{[}0{]}; // for String type input` \newline % Row Count 14 (+ 2) `Int inputString = (int) args{[}0{]}; // for Integer type input`% Row Count 16 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{To use Scanner, importing Scanner library is required : `import java.Object.Scanner` \newline \newline All types of input can be received. (not just String or int)} \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}{Access Modifier}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/son9912_1506383646_download.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- Java uses `\textless{}default\textgreater{}` modifier when not assigning any. \newline - `public` modifier allows same class access \newline - {\emph{Works in inherited class}} means itself and the classes that inherit from it.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.54287 cm} x{3.43413 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Attribute modifier}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Attribute Type}} & {\bf{Access Grants}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Private & Allows only in class where variable belongs \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Public & Allows any class to have this attribute \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Static & Attribute that dependent on class (not object) \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} Final & Defined once. Does not allow any change/inheritance \tn % Row Count 10 (+ 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}{Methods}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Methods are fucking easy, dud. \newline % Row Count 1 (+ 1) \{\{fa-chevron-circle-right\}\} `\textless{}mod\textgreater{} \textless{}return\textgreater{} mthdName (\textless{}args\textgreater{}) \{ \}` \newline % Row Count 3 (+ 2) {\bf{Example:}} \newline % Row Count 4 (+ 1) \{\{fa-chevron-circle-right\}\} `public double getAge () \{` \newline % Row Count 6 (+ 2) `~~return someDouble;` \newline % Row Count 7 (+ 1) `\}`% Row Count 8 (+ 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}{Constructor}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Constructors allow you to create an object template. It consists of {\bf{complete procedures}}. \newline % Row Count 2 (+ 2) {\bf{Create a blank constructor}} to allow its extension classes to inherit this {\emph{super}} constructor. \newline % Row Count 4 (+ 2) \{\{fa-chevron-circle-right\}\} `\textless{}modifier\textgreater{} Person () \{\}` \newline % Row Count 6 (+ 2) {\emph{But will be created automatically by not writing any constructor }} \newline % Row Count 8 (+ 2) {\bf{Create an argument-defined constructor}} \newline % Row Count 9 (+ 1) \{\{fa-chevron-circle-right\}\} `\textless{}modifier\textgreater{} Person (String name) \{` \newline % Row Count 11 (+ 2) `~~this.name = name;` \newline % Row Count 12 (+ 1) `\}`% 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}{Abstract Class}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Abstract is a type of class but it {\bf{can consist of incomplete methods}}. \newline % Row Count 2 (+ 2) {\bf{Create new abstract}} \newline % Row Count 3 (+ 1) \{\{fa-chevron-circle-right\}\} `\textless{}access\_modifier\textgreater{} abstract class HelloWorld () \{\}`% Row Count 5 (+ 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}{Interface}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Interface is different from constructor. It {\bf{consists of incomplete assignments}} \newline % Row Count 2 (+ 2) Interface allows you to {\emph{make sure}} that any inherited class can do the following methods. (It's like a contract to agree that this thing must be able to do this shit.) The method is then completed in the class that implements it. \newline % Row Count 7 (+ 5) {\bf{Creating a new interface}} \newline % Row Count 8 (+ 1) `interface Bicycle \{` \newline % Row Count 9 (+ 1) `~~void speedUp (int increment);` \newline % Row Count 10 (+ 1) `\}` \newline % Row Count 11 (+ 1) -{}-{}-{}- \newline % Row Count 12 (+ 1) `class fuckBike implements Bicycle \{` \newline % Row Count 13 (+ 1) `~~...` \newline % Row Count 14 (+ 1) `~~void speedUp (int increment) \{` \newline % Row Count 15 (+ 1) `~~~~speed += increment;` \newline % Row Count 16 (+ 1) `~~\}` \newline % Row Count 17 (+ 1) `~~...` \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}{Encapsulation}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Encapsulation allows individual methods to have different access modifier. \newline % Row Count 2 (+ 2) Creating {\emph{setters}} and {\emph{getters}} is one way to use encapsulation \newline % Row Count 4 (+ 2) For example \newline % Row Count 5 (+ 1) `private void setTime(int hour, int minuite, int second)\{` \newline % Row Count 7 (+ 2) `this.hour = hour;` \newline % Row Count 8 (+ 1) `this.minuite = minuite;` \newline % Row Count 9 (+ 1) `this.second = second;` \newline % Row Count 10 (+ 1) `\}`% Row Count 11 (+ 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}{Inheritance}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Inheritance helps class to import the superclass' method. \newline % Row Count 2 (+ 2) {\bf{Importing superclass}} \newline % Row Count 3 (+ 1) \{\{fa-chevron-circle-right\}\} `class HelloWorld extends Object \{\}` \newline % Row Count 5 (+ 2) Normally, the class that does not inherit any class will inherit {\emph{Object}} class.* \newline % Row Count 7 (+ 2) Class can {\bf{only inherit 1 class/abstract}} \newline % Row Count 8 (+ 1) {\bf{Importing Interface}} \newline % Row Count 9 (+ 1) \{\{fa-chevron-circle-right\}\} `class HelloWorld inherits InterfaceThing \{\}` \newline % Row Count 11 (+ 2) Class can {\bf{inherit unlimited amount of interface}}% Row Count 13 (+ 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}{Overload}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{We use overload when you want different input to work differently, but remains the same name. \newline % Row Count 2 (+ 2) {\bf{Example of Overload}} \newline % Row Count 3 (+ 1) `public printer(String x)\{\}` \newline % Row Count 4 (+ 1) `public printer(String x, String y)\{\}` \newline % Row Count 5 (+ 1) If the input is 2 string, it will go to the second method instead of first one. \newline % Row Count 7 (+ 2) But you cannot overload by using the same input type sequence. For example \newline % Row Count 9 (+ 2) `public printer(String x)\{\}` \newline % Row Count 10 (+ 1) `public printer(String x, String y)\{\} // conflict` \newline % Row Count 12 (+ 2) `public printer(String y, String x)\{\} // conflict` \newline % Row Count 14 (+ 2) Java will not allow this to be run, because it cannot determine the value.% Row Count 16 (+ 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}{Override}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{When you have inherit some of the class from parents, but you want to do something different. In override feature, all the subclass/class object will use the newer method. \newline % Row Count 4 (+ 4) To make sure JDK knows what you are doing, type `@Override` in front of the public name. If the override is unsuccessful, JDK will returns error. \newline % Row Count 7 (+ 3) Example of overriden helloWorld() method : \newline % Row Count 8 (+ 1) Class Student \newline % Row Count 9 (+ 1) `public void helloWorld()\{` \newline % Row Count 10 (+ 1) \seqsplit{`System.out.println("Hello");`} \newline % Row Count 11 (+ 1) `\}` \newline % Row Count 12 (+ 1) Class GradStudent extends Student \newline % Row Count 13 (+ 1) `@Override` \newline % Row Count 14 (+ 1) `public void helloWorld()\{` \newline % Row Count 15 (+ 1) \seqsplit{`System.out.println("Hello} World");` \newline % Row Count 16 (+ 1) `\}` \newline % Row Count 17 (+ 1) {\bf{Rules of Overridden methods}} \newline % Row Count 18 (+ 1) 1. Access modifier priority can only be narrower or same as superclass \newline % Row Count 20 (+ 2) 2. There is the same name method in superclass / libraries% Row Count 22 (+ 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}{java.io.PrintStream}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Print with new line}} \newline % Row Count 1 (+ 1) \{\{fa-chevron-circle-right\}\} \seqsplit{`System.out.println("Hello} World");` \newline % Row Count 3 (+ 2) {\bf{Print}} \newline % Row Count 4 (+ 1) \{\{fa-chevron-circle-right\}\} `System.out.print("Hello World");`% Row Count 6 (+ 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}{java.util.Scanner}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Create a Scanner object}} \newline % Row Count 1 (+ 1) \{\{fa-chevron-circle-right\}\} `Scanner sc = new Scanner(System.in);` \newline % Row Count 3 (+ 2) {\bf{Accept input}} \newline % Row Count 4 (+ 1) \{\{fa-chevron-circle-right\}\} `double d = sc.nextDouble()`% Row Count 6 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.38896 cm} x{2.58804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{java.lang.Math}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Methods}} & {\bf{Usage}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `Math.max(\textless{}value1\textgreater{}, \textless{}value2\textgreater{})` & Return maximum value \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} `Math.min(\textless{}value1\textgreater{}, \textless{}value2\textgreater{})` & Return minimum value \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} `Math.abs(\textless{}value\textgreater{})` & Return unsigned value \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} `Math.pow(\textless{}number\textgreater{}, \textless{}exponent\textgreater{}` & Return value of a number\textasciicircum{}exponent\textasciicircum{} \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} `Math.sqrt(\textless{}value\textgreater{})` & Return square root of a value \tn % Row Count 11 (+ 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}{java.lang.String}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Find the length}} -\textgreater{} int \newline % Row Count 1 (+ 1) \{\{fa-chevron-circle-right\}\} `msg.length()` \newline % Row Count 2 (+ 1) {\bf{To lower/uppercase}} -\textgreater{} String \newline % Row Count 3 (+ 1) \{\{fa-chevron-circle-right\}\} `msg.toLowerCase()` \newline % Row Count 4 (+ 1) \{\{fa-chevron-circle-right\}\} `msg.toUpperCase()` \newline % Row Count 5 (+ 1) {\bf{Replace a string}} -\textgreater{} String \newline % Row Count 6 (+ 1) \{\{fa-chevron-circle-right\}\} `msg.replaceAll(String a, String b)` \newline % Row Count 8 (+ 2) {\bf{Split string between delimeter}} -\textgreater{} array \newline % Row Count 9 (+ 1) \{\{fa-chevron-circle-right\}\} `msg.split(String delimeter)` \newline % Row Count 11 (+ 2) {\bf{Start/end with}} -\textgreater{} boolean \newline % Row Count 12 (+ 1) \{\{fa-chevron-circle-right\}\} `msg.startsWith(String pre)` \newline % Row Count 14 (+ 2) \{\{fa-chevron-circle-right\}\} `msg.endsWith(String post)` \newline % Row Count 16 (+ 2) {\bf{String format}} -\textgreater{} String \newline % Row Count 17 (+ 1) \{\{fa-chevron-circle-right\}\} `String.format(String format, Object... args)`% Row Count 19 (+ 2) } \tn \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}{java.lang.String}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Methods}} & {\bf{Description}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} charAt(int index) & Returns the char value at the specified index \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} compareTo(String otherString) & Compare 2 strings lexicographically \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} concat(String str) & Concatenate specified string \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} endsWith(String suffix) & Test if the string ends with specified suffix \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} equals(String andObject) & Test if strings values are the same \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} toCharArray() & Convert string to character array \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} toLowerCase() & Convert string to lowercase \tn % Row Count 17 (+ 2) % Row 8 \SetRowColor{LightBackground} toUpperCase() & Convert string to uppercase \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} toString() & Convert things to string \tn % Row Count 21 (+ 2) % Row 10 \SetRowColor{LightBackground} valueOf(\textless{}value\textgreater{}) & Return the representation of argument \tn % Row Count 23 (+ 2) % Row 11 \SetRowColor{white} length() & Return length of the string \tn % Row Count 25 (+ 2) % Row 12 \SetRowColor{LightBackground} replaceAll(String a, String b) & Replace string a to string b \tn % Row Count 27 (+ 2) % Row 13 \SetRowColor{white} split(String delimeter) & Split string between delimeter \tn % Row Count 29 (+ 2) % Row 14 \SetRowColor{LightBackground} startsWith(String prefix) & Test if string starts with specified prefix \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.23965 cm} x{2.73735 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{java.lang.String (cont)}} \tn % Row 15 \SetRowColor{LightBackground} format(String format, Object arg) & Format strings to the format given \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{There is many more in Java documents : \seqsplit{https://docs.oracle.com/javase/9/docs/api/java/lang/String.html}} \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}{java.util.Collection (CollectionAPI)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Provides ways to keep variables and access it faster \newline % Row Count 2 (+ 2) {\bf{Ways to keep data}} \newline % Row Count 3 (+ 1) 1. Set - Care about duplicity, not queue (eg. HashSet) \newline % Row Count 5 (+ 2) 2. List - Care about queue, not duplicity (eg. LinkedList) \newline % Row Count 7 (+ 2) 3. Map - Care about both queue and key duplicity (eg.HashMap) \newline % Row Count 9 (+ 2) {\bf{Methods that will be included}} \newline % Row Count 10 (+ 1) `boolean add(Object element);` \newline % Row Count 11 (+ 1) `boolean remove(Object element);` \newline % Row Count 12 (+ 1) `int size();` \newline % Row Count 13 (+ 1) `boolean isEmpty();` \newline % Row Count 14 (+ 1) `boolean contains(Object element);` \newline % Row Count 15 (+ 1) `Iterator Iterator();`% Row Count 16 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.73735 cm} x{2.23965 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{HashList - CollectionAPI}} \tn % Row 0 \SetRowColor{LightBackground} Method & Usability \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} void add (int index, Object element) & Add value to list \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} Object remove(int index) & Remove item \#index from list \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} Object get(int index) & Retrieve item \#index from list \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} void set(int index, Object element) & Set data to correspond \#index \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} int indexOf(Object element) & Find the \#index from element \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{ListIterator listIterator()} \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{It also includes all CollectionAPI methods \newline \newline {\bf{Create new HashList by using}} \newline `List x = new HashList();`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{1.9908 cm} x{2.9862 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{HashMap - CollectionAPI}} \tn % Row 0 \SetRowColor{LightBackground} Method & Usability \tn % Row Count 1 (+ 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}{Collections}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Create List of 1, 2, 3 on-the-fly}} \newline % Row Count 1 (+ 1) \{\{fa-chevron-circle-right\}\} `Arrays.asList(1, 2, 3)` \newline % Row Count 3 (+ 2) {\bf{Convert primitive array to Stream}} \newline % Row Count 4 (+ 1) \{\{fa-chevron-circle-right\}\} \seqsplit{`Arrays.stream(primitiveArray)`} \newline % Row Count 6 (+ 2) {\bf{Convert ArrayList to Stream}} \newline % Row Count 7 (+ 1) \{\{fa-chevron-circle-right\}\} `arrayList.stream()`% Row Count 8 (+ 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}{LinkedList - CollectionAPI}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Create empty LinkedList of Integer}} \newline % Row Count 1 (+ 1) \{\{fa-chevron-circle-right\}\} `LinkedList myList = new LinkedList\textless{}Integer\textgreater{}t()` \newline % Row Count 3 (+ 2) {\bf{Create LinkedList with values in it}} \newline % Row Count 4 (+ 1) \{\{fa-chevron-circle-right\}\} `new LinkedList\textless{}\textgreater{}(Arrays.asList(1, 2, 3)))` \newline % Row Count 6 (+ 2) {\bf{Add an object to LinkedList}} \newline % Row Count 7 (+ 1) \{\{fa-chevron-circle-right\}\} `myList.add(50)`% Row Count 8 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}