UTF-8 to Mail Header converter

This page can convert any UTF-8 string to ASCII characters that can be used in mail headers (e.g. Subject line).
For example, the UTF-8 string "2πr" will be displayed as =?UTF-8?Q?2=CF=80r?=.

UTF-8 input

Type in some UTF-8 text and press the [Submit] button:

How can I do this myself using Java?

Here's the Java source code for UTF-8 to java code conversion. Source code courtesy Francis Devereux.