Learn and Share Java: Interactive Algorithms Textbook

Each chapter has code that you can try in the browser.