UV (ultra violet) sterilisers have been around the aquarium trade for over 50 years. They haven't changed much in design and are normally a plastic case that houses a UV globe. Water passes through the casing and is exposed to UV light. The UV light is separated from the water by a piece of glass.
The slower the water passes through the UV unit, the more time it spends exposed to the UV light and the more the UV light can kill off anything in the water. Filtering the water before putting it through a UV steriliser is the most effective way of treating the water because there will be fewer particles in the water to hold harmful pathogens. Basically clean water going into the UV unit will allow the UV light to kill more microscopic organisms in the water.
As Byron mentioned, unless you get all the aquarium water through the UV unit before it goes back into the tank, you aren't going to get rid of much because the clean UV treated water simply mixes with tank water that is contaminated. That doesn't mean they don't work, just they work slowly and only kill a small portion of harmful pathogens in the water. So they won't stop your fish getting sick if you have a disease outbreak, but they will slow the spread of the disease. As others have mentioned, big water changes can dilute diseases and green water in aquariums and that is usually cheaper than a UV steriliser.
UV steriliser units for aquariums need the globes to be changed regularly so if you get one, make sure it is easy to replace the globe and make sure the globe doesn't cost too much. There are some cheap UV units on the market but the replacement globes cost nearly as much as the unit.
As a way to reduce diseases in an aquarium, they can be helpful, but so can water changes and gravel cleaning the substrate.