Ferromagnetic materials can be magnetized in the following ways:
Heating the object above its Curie temperature, allowing it to cool in a magnetic field and hammering it as it cools. This is the most effective method, and is similar to the industrial processes used to create permanent magnets.
Placing the item in an external magnetic field will result in the item retaining some of the magnetism on removal. Vibration has been shown to increase the effect. Ferrous materials aligned with the Earth's magnetic field and which are subject to vibration (e.g., frame of a conveyor) have been shown to acquire significant residual magnetism. A magnetic field much stronger than the Earth's can be generated inside a solenoid by passing direct current through it.
Stroking: An existing magnet is moved from one end of the item to the other repeatedly in the same direction.
Magnetized materials can be demagnetized in the following ways:
Heating a magnet past its Curie temperature; the molecular motion destroys the alignment of the magnetic domains. This always removes all magnetization.
Hammering or jarring: the mechanical disturbance tends to randomize the magnetic domains. Will leave some residual magnetization.
Placing the magnet in an alternating magnetic field with an intensity above the material's coercivity and then either slowly drawing the magnet out or slowly decreasing the magnetic field to zero. This is the principle used in commercial demagnetizers to demagnetize tools and erase credit cards and hard disks, and degaussing coils used to demagnetize CRTs.