\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{sally sung} \pdfinfo{ /Title (java-programming.pdf) /Creator (Cheatography) /Author (sally sung) /Subject (Java Programming 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}{22A318} \definecolor{LightBackground}{HTML}{F1F9F0} \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 Programming Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{sally sung} via \textcolor{DarkBackground}{\uline{cheatography.com/216190/cs/47965/}}} \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}sally sung \\ \uline{cheatography.com/sally-sung} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 16th April, 2026.\\ Updated 16th April, 2026.\\ 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}{Inheritance}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{class Animal \{ \newline % Row Count 1 (+ 1) void eat() \{ \newline % Row Count 2 (+ 1) \seqsplit{System.out.println("eat");} \newline % Row Count 3 (+ 1) \} \newline % Row Count 4 (+ 1) \} \newline % Row Count 5 (+ 1) class Dog extends Animal \{ \newline % Row Count 6 (+ 1) void bark() \{ \newline % Row Count 7 (+ 1) \seqsplit{System.out.println("bark");} \newline % Row Count 8 (+ 1) \} \newline % Row Count 9 (+ 1) \}% 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}{Interface}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{interface Animal \{ \newline % Row Count 1 (+ 1) void sound(); \newline % Row Count 2 (+ 1) \} \newline % Row Count 3 (+ 1) class Dog implements Animal \{ \newline % Row Count 4 (+ 1) public void sound() \{ \newline % Row Count 5 (+ 1) \seqsplit{System.out.println("bark");} \newline % Row Count 6 (+ 1) \} \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}{Abstract}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{abstract class Animal \{ \newline % Row Count 1 (+ 1) abstract void sound(); \newline % Row Count 2 (+ 1) void eat() \{ \newline % Row Count 3 (+ 1) \seqsplit{System.out.println("eat");} \newline % Row Count 4 (+ 1) \} \newline % Row Count 5 (+ 1) \} \newline % Row Count 6 (+ 1) class Dog extends Animal \{ \newline % Row Count 7 (+ 1) void sound() \{ \newline % Row Count 8 (+ 1) \seqsplit{System.out.println("bark");} \newline % Row Count 9 (+ 1) \} \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}{Exception}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{public class UsedCarException extends Exception \{ \newline % Row Count 1 (+ 1) private static final long serialVersionUID = 1L; \newline % Row Count 3 (+ 2) public UsedCarException(String message) \{ \newline % Row Count 4 (+ 1) super(message); \newline % Row Count 5 (+ 1) \} \newline % Row Count 6 (+ 1) \}% Row Count 7 (+ 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}{Working with Files}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{public class UsedCarApp \{ \newline % Row Count 1 (+ 1) public static void writeToFile(ArrayList\textless{}UsedCar\textgreater{} cars, String fileName) \{ \newline % Row Count 3 (+ 2) try \{ \newline % Row Count 4 (+ 1) PrintWriter writer = new PrintWriter(new FileWriter(fileName)); \newline % Row Count 6 (+ 2) for (UsedCar car : cars) \{ \newline % Row Count 7 (+ 1) \seqsplit{writer.println(car.toString());} \newline % Row Count 8 (+ 1) \} \newline % Row Count 9 (+ 1) writer.close(); \newline % Row Count 10 (+ 1) System.out.println("\textbackslash{}nSuccessfully saved valid cars to file."); \newline % Row Count 12 (+ 2) \} catch (IOException e) \{ \newline % Row Count 13 (+ 1) \seqsplit{System.out.println("Error} writing to file: " + e.getMessage()); \newline % Row Count 15 (+ 2) \} \newline % Row Count 16 (+ 1) \} \newline % Row Count 17 (+ 1) public static void readFromFile(String fileName) \{ \newline % Row Count 19 (+ 2) try \{ \newline % Row Count 20 (+ 1) Scanner fileInput = new Scanner(new File(fileName)); \newline % Row Count 22 (+ 2) System.out.println("\textbackslash{}nVIN and Price from file:"); \newline % Row Count 24 (+ 2) while \seqsplit{(fileInput.hasNextLine())} \{ \newline % Row Count 25 (+ 1) String line = fileInput.nextLine(); \newline % Row Count 27 (+ 2) String{[}{]} parts = line.split(","); \newline % Row Count 28 (+ 1) if (parts.length == 4) \{ \newline % Row Count 29 (+ 1) String vin = parts{[}0{]}; \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Working with Files (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ String price = parts{[}3{]}; \newline % Row Count 1 (+ 1) System.out.println("VIN: " + vin + " | Price: " + price); \newline % Row Count 3 (+ 2) \} \newline % Row Count 4 (+ 1) \} \newline % Row Count 5 (+ 1) fileInput.close(); \newline % Row Count 6 (+ 1) \} catch (FileNotFoundException e) \{ \newline % Row Count 7 (+ 1) \seqsplit{System.out.println("Error} reading file: " + e.getMessage()); \newline % Row Count 9 (+ 2) \} \newline % Row Count 10 (+ 1) \} \newline % Row Count 11 (+ 1) public static void main(String{[}{]} args) \{ \newline % Row Count 12 (+ 1) Scanner input = new Scanner(System.in); \newline % Row Count 13 (+ 1) ArrayList\textless{}UsedCar\textgreater{} validCars = new ArrayList\textless{}\textgreater{}(); \newline % Row Count 15 (+ 2) final int NUMBER\_OF\_CARS = 3; \newline % Row Count 16 (+ 1) for (int i = 0; i \textless{} NUMBER\_OF\_CARS; i++) \{ \newline % Row Count 18 (+ 2) try \{ \newline % Row Count 19 (+ 1) System.out.println("\textbackslash{}nEnter information for car \#" + (i + 1)); \newline % Row Count 21 (+ 2) System.out.print("Enter VIN (4 digits): "); \newline % Row Count 23 (+ 2) String vin = input.nextLine(); \newline % Row Count 24 (+ 1) System.out.print("Enter make: "); \newline % Row Count 25 (+ 1) String make = input.nextLine(); \newline % Row Count 26 (+ 1) System.out.print("Enter year: "); \newline % Row Count 27 (+ 1) int year = \seqsplit{Integer.parseInt(input.nextLine());} \newline % Row Count 29 (+ 2) System.out.print("Enter price: "); \newline % Row Count 31 (+ 2) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Working with Files (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ double price = \seqsplit{Double.parseDouble(input.nextLine());} \newline % Row Count 2 (+ 2) UsedCar car = new UsedCar(vin, make, year, price); \newline % Row Count 4 (+ 2) validCars.add(car); \newline % Row Count 5 (+ 1) System.out.println("Car created successfully."); \newline % Row Count 7 (+ 2) \} catch (UsedCarException e) \{ \newline % Row Count 8 (+ 1) \seqsplit{System.out.println("UsedCarException:} " + e.getMessage()); \newline % Row Count 10 (+ 2) \} catch (Exception e) \{ \newline % Row Count 11 (+ 1) \seqsplit{System.out.println("Exception:} Invalid input. " + e.getMessage()); \newline % Row Count 13 (+ 2) \} \newline % Row Count 14 (+ 1) \} \newline % Row Count 15 (+ 1) String fileName = "UsedCars.txt"; \newline % Row Count 16 (+ 1) writeToFile(validCars, fileName); \newline % Row Count 17 (+ 1) readFromFile(fileName); \newline % Row Count 18 (+ 1) input.close(); \newline % Row Count 19 (+ 1) \} \newline % Row Count 20 (+ 1) \}% 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}{JDBC}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{module-info.java \textgreater{} \newline % Row Count 1 (+ 1) module FinalTermPractice \{ \newline % Row Count 2 (+ 1) requires java.sql; \newline % Row Count 3 (+ 1) \}% Row Count 4 (+ 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}{JDBC}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{import java.sql.*; \newline % Row Count 1 (+ 1) public class EmployeeDBApp \{ \newline % Row Count 2 (+ 1) private static final String DB\_FILE = "EmployeeDB.accdb"; \newline % Row Count 4 (+ 2) private static final String DB\_URL = "jdbc:ucanaccess://" + DB\_FILE; \newline % Row Count 6 (+ 2) public static Connection getConnection() throws SQLException, ClassNotFoundException \{ \newline % Row Count 8 (+ 2) \seqsplit{Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");} \newline % Row Count 10 (+ 2) return \seqsplit{DriverManager.getConnection(DB\_URL);} \newline % Row Count 12 (+ 2) \} \newline % Row Count 13 (+ 1) public static void insertEmployee(Scanner input) \{ \newline % Row Count 15 (+ 2) Connection conn = null; \newline % Row Count 16 (+ 1) Statement statement = null; \newline % Row Count 17 (+ 1) try \{ \newline % Row Count 18 (+ 1) conn = getConnection(); \newline % Row Count 19 (+ 1) statement = conn.createStatement(); \newline % Row Count 20 (+ 1) System.out.print("Enter employee name: "); \newline % Row Count 22 (+ 2) String name = input.nextLine(); \newline % Row Count 23 (+ 1) System.out.print("Enter employee salary: "); \newline % Row Count 25 (+ 2) double salary = \seqsplit{Double.parseDouble(input.nextLine());} \newline % Row Count 27 (+ 2) String insertQ = "INSERT INTO Employee (Name, Salary) VALUES ('" \newline % Row Count 29 (+ 2) + name + "', " + salary + ")"; \newline % Row Count 31 (+ 2) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{JDBC (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ \seqsplit{statement.executeUpdate(insertQ);} \newline % Row Count 1 (+ 1) \seqsplit{System.out.println("Employee} inserted successfully."); \newline % Row Count 3 (+ 2) \} catch (ClassNotFoundException ex) \{ \newline % Row Count 4 (+ 1) \seqsplit{System.out.println("Driver} error: " + ex.getMessage()); \newline % Row Count 6 (+ 2) \} catch (SQLException ex) \{ \newline % Row Count 7 (+ 1) \seqsplit{System.out.println("Database} error: " + ex.getMessage()); \newline % Row Count 9 (+ 2) \} catch (Exception ex) \{ \newline % Row Count 10 (+ 1) \seqsplit{System.out.println("Input} error: " + ex.getMessage()); \newline % Row Count 12 (+ 2) \} finally \{ \newline % Row Count 13 (+ 1) try \{ \newline % Row Count 14 (+ 1) if (statement != null) \newline % Row Count 15 (+ 1) statement.close(); \newline % Row Count 16 (+ 1) if (conn != null) \newline % Row Count 17 (+ 1) conn.close(); \newline % Row Count 18 (+ 1) \} catch (SQLException ex) \{ \newline % Row Count 19 (+ 1) \seqsplit{System.out.println(ex.getMessage());} \newline % Row Count 21 (+ 2) \} \newline % Row Count 22 (+ 1) \} \newline % Row Count 23 (+ 1) \} \newline % Row Count 24 (+ 1) public static void \seqsplit{updateEmployeeSalary(Scanner} input) \{ \newline % Row Count 26 (+ 2) Connection conn = null; \newline % Row Count 27 (+ 1) Statement statement = null; \newline % Row Count 28 (+ 1) try \{ \newline % Row Count 29 (+ 1) conn = getConnection(); \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{JDBC (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ statement = conn.createStatement(); \newline % Row Count 1 (+ 1) System.out.print("Enter employee name to update: "); \newline % Row Count 3 (+ 2) String name = input.nextLine(); \newline % Row Count 4 (+ 1) System.out.print("Enter new salary: "); \newline % Row Count 6 (+ 2) double salary = \seqsplit{Double.parseDouble(input.nextLine());} \newline % Row Count 8 (+ 2) String updateQ = "UPDATE Employee SET Salary = " + salary \newline % Row Count 10 (+ 2) + " WHERE Name = '" + name + "'"; \newline % Row Count 12 (+ 2) int rows = \seqsplit{statement.executeUpdate(updateQ);} \newline % Row Count 14 (+ 2) if (rows \textgreater{} 0) \{ \newline % Row Count 15 (+ 1) \seqsplit{System.out.println("Salary} updated successfully."); \newline % Row Count 17 (+ 2) \} else \{ \newline % Row Count 18 (+ 1) \seqsplit{System.out.println("Employee} not found."); \newline % Row Count 20 (+ 2) \} \newline % Row Count 21 (+ 1) \} catch (ClassNotFoundException ex) \{ \newline % Row Count 22 (+ 1) \seqsplit{System.out.println("Driver} error: " + ex.getMessage()); \newline % Row Count 24 (+ 2) \} catch (SQLException ex) \{ \newline % Row Count 25 (+ 1) \seqsplit{System.out.println("Database} error: " + ex.getMessage()); \newline % Row Count 27 (+ 2) \} catch (Exception ex) \{ \newline % Row Count 28 (+ 1) \seqsplit{System.out.println("Input} error: " + ex.getMessage()); \newline % Row Count 30 (+ 2) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{JDBC (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ \} finally \{ \newline % Row Count 1 (+ 1) try \{ \newline % Row Count 2 (+ 1) if (statement != null) \newline % Row Count 3 (+ 1) statement.close(); \newline % Row Count 4 (+ 1) if (conn != null) \newline % Row Count 5 (+ 1) conn.close(); \newline % Row Count 6 (+ 1) \} catch (SQLException ex) \{ \newline % Row Count 7 (+ 1) \seqsplit{System.out.println(ex.getMessage());} \newline % Row Count 9 (+ 2) \} \newline % Row Count 10 (+ 1) \} \newline % Row Count 11 (+ 1) \} \newline % Row Count 12 (+ 1) public static void deleteEmployee(Scanner input) \{ \newline % Row Count 14 (+ 2) Connection conn = null; \newline % Row Count 15 (+ 1) Statement statement = null; \newline % Row Count 16 (+ 1) try \{ \newline % Row Count 17 (+ 1) conn = getConnection(); \newline % Row Count 18 (+ 1) statement = conn.createStatement(); \newline % Row Count 19 (+ 1) System.out.print("Enter employee name to delete: "); \newline % Row Count 21 (+ 2) String name = input.nextLine(); \newline % Row Count 22 (+ 1) String deleteQ = "DELETE FROM Employee WHERE Name = '" + name + "'"; \newline % Row Count 24 (+ 2) int rows = \seqsplit{statement.executeUpdate(deleteQ);} \newline % Row Count 26 (+ 2) if (rows \textgreater{} 0) \{ \newline % Row Count 27 (+ 1) \seqsplit{System.out.println("Employee} deleted successfully."); \newline % Row Count 29 (+ 2) \} else \{ \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{JDBC (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ \seqsplit{System.out.println("Employee} not found."); \newline % Row Count 2 (+ 2) \} \newline % Row Count 3 (+ 1) \} catch (ClassNotFoundException ex) \{ \newline % Row Count 4 (+ 1) \seqsplit{System.out.println("Driver} error: " + ex.getMessage()); \newline % Row Count 6 (+ 2) \} catch (SQLException ex) \{ \newline % Row Count 7 (+ 1) \seqsplit{System.out.println("Database} error: " + ex.getMessage()); \newline % Row Count 9 (+ 2) \} catch (Exception ex) \{ \newline % Row Count 10 (+ 1) \seqsplit{System.out.println("Input} error: " + ex.getMessage()); \newline % Row Count 12 (+ 2) \} finally \{ \newline % Row Count 13 (+ 1) try \{ \newline % Row Count 14 (+ 1) if (statement != null) \newline % Row Count 15 (+ 1) statement.close(); \newline % Row Count 16 (+ 1) if (conn != null) \newline % Row Count 17 (+ 1) conn.close(); \newline % Row Count 18 (+ 1) \} catch (SQLException ex) \{ \newline % Row Count 19 (+ 1) \seqsplit{System.out.println(ex.getMessage());} \newline % Row Count 21 (+ 2) \} \newline % Row Count 22 (+ 1) \} \newline % Row Count 23 (+ 1) \} \newline % Row Count 24 (+ 1) public static void displayAllEmployees() \{ \newline % Row Count 25 (+ 1) Connection conn = null; \newline % Row Count 26 (+ 1) Statement statement = null; \newline % Row Count 27 (+ 1) ResultSet rs = null; \newline % Row Count 28 (+ 1) ArrayList\textless{}Employee\textgreater{} employees = new ArrayList\textless{}Employee\textgreater{}(); \newline % Row Count 30 (+ 2) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{JDBC (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ try \{ \newline % Row Count 1 (+ 1) conn = getConnection(); \newline % Row Count 2 (+ 1) statement = conn.createStatement(); \newline % Row Count 3 (+ 1) String query = "SELECT * FROM Employee"; \newline % Row Count 5 (+ 2) rs = \seqsplit{statement.executeQuery(query);} \newline % Row Count 6 (+ 1) while (rs.next()) \{ \newline % Row Count 7 (+ 1) int id = rs.getInt("ID"); \newline % Row Count 8 (+ 1) String name = rs.getString("Name"); \newline % Row Count 10 (+ 2) double salary = rs.getDouble("Salary"); \newline % Row Count 12 (+ 2) Employee emp = new Employee(id, name, salary); \newline % Row Count 14 (+ 2) employees.add(emp); \newline % Row Count 15 (+ 1) \} \newline % Row Count 16 (+ 1) if (employees.size() == 0) \{ \newline % Row Count 17 (+ 1) System.out.println("No employee records found."); \newline % Row Count 19 (+ 2) \} else \{ \newline % Row Count 20 (+ 1) System.out.println("\textbackslash{}n-{}-{}- All Employees -{}-{}-"); \newline % Row Count 22 (+ 2) for (Employee emp : employees) \{ \newline % Row Count 23 (+ 1) System.out.println("ID: " + emp.getId() \newline % Row Count 25 (+ 2) + ", Name: " + emp.getName() \newline % Row Count 27 (+ 2) + ", Salary: " + emp.getSalary()); \newline % Row Count 29 (+ 2) \} \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{JDBC (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ \} \newline % Row Count 1 (+ 1) \} catch (ClassNotFoundException ex) \{ \newline % Row Count 2 (+ 1) \seqsplit{System.out.println("Driver} error: " + ex.getMessage()); \newline % Row Count 4 (+ 2) \} catch (SQLException ex) \{ \newline % Row Count 5 (+ 1) \seqsplit{System.out.println("Database} error: " + ex.getMessage()); \newline % Row Count 7 (+ 2) \} finally \{ \newline % Row Count 8 (+ 1) try \{ \newline % Row Count 9 (+ 1) if (rs != null) \newline % Row Count 10 (+ 1) rs.close(); \newline % Row Count 11 (+ 1) if (statement != null) \newline % Row Count 12 (+ 1) statement.close(); \newline % Row Count 13 (+ 1) if (conn != null) \newline % Row Count 14 (+ 1) conn.close(); \newline % Row Count 15 (+ 1) \} catch (SQLException ex) \{ \newline % Row Count 16 (+ 1) \seqsplit{System.out.println(ex.getMessage());} \newline % Row Count 18 (+ 2) \} \newline % Row Count 19 (+ 1) \} \newline % Row Count 20 (+ 1) \} \newline % Row Count 21 (+ 1) public static void showMenu() \{ \newline % Row Count 22 (+ 1) System.out.println("\textbackslash{}n===== Employee Database Menu ====="); \newline % Row Count 24 (+ 2) System.out.println("1. Insert Employee"); \newline % Row Count 25 (+ 1) System.out.println("2. Update Employee Salary"); \newline % Row Count 27 (+ 2) System.out.println("3. Delete Employee"); \newline % Row Count 28 (+ 1) System.out.println("4. Display All Employees"); \newline % Row Count 30 (+ 2) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{JDBC (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ System.out.println("5. Exit"); \newline % Row Count 1 (+ 1) System.out.print("Enter your choice: "); \newline % Row Count 2 (+ 1) \} \newline % Row Count 3 (+ 1) public static void main(String{[}{]} args) \{ \newline % Row Count 4 (+ 1) Scanner input = new Scanner(System.in); \newline % Row Count 5 (+ 1) int choice = 0; \newline % Row Count 6 (+ 1) do \{ \newline % Row Count 7 (+ 1) showMenu(); \newline % Row Count 8 (+ 1) try \{ \newline % Row Count 9 (+ 1) choice = \seqsplit{Integer.parseInt(input.nextLine());} \newline % Row Count 11 (+ 2) switch (choice) \{ \newline % Row Count 12 (+ 1) case 1: \newline % Row Count 13 (+ 1) insertEmployee(input); \newline % Row Count 14 (+ 1) break; \newline % Row Count 15 (+ 1) case 2: \newline % Row Count 16 (+ 1) \seqsplit{updateEmployeeSalary(input);} \newline % Row Count 18 (+ 2) break; \newline % Row Count 19 (+ 1) case 3: \newline % Row Count 20 (+ 1) deleteEmployee(input); \newline % Row Count 21 (+ 1) break; \newline % Row Count 22 (+ 1) case 4: \newline % Row Count 23 (+ 1) displayAllEmployees(); \newline % Row Count 24 (+ 1) break; \newline % Row Count 25 (+ 1) case 5: \newline % Row Count 26 (+ 1) \seqsplit{System.out.println("Program} terminated."); \newline % Row Count 28 (+ 2) break; \newline % Row Count 29 (+ 1) default: \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{JDBC (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ \seqsplit{System.out.println("Invalid} choice. Please enter a number from 1 to 5."); \newline % Row Count 2 (+ 2) \} \newline % Row Count 3 (+ 1) \} catch (Exception ex) \{ \newline % Row Count 4 (+ 1) \seqsplit{System.out.println("Invalid} input. Please enter a valid number."); \newline % Row Count 6 (+ 2) \} \newline % Row Count 7 (+ 1) \} while (choice != 5); \newline % Row Count 8 (+ 1) input.close(); \newline % Row Count 9 (+ 1) \} \newline % Row Count 10 (+ 1) \}% Row Count 11 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}