\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{codekook} \pdfinfo{ /Title (java-cheat-sheet.pdf) /Creator (Cheatography) /Author (codekook) /Subject (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}{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{java Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{codekook} via \textcolor{DarkBackground}{\uline{cheatography.com/62383/cs/16019/}}} \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}codekook \\ \uline{cheatography.com/codekook} \\ \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 7th June, 2018.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{0.84609 cm} x{4.13091 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{基本概念}} \tn % Row 0 \SetRowColor{LightBackground} JDK & 开发java用 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} JRE & 运行java程序用 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} javac & \seqsplit{java编译器,源代码} -\textgreater{} \seqsplit{字节码(.class文件)} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{bytecode} & \seqsplit{java字节码,包含java虚拟机能识别的指令集} \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} JVM & \seqsplit{java虚拟机,能将java字节码翻译成机器码来执行} \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} jar & \seqsplit{一种压缩文件,将多个}.class文件打包到一起 \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.23579 cm} x{1.87657 cm} x{1.46464 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{数据类型}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{类型}}\{\{bb\}\} & {\bf{长度(位)}}\{\{bb\}\} & {\bf{默认值}}\{\{bb\}\} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} byte & 8 & 0 \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} short & 16 & 0 \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} char & 16 & \textbackslash{}u0000 \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} int & 32 & 0 \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} long & 64 & 0L \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} float & 32 & 0.0F \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} boolean & 未指定 & false \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.55618 cm} x{1.60195 cm} x{1.41887 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{类型转换}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{表达式}}\{\{bb\}\} & {\bf{结果类型}}\{\{bb\}\} & {\bf{结果值}}\{\{bb\}\} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} (1 + 2 + 3) / 4.0 & double & 1.5 \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} 11 * 2.0F & float & 22.0 \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} (int) 11 * 2.0 & double & 22.0 \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} 11 * (int) 2.0 & int & 22 \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} (int)(11 {\emph{ 2.0 }} 2.0) & int & 44 \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} 1 + 2L & long & 3 \tn % Row Count 12 (+ 1) % Row 7 \SetRowColor{white} (int) (1 + 2L) & int & 3 \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{5.377cm}}{隐式转换: \newline int -\textgreater{} long -\textgreater{} float -\textgreater{} double \newline 显式转换:int i = (int) 2.20 \newline 可能会丢失数据精度} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.9154 cm} x{1.55618 cm} x{2.10542 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{命名规范}} \tn % Row 0 \SetRowColor{LightBackground} 类名\{\{nobreak\}\} & FileReader & 首字母大写 \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} 包名 & cn.hchaojie\{\{nl\}\}.blog.article & 全部小写\{\{nl\}\}域名倒写+应用名+模块名 \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} 变量 & fileReader & 首字母小写 \tn % Row Count 7 (+ 1) % Row 3 \SetRowColor{white} 常量 & DAY\_OF\_WEEK\{\{nobreak\}\} & \seqsplit{全部大写,下划线分割} \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{5.377cm}}{\seqsplit{命名要具有可读性、区分性} \newline 采用驼峰形式 \newline 不要使用中文;除了常量,不要用下划线; \newline 不要用无意义的名字} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.23505 cm} p{1.74195 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{java.lang.Math}} \tn % Row 0 \SetRowColor{LightBackground} max(3, 100) & 100 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} min(3, 100) & 3 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} abs(-3) & 3 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} pow(2, 10) & 1024.0 \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} pow(4, 0.5) & 2.0 \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} sqrt(4) & 2.0 \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} log(2) & 1.0 \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{4.03137 cm} x{0.94563 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{字符串格式化}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{System.out.printf(format, arg1, arg2)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{String.format(format, arg1, arg2)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \%d & \seqsplit{integer} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \%s & string \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \%f & double \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} String.format("\%.2f", 20.9988) & 20.99 \tn % Row Count 6 (+ 1) \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.String}} \tn % Row 0 \SetRowColor{LightBackground} length() & 求长度 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} toUpperCase() & 转大写 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} toLowerCase() & 转小写 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} chartAt(0) & 按位置取字符 \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} equals() & 判断相等 \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} startsWith(prefix) & \seqsplit{是否以字符串开头} \tn % Row Count 7 (+ 2) % Row 6 \SetRowColor{LightBackground} endsWith(suffix) & \seqsplit{是否以字符串结尾} \tn % Row Count 9 (+ 2) % Row 7 \SetRowColor{white} split(delimiter) & 以分隔符切分 \tn % Row Count 10 (+ 1) % Row 8 \SetRowColor{LightBackground} String.join() & 以分隔符连接 \tn % Row Count 11 (+ 1) % Row 9 \SetRowColor{white} indexOf() & 子字符串位置 \tn % Row Count 12 (+ 1) % Row 10 \SetRowColor{LightBackground} replace() & 替换子字符串 \tn % Row Count 13 (+ 1) % Row 11 \SetRowColor{white} valueOf() & 数字转字符串 \tn % Row Count 14 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.89586 cm} x{4.08114 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{面向对象}} \tn % Row 0 \SetRowColor{LightBackground} class & {\bf{类}}、对象的一个{\bf{模板}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{instance} & 根据类模板创建的一个个{\bf{实例}} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} object & 一个实例也叫一个{\bf{对象}} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{reference} & {\bf{引用}},给对象取的一个名字,通过引用来操作对象 \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{package} & {\bf{包}}, \seqsplit{是对类的一种组织形式} \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}{类结构}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{public class Employee \{ \newline // \seqsplit{成员变量,也叫域、字段、实例变量} \newline private String idNum; \newline private String name; \newline private int age; \newline \newline // 构造器 \newline public Employee(String id) ... \newline public Employee(String id, String name) \newline \newline // 方法 \newline public String toString() ... \newline public void setName() ... \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}