\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{gamer88} \pdfinfo{ /Title (final-exam-java.pdf) /Creator (Cheatography) /Author (gamer88) /Subject (Final Exam 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{Final Exam Java Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{gamer88} via \textcolor{DarkBackground}{\uline{cheatography.com/191809/cs/39857/}}} \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}gamer88 \\ \uline{cheatography.com/gamer88} \\ \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 12th August, 2023.\\ 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*}{4} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{123}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{What is the advantage of using try-with-resource over normal try-and-catch when creating AutoClosable resources? \newline % Row Count 3 (+ 3) a) Try-with-resource will automatically close the resources upon leaving the scope of try. \newline % Row Count 5 (+ 2) b) Multiple lines of resources separated by ";" can be placed inside of one try-with-resource. \newline % Row Count 7 (+ 2) c) There is no need to create a finally block with null check and close statement for each resource. \newline % Row Count 10 (+ 3) d) All are advantages (correct)% Row Count 11 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{1234}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Match the servlet method to its operation? \newline % Row Count 1 (+ 1) \_\_4\_\_ doDelete \newline % Row Count 2 (+ 1) \_\_2\_\_ doPost \newline % Row Count 3 (+ 1) \_\_3\_\_ doPut \newline % Row Count 4 (+ 1) \_\_1\_\_ doGet \newline % Row Count 5 (+ 1) 1. Read, provide data to user, for example, return a html page or a DB SELECT. \newline % Row Count 7 (+ 2) 2. Create, process user provided data, for example, add row to a table. \newline % Row Count 9 (+ 2) 3. Update, depending on the user data update information on the server, for example, DB UDPATE. \newline % Row Count 11 (+ 2) 4. Delete, remove data from the server or DB.% Row Count 12 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{123321}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{What is false about XHMTL? \newline % Row Count 1 (+ 1) a) Elements must always be properly nested in XHTML. \newline % Row Count 3 (+ 2) b) \textless{}!DOCTYPE\textgreater{} is mandatory in XHTML. \newline % Row Count 4 (+ 1) c) Attribute minimization is forbidden in XHTML. \newline % Row Count 5 (+ 1) d) All others are false. (correct)% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{123312321}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{There are no differences between the two blocks of code below. They will both produce the same result. (Note: Assume the code is correct, anything omitted is irrelevant to the question.) \newline % Row Count 4 (+ 4) // Code Block 1 \newline % Row Count 5 (+ 1) Properties dbProps = new Properties(); \newline % Row Count 6 (+ 1) dbProps.put("user", username); \newline % Row Count 7 (+ 1) dbProps.put("password", password); \newline % Row Count 8 (+ 1) Connection connection = \seqsplit{DriverManager.getConnection(jdbcUrl}, dbProps); \newline % Row Count 10 (+ 2) // Code Block 2 \newline % Row Count 11 (+ 1) Connection connection = \seqsplit{DriverManager.getConnection(jdbcUrl}, username, password); \newline % Row Count 13 (+ 2) a) True (correct) \newline % Row Count 14 (+ 1) b) False% Row Count 15 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{413}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{When a JSP page is called, it will be compiled (by the JSP engine internally) into a Java servlet. \newline % Row Count 2 (+ 2) a) True (correct) \newline % Row Count 3 (+ 1) b) False% Row Count 4 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{123}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{All JPQL queries can be written in HQL as Hibernate is 100\% compliant with JPA. However, not all HQL queries can be written in JPQL as Hibernate has extra features that JPA does not support. \newline % Row Count 4 (+ 4) a) True (correct) \newline % Row Count 5 (+ 1) b) False% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{123}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{All JPQL queries can be written in HQL as Hibernate is 100\% compliant with JPA. However, not all HQL queries can be written in JPQL as Hibernate has extra features that JPA does not support. \newline % Row Count 4 (+ 4) a) True (correct) \newline % Row Count 5 (+ 1) b) False% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{1233}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Match the method to its description? If you are not sure, look up the documentation online. \newline % Row Count 2 (+ 2) \_\_2\_\_ Can execute any query that does not return any ResultSet like INSERT and UPDATE. It returns the number of updated rows. \newline % Row Count 5 (+ 3) \_\_1\_\_ Can execute any type of query, like SELECT and INSERT. If return is true, the executed query has a ResultSet, otherwise, just a row count of updated rows or nothing. \newline % Row Count 9 (+ 4) \_\_3\_\_ Can execute any query which return a set of rows, like SELECT. It returns a ResultSet which contains the data and can never be null. \newline % Row Count 12 (+ 3) \seqsplit{1. PreparedStatement::execute} \newline % Row Count 13 (+ 1) \seqsplit{2. PreparedStatement::executeUpdate} \newline % Row Count 14 (+ 1) \seqsplit{3. PreparedStatement::executeQuery}% Row Count 15 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{4531}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Which scope is used on managed bean which is to be created/instantiated for every client session? \newline % Row Count 2 (+ 2) a) @SessionScoped (correct) \newline % Row Count 3 (+ 1) b) @ViewScoped \newline % Row Count 4 (+ 1) c) @ApplicationScoped \newline % Row Count 5 (+ 1) d) @RequestScoped% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{123312}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Assume we have the code below, which annotation prevents "foo" from being null? \newline % Row Count 2 (+ 2) @Entity(name = "A") \newline % Row Count 3 (+ 1) @Table(name = "TABLE\_A") \newline % Row Count 4 (+ 1) public class APojo \{ \newline % Row Count 5 (+ 1) @Id \newline % Row Count 6 (+ 1) \seqsplit{ @GeneratedValue(strategy} = GenerationType.IDENTITY) \newline % Row Count 8 (+ 2) protected int id; \newline % Row Count 9 (+ 1) @Column(name = "COL\_1") \newline % Row Count 10 (+ 1) protected String foo; \newline % Row Count 11 (+ 1) //JPA likes default constructor \newline % Row Count 12 (+ 1) public APojo() \{ \newline % Row Count 13 (+ 1) \} \newline % Row Count 14 (+ 1) \} \newline % Row Count 15 (+ 1) a) @Basic \newline % Row Count 16 (+ 1) b) @Basic(optional=false) (CORRECT) \newline % Row Count 17 (+ 1) c) @Basic(optional=true) \newline % Row Count 18 (+ 1) d) No need because by default nothing can be null.% Row Count 19 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{132}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{In which of the following JSF phases has HTTP request parameters placed in a hash table and passed to all objects in the component tree. \newline % Row Count 3 (+ 3) a) Restore View \newline % Row Count 4 (+ 1) b) Update Model Values \newline % Row Count 5 (+ 1) c) Apply Request Values (correct) \newline % Row Count 6 (+ 1) d) Process Validations% Row Count 7 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{4314}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{What does the annotation @Transient on a field or property of an entity mean? \newline % Row Count 2 (+ 2) a) It specifies that the field or property is to be mapped to a column on a table in the database. \newline % Row Count 4 (+ 2) b) It specifies that the field or property is not persistent. (correct) \newline % Row Count 6 (+ 2) c) All answers are wrong. \newline % Row Count 7 (+ 1) d) It specifies that the field or property can be null.% Row Count 9 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{123213}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{What is true about the @Table annotation? \newline % Row Count 1 (+ 1) a) All answers are true.(correct) \newline % Row Count 2 (+ 1) b) If no @Table annotation is used, then default values are used, that is, the entity class MyEntity will be mapped to the myentity table in the database if no @Table annotation is provided. \newline % Row Count 6 (+ 4) c) It allows you to define the name, schema, and catalog of the table for your entity mapping.% Row Count 8 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}