\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{exo} \pdfinfo{ /Title (comp160.pdf) /Creator (Cheatography) /Author (exo) /Subject (COMP160 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}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \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{COMP160 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{exo} via \textcolor{DarkBackground}{\uline{cheatography.com/19823/cs/2776/}}} \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}exo \\ \uline{cheatography.com/exo} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 7th November, 2014.\\ Updated 7th 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}{Lecture 14 - References}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{* }} Reference types include String, Array and other classes. \newline % Row Count 2 (+ 2) {\bf{* }} {\bf{This}} is a keyword that always refers to the current instance object. \newline % Row Count 4 (+ 2) {\bf{* }} No need for different parameter names.% Row Count 5 (+ 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}{Lecture 16 - Arrays 2}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{*}} Arrays are objects and can hold references to objects. \newline % Row Count 2 (+ 2) {\bf{*}} The state of an array can be changed by a reference to an array (a change to the reference b for example will also change a) \newline % Row Count 5 (+ 3) {\bf{*}} An array of classes can be made just as if you were creating an array of primative values: \newline % Row Count 7 (+ 2) `AClass {[}{]} z = \{new AClass(), new AClass(3.3, "hello", 3), new AClass() \};`% Row Count 9 (+ 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}{Lecture 18 - events}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{ * }} Objects that represent events in the GUI (button clicks, mosue clicks, text input etc.) \newline % Row Count 2 (+ 2) {\bf{ * }} Remember to import java.awt.*; javax.swing.*; java.awt.event.*; \newline % Row Count 4 (+ 2) {\bf{ * }} Event model: (event generator object makes an) Programmer creates components and registers listener for each one. (even object reference sent to) automatically handlered whe user generates an event. (event listener object) programmer creates listener objects% Row Count 10 (+ 6) } \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}{Lecture 21 - Hierarchies, Inheritance}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{ * }} Extends: we can extend a class to create/define a new class (subclass/child) A child class has it own member (datafields \& members) and also non private members of the parent class. \newline % Row Count 4 (+ 4) {\bf{ * }} Hierarchy: A class inherits from its parent, this is how objects get methods like toString that aren't its own \newline % Row Count 7 (+ 3) {\bf{ * }} Super: keyword refering to members of current class/object inherited from the parent class% Row Count 9 (+ 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}{Lecture 24 - Collections, ArrayList, Applets}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{ * }} Enumerated Types: Enumerated types are a way of creating a new type by enumerating (listing) every possible value. \newline % Row Count 3 (+ 3) {\bf{ * }} Generics: where programs are written in terms of "to be specified later". \newline % Row Count 5 (+ 2) {\bf{ * }} Collections: Java has many ways of representing and processing collections of objects, using classes and interfaces in java.util. These are called collection classes, collection framework, or collection API. \newline % Row Count 10 (+ 5) {\bf{ * }} ArrayList: A data structure which can store varying numbers of (references to) objects in a flexible list. import java.util.ArrayList. Doesn't hold primitive types. \newline % Row Count 14 (+ 4) {\bf{ * }} ` ArrayList\textless{}String\textgreater{} a1 = new ArrayList \textless{}String\textgreater{}(); ` \newline % Row Count 16 (+ 2) `a1.add("red"); ` \newline % Row Count 17 (+ 1) `a1.add("green"); ` \newline % Row Count 18 (+ 1) `String a = a1.get(1); ` \newline % Row Count 19 (+ 1) `system.out.println(a); ` \newline % Row Count 20 (+ 1) `a.indexOf("yellow"); `% Row Count 21 (+ 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}{Lecture 15 - Arrays 1}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{* }} An array is a named collection of data of same type and a fixed size. \newline % Row Count 2 (+ 2) {\bf{* }} Index can only be an int (or a char cast to an int) \newline % Row Count 4 (+ 2) {\bf{* }} Hold primitive types, references / handles / pointers to objects \newline % Row Count 6 (+ 2) {\bf{* }} Initialiser lists:` int {[}{]}intAr = \{ 3, 7, 9, 23, 2 \};` \newline % Row Count 8 (+ 2) {\bf{* }} An array always starts at position 0 and goes to length -1 \newline % Row Count 10 (+ 2) {\bf{* }} Multidimensional Arrays - `int {[}{]}{[}{]}a = new int {[}3{]} {[}5{]}; `initializing = `double {[}{]}{[}{]}b = \{ \{1.0, 3.4\}, \{5.6, 8.9\} \};`% Row Count 13 (+ 3) } \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-each}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{for(double {[} {]} row : b ) \{ \newline for(double x : row ) \{ \newline System.out.print( x + " " ); \newline \} \newline System.out.println(); \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}{Listener}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{public void actionPerformed (ActionEvent event) \{ \newline if (event.getSource() == left) \newline label.setText( "Left" ); \newline else \newline label.setText( "Right" ); \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}{Lecture 22 - Visibility, overriding}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{ * }} Packages: A package is a related group of classes. Ones that you don't put into a package get put into the default package. \newline % Row Count 3 (+ 3) {\bf{ * }} Visibility - package visibility is used when no visibility is specified - accessible only to classes in this package. protected visibility - accessible to classes in this package and any class extending this one \newline % Row Count 8 (+ 5) {\bf{ * }} Method overloading: A class can have multiple methods of the same name as long as they have different parameter specifications. \newline % Row Count 11 (+ 3) {\bf{ * }} Method Overriding: methods with same signature (name and parameter specification) exist in both parent and child class. \newline % Row Count 14 (+ 3) {\bf{ * }} When datafields have the same name it is called shadowing% 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}{ArrayList}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`ArrayList()` \newline % Row Count 1 (+ 1) Constructor: creates an initially empty list \newline % Row Count 2 (+ 1) `void add (Object obj)` \newline % Row Count 3 (+ 1) Inserts the specified object to the end of this list \newline % Row Count 5 (+ 2) `void add(int index, Object object)` \newline % Row Count 6 (+ 1) Inserts the specified element at the specified position in this list \newline % Row Count 8 (+ 2) `void clear()` \newline % Row Count 9 (+ 1) removes all of the elements from this list \newline % Row Count 10 (+ 1) `Object remove (int index)` \newline % Row Count 11 (+ 1) Removes the element at the specified position in this list \newline % Row Count 13 (+ 2) `Object get (int index)` \newline % Row Count 14 (+ 1) Returns the element at the specified position in this list \newline % Row Count 16 (+ 2) `int indexOf(Object obj)` \newline % Row Count 17 (+ 1) Returns the index of the first occurrence of the specified element in this list, \newline % Row Count 19 (+ 2) or -1 if this list does not contain the element \newline % Row Count 20 (+ 1) `boolean contains(Object obj)` \newline % Row Count 21 (+ 1) Returns true if this list contains the specified element \newline % Row Count 23 (+ 2) `boolean isEmpty` \newline % Row Count 24 (+ 1) Returns true if this list contains no elements \newline % Row Count 25 (+ 1) `int size()` \newline % Row Count 26 (+ 1) Returns the number of elements in this list% Row Count 27 (+ 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}{Printing out a 2D array}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{for(int row = 0; row \textless{} b.length; row++) \{ \newline for(int col = 0; col \textless{} b{[}row{]}.length; col++)\{ \newline System.out.print( b{[}row{]} {[}col {]} + " "); \newline \} \newline System.out.println(); \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}{Lecture 17 - Graphics components}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{*}} {\bf{Components}}: Objects that are drawn in the GUI (including containers such as frames and panels). \newline % Row Count 3 (+ 3) {\bf{*}} A Container is a type of component that holds and organises other components JPanel holds other components, JFrame holds JPanels in a window \newline % Row Count 6 (+ 3) {\bf{*}} {\bf{Layout}}: (default) FlowLayout: Left to right top to bottom. BorderLayout: 5 positions, north south east west centre. BoxLayout: Single row or column. GridLayout: a grid. Example: \seqsplit{`add(b5.BorderLayout.East)`} \newline % Row Count 11 (+ 5) {\bf{*}}% Row Count 12 (+ 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}{Lecture 20 - Input/Output}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{ * }} A stream is a source or destination of a sequence of data. \newline % Row Count 2 (+ 2) {\bf{ * }} Tokens are text items separated by "white space" \newline % Row Count 4 (+ 2) {\bf{ * }} try..catch: exception handling. when error occurs: do nothing - program will crash, handle the error with try catch. \newline % Row Count 7 (+ 3) {\bf{ * }} Use a scanner to read from a file.% 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}{Lecture 23 - Abstract classes}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{ * }} instanceof (boolean): returns true if an object is an instance of a class i.e. s intanceof Square \newline % Row Count 3 (+ 3) {\bf{ * }} Abstract Classes: They are used when you want to create instances of subclasses but not the abstract parent itself. Abstract class can have its own normal methods. \newline % Row Count 7 (+ 4) {\bf{ * }} Abstract methods must be implemented in child classes, have no body in parent class. \newline % Row Count 9 (+ 2) {\bf{ * }} A child class can only have one parent. Multiple inheritance. \newline % Row Count 11 (+ 2) {\bf{ * }} Java has interfaces to avoid full multiple inheritance. Interfaces may only contain abstract methods and static final data fields. \newline % Row Count 14 (+ 3) {\bf{ * }} Final: a final class may not be extended, a final method may not be over ridden.% Row Count 16 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}