Shoutfire is a project mainly written in Java, it's free.
An Android chat application.
The application includes a PHP interface to a MySQL database. The database stores all messages. A user can only see the last 100 messages.