A generator is a device that converts mechanical energy into electrical energy. It can be either an AC generator (alternator) or a DC generator, depending on the type of current produced.
The working principle of generator is based on the fact that a moving wire in the presence of a magnetic field has a voltage induced in it.