Shareware is a kind of marketing, not a kind of software. Think of it as "try before you buy". You download a copy of the software, install it, and pay for it if you like it. Shareware commonly has some kind of built-in trick to keep you from using forever for free. For instance, some products will cease to function after a set period of time. Others have no expiration date but have a built-in limitation, such as the inability to save files.
Freeware is very much what its name implies; software that's free to use. There are often restrictions on selling or redistributing these products. For an overview of the most common public-domain licensing arrangement, see http://www.gnu.org/licenses/licenses.html.
Who would want to write software for free? The answer can be somewhat complex, but this is as good a summary as any.