Please see David Eck's response!
I don't didn'tdon't know why Eck made his book freely available, but I can tell you why I make my course materials freely available, and will continue to do so even if I ever take the final step of turning them into a book.
Because I want as many people as possible to use what I've written.
As others have pointed out, the expected profit from publishing a textbook is minuscule, especially a textbook in a well-worn topic like Java programming or algorithms. By making my notes freely available instead of selling them, I potentially lose a small amount of money, but I gain a significantly wider audience. And that wider audience justifies, in my mind, the thousands of hours that I have put into writing, polishing, illustrating, rewriting, and maintaniing them, far more than any monetary compensation would.