# Java Notes: Table of Contents

Java Notes. These Java programming notes are written to fill in missing or weak topics in textbooks that I've taught from. Many pages are useful for reference, but not as an ordered tutorial. Some pages are still rough drafts, but I'm slowly working on fixing them. notes-java-2007-04-25.zip [2.4 MB]. Java Basics. I've started writing a more coherent tutorial called Java Basics. In addition to lessons, there is also commentary which explains why things are done the way they are. JavaBasics-2007-04-25.zip [0.4 MB]. | Copyleft - Java Notes is copyrighted by the very permissive MIT License, except as otherwise noted (eg, some GPL'ed images). Copyright - Java Basics, which has more work put into it, has a traditional copyright, but allows free educational use. Public Domain - All source code in the examples in both Java Notes and Java Basics is placed in the public domain so you can use them. Enjoy, Fred Swartz

### Background Preface Programs Files and Directories CLASSPATH Directories and Files Packages - Importing Packages - Defining Using other packages NoSuchMethodError main Garbage Collection Links My Favorite Books ### Java Tools Tools Java Development Kit Programming IDEs NetBeans NetBeans GUI Projects NetBeans Code Snippets Text Editors TextPad Editor Ant Checkers ### Deployment Applications, Applets, etc. Intro GUI - Swing vs. AWT Strengths Weaknesses History of Java Java Virtual Machine Java vs. C Applications - example Compiling a Java program Applets ### Principles and practices Style Coding guidelines - summary Cohesion Design By Contract Process - Iterative Development Process Iterative/Incremental Dev Start with working pgm Errors and debugging Fail Early, Fail Often Error Processing Debugging Output OO Design Frameworks Complexity Complexity is your enemy Complexity Measurement Method Cyclomatic Complexity Function Point Analysis FPA Introduction ### Summaries Data summaries Summary - Data Summary - Expressions Summary - String Summary - Character Summary - StringBuilder etc Summary - Arrays 1 Summary - Arrays 2 GUI summaries Summary - GUI Components Summary - GUI Containers Summary - GUI Layouts 1 Summary - GUI Layouts 2 Summary - Graphics Misc summaries Summary - Intro Programming Summary - Basic Elements Summary - Control Flow Summary - Packages Summary - Scanner Summary - Math class Summary - Random numbers DOS Commands ### Introductory Example Programs Overview of Intro Programs Do nothing! First Program - Do Nothing Output only Console: Hello Earthling Dialog: Hello Earthling Input - Output Example: Console: To your leader Example: Dialog: To your leader Example: Console: Capitalize Example: Dialog: Capitalize Ex: Console: Kilometers to Miles Ex: Dialog: Kilometers to Miles Ex: Dialog: Km to Miles - Format Loop (Input, Calculate, Output) Example: Console: Adding Machine Example: Console: Max, min, avg Example: Dialog: Adding Machine Example: Dialog: Longest Word Example: Dialog: Bad Words Programming Problems Body Mass Index - Dialog Count Words - Dialog Methods Ex: Dialog: Km to Miles - Method Ex: Dialog: Input Range Method Try...Catch Ex: Dialog: Km to Miles - Try-Catch ### Example GUI Programs Components Example - ToUppercase Example - CombineName Example - Body Mass Index Example - Sleepy Face Example - Calculator Example - Simple editor Example - Roman numerals Graphics Example - Drawing a Face Example - BullseyeDemo Example - Roll Dice Example - ColorDisplay Example - Circles Animation Example - Bouncing Ball TextClock Example - Text Clock Example - Text Clock 2 Example - Extend Clock Example - Buffered Clock Mouse Example - MouseTest Example - DragDemo Example - Card Demo Example - PaintDemo Example - Raise Games Example - FreeCell Example - Slide Puzzle Example - Five-in-a-row Example - Sudoku v3 Collections Example - WordFrequency | ### Language Basics Comments Identifier Names import Final ### Control Flow If if Statement - Overview Else not Required Braces are your friend 'if' Statement - Indentation 'if' Statement - if inside if 'if' Statement - 'else if' style switch switch Statement - Overview switch Example - Random Insults Loops Loops - Introduction While Statement For Statement "Foreach" Statement Ex: String reverse Assertions Assertions Exceptions Exceptions Exception Usage Exceptions - More Throwing Exceptions Methods See Java Basics Methods - Example Static methods Example methods and loops ### Classes See Java Basics Overview OOP Terminology Constructors Constructors Constructors - super Constructors - super example Exercise: Constructor Chaining Interfaces Interfaces Example - Handyperson Reflection / Introspection Class class Enums Enums ### IO File IO java.io.File File I/O - Text Files Sys Independent Newline BufferedReader/Writer File Filters javax.swing.filechooser.FileFilter java.io.FileFilter Examples Example - FileTest Example - ReadWords Example - NanoEdit Example - Recursive List Console (System.in / System.out) Console I/O Console-Dialog Comparison Dialog (JOptionPane) Dialog Box Input Loop Internet Read page from Web server Formatted Output Formatted Output Properties and Preferences Preferences Properties System Properties JDBC Database Engines ### Algorithms Big-Oh Notation Big-Oh Notation Comparing Comparators Copying Deep vs Shallow Copies clone() Searching Search/Sort Overview Collections Class Linear search Binary search Recursive binary search Sorting Selection Sort Bubble Sorts Sorting Arrays Random numbers Random numbers - intro Random numbers - API Shuffling Math Math and java.util.Random ### Other Time Various time classes javax.swing.Timer java.util.Calendar Sound Beep Audio Memory OutOfMemoryError | ### Data Basic Types Numbers Integers Floating-point Characters Unicode Summary - Character Boolean Autoboxing Variables Variables Local/Instance/Class Shadow variables are evil Shadowing this Expressions Expressions Precedence Assignment Extended Assigment Ops Comparison Comparison Operators ==, .equals(), and compareTo() Bit operations Bitwise operations Numbers java.math.BigInteger Example - Factorial Strings String Overview String Comparison Summary pages Summary - String Summary - StringBuilder Conversion Converting Numbers to String Converting Anything to String Converting Strings to Numbers Regular_expressions Regular Expressions String Regex Methods Basic regex summary Pattern and Matcher Regex Language Regex Examples Full regex summary StringTokenizer java.util.StringTokenizer Tokenizing Delimiters TokenizeExpr.java String Examples Example - Display Extension Example - Change Extension Example - Count occurences Example - Count vowels Example - Palindrome test Example - Replace word Example - SortWords3.java Example - Array to String Example - String to "tokens" Arrays Arrays Array library methods Examples Example: Reverse an array Example: Maximum of array Example: Average of array Examples: Sorting Arrays - 2-dimensional Arrays of arrays Arrays - more Collections - Generic Java Data Structures Collections Overview Collection Interface Lists ArrayList<E> Example - Alphabetize Vector<E> Simple Linked Lists Deques ArrayDeque<E> Sets Set<E> interface Maps Map<K, V> interface Map iteration Example - WordFrequency Iterators Iterators Other Class or Interface Generics Alternative Data Structures Exercises Exercise - Unique Components Exercise - State Capitals | ### GUI See Java Basics Basics GUI Tips GUI Structural Patterns Summaries Summary - Basic Components Summary - Containers Summary - Layouts Events and Listeners Events - Introduction Listeners Inner-class Listeners Anonymous Listeners Top-level Listeners Action, AbstractAction Components Components Introduction to Components Where to declare components Intro to components Buttons Text JLabel Buttons JButton JButton Appearance Buttons with Icons Textfield JTextField Textarea JTextArea Example - JTextArea Radio buttons Radio Buttons Checkboxes JCheckBox Sliders Sliders Change Listener Combobox JComboBox (uneditable) Menus JMenuBar, JMenu, ... Containers Containers Windows JFrame - Window JFrame Close Box Window Size and Position Content Panes Dialogs Dialogs JOptionPane - Simple JOptionPane.showConfirmDialog JFileChooser FileFilter Panels JPanel - Container JTabbedPane Layouts Layouts FlowLayout BorderLayout GridLayout BoxLayout and Boxes BoxLayout spacing BoxLayout alignment GridBagLayout Example: GridBagLayout Null Layout Alternate Layout Managers GUI Program Structure Big Blob Structure UI-Model Structure UI-Model Communication Misc Cursor GUI Alternatives ### GUI - Appearance Fonts Font class FontMetrics Centering Text Example - FontDemo Borders Borders Border Example Look and Feel Look and Feel ### GUI - Low level Graphics Summary: Graphics drawing Drawing Screen Coordinates Graphics class Who calls paintComponent Color Polygons Summary: Drawing component JPanel - Drawing Area JPanel - Drawing Area 2 JPanel - Example Images - BufferedImage Images - ImageIcon Graphics2D Graphics2D Antialiasing Mouse The Mouse MouseListener MouseMotionListener Mouse Listeners Mouse Buttons, Modifier Keys Keyboard Keyboard Example - KeyDemo

Acknowledgements.