As your science teacher taught, a mechanical wave is a rhythmical movement of energy that passes through matter, as the wave passes it causes the molecules of the matter it moves through to oscillate (either backwards and forwards, or up and down). The waters of this planet are full of waves, not just on the surface where we see them, but everywhere, these waves are caused by anything that moves in the water and by the movement of the water itself, and it would be very useful, if you lived in the water, to be able to detect these waves. The lateral line system is the fish's way of doing this.
By being able to detect these waves a fish can learn a lot about the world it is living in. For instance when a fish swims it creates a bow wave (amongst others) by pushing some water in front of it. When this wave impacts an obstacle it reflects a distorted form of its self back towards the fish. By being able to sense this reflected wave a fish can avoid bumping into things, such as the glass of a fish tank, even when all its other senses are inoperable.
The 'lateral line' system is a way of detecting wave energy as it passes over or bounces off the fishes body. It works using mechanoreceptors similar to those responsible for the senses of hearing and balance. The basic sense receptor, called a 'neuromast' consists of a cup like base which rests in the epidermis and a cylindrical gelatinous cupola which extends beyond the epidermis into either, a supporting mass of lymph fluid or, in a few deep sea fish, directly into the water. Any mechanical wave that passes through the water sets up reciprocal movements in the lymph fluid that surrounds the cupola.
Within the supporting cup are sense cells which possess hairs that reach up into the cupola. When the cupola is moved by a passing pressure wave the hairs are bent and this triggers a different electrical impulse to be sent to the brain. I said a different electrical impulse because the neuromasts are constantly sending off a regular series of impulses to the brain. This baseline signal is changed when the hairs are bent, bending to one side results in an increase in the impulse's frequency and bending to the other side results in a decrease in the impulse's frequency.
Fish have these neuromasts located all over their body, some are individually housed in shallow pits, but many others are located in special epidermal (skin) canals that open regularly to the surface through pores. These canals and canal pores make up the lateral line that we see running along the fish's flanks. However most fish have an additional series of canals that run over their head. One canal passes above the eye and on to the end of the fish's snout, two more pass below the eye and then on to the upper and lower jaws respectively. These lines may give rise to a few, or even many, branch lines.
The lateral line system is an essential component of a fish's sensory arsenal and is undoubtedly one of the reasons fish have been so successful as a group. It is also a wonderful example of Nature taking an already existing adaptation and retooling it to work in another capacity.