\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{Jianmin Feng (taotao)} \pdfinfo{ /Title (java-building-blocks-oca.pdf) /Creator (Cheatography) /Author (Jianmin Feng (taotao)) /Subject (Java Building Blocks (OCA) 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}{226611} \definecolor{LightBackground}{HTML}{F8FAF7} \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 Building Blocks (OCA) Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Jianmin Feng (taotao)} via \textcolor{DarkBackground}{\uline{cheatography.com/79308/cs/19322/}}} \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}Jianmin Feng (taotao) \\ \uline{cheatography.com/taotao} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 9th May, 2019.\\ 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{2.33919 cm} x{2.63781 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Class structure}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{fields/attributes/properties} & object Status \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{Methods/Behaviors/Functions} & object behavior \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} comments (3 types) & //single line \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} & /* multiple*/ \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} & /**java doc */ \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} classes vs files & one file have one public class \tn % Row Count 9 (+ 2) % Row 6 \SetRowColor{LightBackground} & one file could have more classes \tn % Row Count 11 (+ 2) \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}{Main()}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{JVM hook point to prcess, program entry point} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} public static void main( String{[}{]} args)\{\} & array input \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} public static void main( String... args)\{\} & varargs list \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} args{[}0{]} is the first argument & separated by space \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} javac -cp ",;..;.." MyClass.java & \textgreater{} MyClass.class \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} java -cp "..." MyClass "San Diego" & args{[}0{]}="San \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} java -cp "..." MyClass.class & X MyClass \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} -cp ".; c:\textbackslash{}tmp\textbackslash{}my*" & sub directory not included by * \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{variable arguments: array arguments with variable size. int... num is an array with variable size. Only the last parameter could be varargs.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.18988 cm} x{2.78712 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Creating Objects}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Constructor}} & initialize instance fields \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} name=Class name & public always \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} no return type & not void either \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{new Contructor()} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} default constructor & do nothing constructor \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{{\bf{getter}}} \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{setter}}} \tn % Row Count 9 (+ 1) % Row 7 \SetRowColor{white} {\bf{code block}} & \{ \} \tn % Row Count 10 (+ 1) % Row 8 \SetRowColor{LightBackground} {\bf{initializer block}} & code block out of method block \tn % Row Count 12 (+ 2) % Row 9 \SetRowColor{white} {\bf{initialization order}} & field declaration line \tn % Row Count 14 (+ 2) % Row 10 \SetRowColor{LightBackground} & static initializer block \tn % Row Count 16 (+ 2) % Row 11 \SetRowColor{white} & instance initializer block \tn % Row Count 18 (+ 2) % Row 12 \SetRowColor{LightBackground} & constructor \tn % Row Count 19 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Packages and import}} \tn % Row 0 \SetRowColor{LightBackground} packages=organizer for easy to find/use types(class, interface,enum); & avoid naming conflict;control access to code(package private) \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{{\bf{Syntax}}} \tn % Row Count 5 (+ 1) % Row 2 \SetRowColor{LightBackground} import java.nio.*; & X only subpackage here \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} import \seqsplit{java.nio.files.Paths.*;} & X can not import fields or methos \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} import \seqsplit{java.nio.files.Paths;} & import class \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} import java.nio.files.*; & import classes \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} import java.nio.files.{\emph{.}}; & X \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} import java.lang.*; & OK, redundant \tn % Row Count 16 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Naming conflicts}}} \tn % Row Count 17 (+ 1) % Row 9 \SetRowColor{white} import java.sql.*; import java.util.* & Date is ambiguous \tn % Row Count 19 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Class import precedent *} \tn % Row Count 20 (+ 1) % Row 11 \SetRowColor{white} import java.sql.Date; import java.util.Date; & import collides \tn % Row Count 23 (+ 3) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{use full qualified class name to avoid naming conflicts} \tn % Row Count 25 (+ 2) % Row 13 \SetRowColor{white} {\bf{Create package}} & first line in file \tn % Row Count 26 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{javac pkg/ClassA.java pkg/ClassB.java} \tn % Row Count 27 (+ 1) % Row 15 \SetRowColor{white} java pkg.ClassA.class & X usepkg.ClassA \tn % Row Count 29 (+ 2) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Classpath}}} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Packages and import (cont)}} \tn % Row 17 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{java -cp {\bf{ ".; c:/java/lib/*; ..." }}pkg.ClassA} \tn % Row Count 1 (+ 1) % Row 18 \SetRowColor{white} c:/java/lib/* & jar or subdir by import/pkg statement \tn % Row Count 3 (+ 2) % Row 19 \SetRowColor{LightBackground} c:/java/lib & all .class file in the dir \tn % Row Count 5 (+ 2) % Row 20 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{-cp will ignore environment class\_path variable} \tn % Row Count 6 (+ 1) % Row 21 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{import static}}} \tn % Row Count 7 (+ 1) % Row 22 \SetRowColor{white} import a.b.X.*; & direct access all static member \tn % Row Count 9 (+ 2) % Row 23 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{if access static by ref, need to import the class, instead of static import} \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{java import only make compiling a little longer, not make program larger.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.94103 cm} x{3.03597 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{JAR file}} \tn % Row 0 \SetRowColor{LightBackground} Java Archive & ole format zip file with optional .jar ext \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Content & class files+resource files \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{why jar?} \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} Security \_digital signning & compression \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} package versioning & portable \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} Create jar & jar cf jar-file \seqsplit{imput-file(s)/directories} \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} & \_export \tn % Row Count 12 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{classpath=c:\textbackslash{}lib\textbackslash{}Car.jar} \tn % Row Count 13 (+ 1) % Row 8 \SetRowColor{LightBackground} classpath=c:\textbackslash{}lib* & all jars \tn % Row Count 15 (+ 2) % Row 9 \SetRowColor{white} classpath=c:\textbackslash{}lib & all .class files \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.58726 cm} p{0.4177 cm} x{1.58726 cm} p{0.58478 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{5.377cm}}{\bf\textcolor{white}{Primitive types}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{primitives}} & byte & literal & \seqsplit{default} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} boolean & bit & true & false \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} byte & 1 & 123 & 0 \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} short & 2 & 123 & 0 \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} int & 4 & 123 & 0 \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} long & 8 & 123L & 0 \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} float & 4 & 123.5f & 0.0f \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} double & 8 & 123.5 & 0.0 \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} char & 2 & 'a' & '' \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{4}{x{5.377cm}}{{\bf{Assignment of literal}}} \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} Long max=3123456789 & X & Long \seqsplit{max=3123456789L} & OK \tn % Row Count 13 (+ 2) % Row 11 \SetRowColor{white} byte b =123; & OK & byte b=256; & x \tn % Row Count 14 (+ 1) % Row 12 \SetRowColor{LightBackground} float f=123.5; & X & float f=123.5f; & OK \tn % Row Count 15 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}----} \SetRowColor{LightBackground} \mymulticolumn{4}{x{5.377cm}}{default 123 is int, 123.5 is double \newline default value is for instance variable, local variable has no default, need to be initialized explicitly before use it \newline char is treated as integer number in java, could use ++ -{}- and conversion between int, byte,short.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.75434 cm} p{0.66832 cm} x{1.33664 cm} p{0.4177 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{5.377cm}}{\bf\textcolor{white}{Number format conversion}} \tn % Row 0 \SetRowColor{LightBackground} binary & ob11 & 1,2,4,8 & 3 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} octal & o17 & 1,8,64 & 15 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} decimal & 56 & 1,10,100 & 56 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} hexadecimal & ox1f & 1,16,256 & 31 \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{4}{x{5.377cm}}{System.out.println(ox1f) will display in decimal 31.} \tn % Row Count 6 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{4}{x{5.377cm}}{\_ used for all number formats} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{4}{x{5.377cm}}{\_123 is a valid identifier} \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}----} \SetRowColor{LightBackground} \mymulticolumn{4}{x{5.377cm}}{underscore for easy read, \_ could not anywhere but 4 locations: beginning, end,before or after decimal point. \_123\_.\_45\_} \tn \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Reference types}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Reference type reference an object, hold the memory location of the object it reference to.} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{A reference also called a pointer} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{The default value for a instance reference type is null} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{local reference variable must be initialized to a null or object} \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.23579 cm} x{1.41887 cm} x{1.92234 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Reference vs primitives}} \tn % Row 0 \SetRowColor{LightBackground} & References & Primitives \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} data & obj memory addr & value \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} default value & null & 0,false,0.0f,0.0, NUL \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{5.377cm}}{java strong typed, can not assign 1 to boolean; \newline null is an object, can print it ("null"), cannot call method from it - NullPointException.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Object vs Primitive}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{primitive has only one piece of state information, absolutely no behavior} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{Object bundled with one or multiple states and/or behavior} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Object on heap, ref by ref type} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.9862 cm} x{1.9908 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Stack vs Heap}} \tn % Row 0 \SetRowColor{LightBackground} Stack & Heap \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} small & large \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Ref variables & objects \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} live-span within scope & live or ready for gc \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} primitive value/member address & object state \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.79172 cm} x{3.18528 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Declare and initializing variables}} \tn % Row 0 \SetRowColor{LightBackground} variable name & Starts lower letters | \$ | \_ \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} & my contains numbers \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} package, keyword & lower letters \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} Class & Initcap \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} Constant & all caps \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} int a,string s; & X \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.18988 cm} x{2.78712 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Default initialization of variables}} \tn % Row 0 \SetRowColor{LightBackground} local variable & must be explicitly initialized \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} instance/class variables & false, 0,0.0,'\textbackslash{}u0000'(NUL),null \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} boolean & false \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} byte,short,int,long & 0 \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} float duble & 0.0 \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} char & '\textbackslash{}u0000'(NUL) \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} reference type & null \tn % Row Count 10 (+ 1) \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}{Variable scope}} \tn % Row 0 \SetRowColor{LightBackground} block scope & multiple levels \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} methods scope & life time =\textgreater{} from declaration to end of block \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} instance scope & life time =\textgreater{}from declaration to gc of obj \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} class static scope & lifetime=\textgreater{} from declaration to end of program \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{a variable declared in switch,if,for loop can not used outside of them} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Order of element in a class}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{package declaration} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{import statement} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{class declaration} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{field declaration} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{methods declaration} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Garbage collection}} \tn % Row 0 \SetRowColor{LightBackground} automatically handled & remove the referenced obj from heap \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} could manual call System.gc() -{}-\textgreater{}finalize() & just a hit, may not get run, but if run, never run twice \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} Obj available for gc: unreferenced & set to null; change ref; all ref out of scope \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} {\bf{Object }} & {\bf{References}} \tn % Row Count 9 (+ 1) % Row 4 \SetRowColor{LightBackground} on heap & on stack \tn % Row Count 10 (+ 1) % Row 5 \SetRowColor{white} diff in size & same size (mem addr) \tn % Row Count 11 (+ 1) % Row 6 \SetRowColor{LightBackground} accessed by ref & by variable name \tn % Row Count 12 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{{\bf{Memory Leak}}} \tn % Row Count 13 (+ 1) % Row 8 \SetRowColor{LightBackground} lazy code:leave unused obj hanging & create variable never used \tn % Row Count 15 (+ 2) \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}{Benefit of Java}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Object oriented} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \seqsplit{encapsulation} & getter, setter + private \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{platform independent} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} robust & auto mem mgn, gc \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} simple & no pointer, no operator overloading \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} secure & run within JVM ( sandbox) \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}