Books & Videos

Table of Contents

  1. Chapter 1 Dive in A Quick Dip: Breaking the Surface

    1. The Way Java Works

    2. What you’ll do in Java

    3. A very brief history of Java

    4. Code structure in Java

    5. Anatomy of a class

    6. Writing a class with a main

    7. Looping and looping and...

    8. Conditional branching

    9. Coding a Serious Business Application

    10. Phrase-O-Matic

  2. Chapter 2 Classes and Objects: A Trip to Objectville

    1. Chair Wars: (or How Objects Can Change Your Life)

    2. Making your first object

    3. Making and testing Movie objects

    4. Quick! Get out of main!

    5. Running the Guessing Game

  3. Chapter 3 Primitives and References: Know Your Variables

    1. Declaring a variable

    2. “I’d like a double mocha, no, make it an int.”

    3. You really don’t want to spill that...

    4. Back away from that keyword!

    5. This table reserved

    6. Controlling your Dog object

    7. An object reference is just another variable value

    8. An array is like a tray of cups

    9. Arrays are objects too

    10. Make an array of Dogs

    11. Control your Dog (with a reference variable)

    12. A Dog example

  4. Chapter 4 Methods Use Instance Variables: How Objects Behave

    1. Remember: a class describes what an object knows and what an object does

    2. The size affects the bark

    3. You can send things to a method

    4. You can get things back from a method

    5. You can send more than one thing to a method

    6. Java is pass-by-value. That means pass-by-copy

    7. Cool things you can do with parameters and return types

    8. Encapsulation

    9. Encapsulating the GoodDog class

    10. How do objects in an array behave?

    11. Declaring and initializing instance variables

    12. The difference between instance and local variables

    13. Comparing variables (primitives or references)

  5. Chapter 5 Writing a Program: Extra-Strength Methods

    1. Let’s build a Battleship-style game: “Sink a Dot Com”

    2. First, a high-level design

    3. The “Simple Dot Com Game” a gentler introduction

    4. Developing a Class

    5. The checkYourself() method

    6. The game’s main() method

    7. More about for loops

    8. Trips through a loop

    9. The enhanced for loop

    10. Casting primitives

  6. Chapter 6 Get to Know the Java API: Using the Java Library

    1. In our last chapter, we left you with the cliff-hanger. A bug

    2. So what happened?

    3. How do we fix it ?

    4. Option one is too clunky

    5. Option two is a little better, but still pretty clunky

    6. Wake up and smell the library

    7. Some things you can do with ArrayList

    8. Comparing ArrayList to a regular array

    9. Comparing ArrayList to a regular array

    10. Let’s fix the DotCom code

    11. New and improved DotCom class

    12. Let’s build the REAL game: “Sink a Dot Com”

    13. What needs to change?

    14. Who does what in the DotComBust game (and when)

    15. Prep code for the real DotComBust class

    16. The final version of the DotCom class

    17. Super Powerful Boolean Expressions

    18. Using the Library (the Java API)

    19. How to play with the API

  7. Chapter 7 Inheritance and Polymorphism: Better Living in Objectville

    1. Chair Wars Revisited...

    2. Let’s design the inheritance tree for an Animal simulation program

    3. Using inheritance to avoid duplicating code in subclasses

    4. Do all animals eat the same way?

    5. Looking for more inheritance opportunities

    6. Designing an Inheritance Tree

    7. When designing with inheritance, are you using or abusing?

    8. Keeping the contract: rules for overriding

    9. Overloading a method

  8. Chapter 8 Interfaces and Abstract Classes: Serious Polymorphism

    1. Did we forget about something when we designed this?

    2. Interface to the rescue!

    3. Making and Implementing the Pet interface

  9. Chapter 9 Constructors and Garbage Collection: Life and Death of an Object

    1. The Stack and the Heap: where things live

    2. Methods are stacked

    3. What about local variables that are objects?

    4. If local variables live on the stack, where do instance variables live?

    5. The miracle of object creation

    6. Construct a Duck

    7. Initializing the state of a new Duck

    8. Using the constructor to initialize important Duck stateNot to imply that not all Duck state is not unimportant.

    9. Make it easy to make a Duck

    10. Doesn’t the compiler always make a no-arg constructor for you? No!

    11. Nanoreview: four things to remember about constructors

    12. Wait a minute... we never DID talk about superclasses and inheritance and how that all fits in with constructors

    13. The role of superclass constructors in an object’s life

    14. Making a Hippo means making the Animal and Object parts too...

    15. How do you invoke a superclass constructor?

    16. Can the child exist before the parents?

    17. Superclass constructors with arguments

    18. Invoking one overloaded constructor from another

    19. Now we know how an object is born, but how long does an object live?

    20. What about reference variables?

  10. Chapter 10 Numbers and Statics: Numbers Matter

    1. MATH methods: as close as you’ll ever get to a global method

    2. The difference between regular (non-static) and static methods

    3. What it means to have a class with static methods

    4. Static methods can’t use non-static (instance) variables!

    5. Static methods can’t use non-static methods, either!

    6. Static variable: value is the same for ALL instances of the class

    7. Initializing a static variable

    8. static final variables are constants

    9. final isn’t just for static variables...

    10. Math methods

    11. Wrapping a primitive

    12. Before Java 5.0, YOU had to do the work...

    13. Autoboxing: blurring the line between primitive and object

    14. Autoboxing works almost everywhere

    15. But wait! There’s more! Wrappers have static utility methods too!

    16. And now in reverse... turning a primitive number into a String

    17. Number formatting

    18. Formatting deconstructed...

    19. The percent (%) says, “insert argument here” (and format it using these instructions)

    20. The format String uses its own little language syntax

    21. The format specifier

    22. The only required specifier is for TYPE

    23. What happens if I have more than one argument?

    24. So much for numbers, what about dates?

    25. Working with Dates

    26. Moving backward and forward in time

    27. Getting an object that extends Calendar

    28. Working with Calendar objects

    29. Highlights of the Calendar API

    30. Even more Statics!... static imports

  11. Chapter 11 Exception Handling: Risky Behavior

    1. Let’s make a Music Machine

    2. We’ll start with the basics

    3. First we need a Sequencer

    4. The compiler needs to know that YOU know you’re calling a risky method

    5. An exception is an object... of type Exception

    6. If it’s your code that catches the exception, then whose code throws it?

    7. Flow control in try/catch blocks

    8. Finally: for the things you want to do no matter what

    9. Did we mention that a method can throw more than one exception?

    10. Exceptions are polymorphic

    11. Multiple catch blocks must be ordered from smallest to biggest

    12. You can’t put bigger baskets above smaller baskets

    13. When you don’t want to handle an exception...

    14. Ducking (by declaring) only delays the inevitable

    15. Getting back to our music code...

    16. Making actual sound

    17. Your very first sound player app

    18. Making a MidiEvent (song data)

    19. MIDI message: the heart of a MidiEvent

    20. Change a message

  12. Chapter 12 Getting GUI: A Very Graphic Story

    1. It all starts with a window

    2. Your first GUI: a button on a frame

    3. But nothing happens when I click it...

    4. Getting a user event

    5. Listeners, Sources, and Events

    6. Getting back to graphics...

    7. Make your own drawing widget

    8. Fun things to do in paintComponent()

    9. Behind every good Graphics reference is a Graphics2D object

    10. Because life’s too short to paint the circle a solid color when there’s a gradient blend waiting for you

    11. We can get an event. We can paint graphics. But can we paint graphics when we get an event?

    12. GUI layouts: putting more than one widget on a frame

    13. Let’s try it with TWO buttons

    14. So now we need FOUR widgets

    15. And we need to get TWO events

    16. Inner class to the rescue!

    17. An inner class instance must be tied to an outer class instanceThere’s an exception to this, for a very special case—an inner class defined within a static method. But we’re not going there, and you might go your entire Java life without ever encountering one of these.

    18. How to make an instance of an inner class

    19. Using an inner class for animation

    20. Listening for a non-GUI event

    21. An easier way to make messages / events

  13. Chapter 13 Using Swing: Work on Your Swing

    1. Swing components

    2. Layout Managers

    3. How does the layout manager decide?

    4. The Big Three layout managers: border, flow, and box

    5. Playing with Swing components

    6. Making the BeatBox

  14. Chapter 14 Serialization and File I/O: Saving Objects

    1. Capture the Beat

    2. Saving State

    3. Writing a serialized object to a file

    4. Data moves in streams from one place to another

    5. What really happens to an object when it’s serialized?

    6. But what exactly IS an object’s state? What needs to be saved?

    7. If you want your class to be serializable, implement Serializable

    8. Deserialization: restoring an object

    9. What happens during deserialization?

    10. Saving and restoring the game characters

    11. Writing a String to a Text File

    12. Text File Example: e-Flashcards

    13. Quiz Card Builder (code outline)

    14. The class

    15. Reading from a Text File

    16. Quiz Card Player (code outline)

    17. Parsing with String split()

    18. Version ID: A Big Serialization Gotcha

    19. Using the serialVersionUID

    20. Saving a BeatBox pattern

    21. Restoring a BeatBox pattern

  15. Chapter 15 Networking and Threads: Make a Connection

    1. Real-time Beat Box Chat

    2. Connecting, Sending, and Receiving

    3. Make a network Socket connection

    4. A TCP port is just a number. A 16-bit number that identifies a specific program on the server

    5. To read data from a Socket, use a BufferedReader

    6. To write data to a Socket, use a PrintWriter

    7. The DailyAdviceClient

    8. DailyAdviceClient code

    9. Writing a simple server

    10. DailyAdviceServer code

    11. Writing a Chat Client

    12. Java has multiple threads but only one Thread class

    13. What does it mean to have more than one call stack?

    14. Every Thread needs a job to do. A method to put on the new thread stack

    15. To make a job for your thread, implement the Runnable interface

    16. The Thread Scheduler

    17. Putting a thread to sleep

    18. Using sleep to make our program more predictable

    19. Making and starting two threads

    20. What will happen?

    21. Um, yes. There IS a dark side

    22. The Ryan and Monica problem, in code

    23. We need the makeWithdrawal ( ) method to run as one atomic thing

    24. Using an object’s lock

    25. The dreaded “Lost Update” problem

    26. Let’s run this code...

    27. Make the increment() method atomic. Synchronize it!

    28. The deadly side of synchronization

    29. New and improved SimpleChatClient

    30. The really really simple Chat Server

  16. Chapter 16 Collections and Generics: Data structures

    1. Tracking song popularity on your jukebox

    2. Here’s what you have so far, without the sort:

    3. But the ArrayList class does NOT have a sort() method!

    4. ArrayList is not the only collection

    5. You could use a TreeSet... Or you could use the Collections.sort() method

    6. Adding Collections.sort() to the Jukebox code

    7. But now you need Song objects, not just simple Strings

    8. Changing the Jukebox code to use Songs instead of Strings

    9. It won’t compile!

    10. Generics means more type-safety

    11. Learning generics

    12. Using generic CLASSES

    13. Using type parameters with ArrayList

    14. Using generic METHODS

    15. Here’s where it gets weird...

    16. Revisiting the sort( ) method

    17. In generics, “extends” means “extends or implements”

    18. Finally we know what’s wrong...

    19. The new, improved, comparable Song class

    20. We can sort the list, but...

    21. Using a custom Comparator

    22. Updating the Jukebox to use a Comparator

    23. Uh-oh. The sorting all works, but now we have duplicates...

    24. We need a Set instead of a List

    25. The Collection API (part of it)

    26. Using a HashSet instead of ArrayList

    27. What makes two objects equal?

    28. How a HashSet checks for duplicates: hashCode() and equals()

    29. The Song class with overridden hashCode() and equals()

    30. And if we want the set to stay sorted, we’ve got TreeSet

    31. What you MUST know about TreeSet...

    32. TreeSet elements MUST be comparable

    33. We’ve seen Lists and Sets, now we’ll use a Map

    34. Finally, back to generics

    35. Using polymorphic arguments and generics

    36. But will it work with ArrayList<Dog> ?

    37. What could happen if it were allowed...

    38. Wildcards to the rescue

    39. Alternate syntax for doing the same thing

  17. Chapter 17 Package, Jars and Deployment: Release Your Code

    1. Deploying your application

    2. Imagine this scenario...

    3. Separate source code and class files

    4. Put your Java in a JAR

    5. Running (executing) the JAR

    6. Put your classes in packages!

    7. Preventing package name conflicts

    8. Compiling and running with packages

    9. The -d flag is even cooler than we said

    10. Making an executable JAR with packages

    11. So where did the manifest file go?

    12. Java Web Start

    13. The .jnlp file

  18. Chapter 18 Remote Deployment with RMI: Distributed Computing

    1. Method calls are always between two objects on the same heap

    2. What if you want to invoke a method on an object running on another machine?

    3. Object A, running on Little, wants to call a method on Object B, running on Big

    4. But you can’t do that

    5. The role of the ‘helpers’

    6. Java RMI gives you the client and service helper objects!

    7. How does the client get the stub object?

    8. How does the client get the stub class?

    9. Be sure each machine has the class files it needs

    10. Yeah, but who really uses RMI?

  1. Appendix Final Code Kitchen

    1. Final BeatBox client program

    2. Final BeatBox server program

  2. Appendix The Top Ten Topics that almost made it into the Real Book...

    1. #10 Bit Manipulation

    2. #9 Immutability

    3. #8 Assertions

    4. #7 Block Scope

    5. #6 Linked Invocations

    6. #5 Anonymous and Static Nested Classes

    7. #4 Access Levels and Access Modifiers (Who Sees What)

    8. #3 String and StringBuffer/StringBuilder Methods

    9. #2 Multidimensional Arrays

    10. And the number one topic that didn’t quite make it in...

    11. #1 Enumerations (also called Enumerated Types or Enums)

  3. Appendix This isn’t goodbye