History
Steam locomotives from the industrial revolution are the precursor of modern trains. The contraption at the heart of these machines is the Steam Engine, which is actually much older than most people realise. "Aeolipiles" which were the original form of steam engine were an ancient Roman invention, dating from as old as the 2nd century B.C, and consisted of a heated water container with tubes coming off of it, which led to a rotating piece that would release the steam as jets, creating torque.

The Aeolipile, however, is not known to have ever been used for any practical purpose, but simply as a novelty, or a temple wonder, according to some sources.
Some of the first known practical uses for steam engines were to pump water. An example of this was Thomas Savery's steam pump, dating from the late 17th century,
which was used to pump water from the mines. This pump utilised the suction created by condensed steam, along with hand-operated valves to draw water up.
The first person to create a practical and useful steam engine, using the concept of pistons and cylinders was Thomas Newcomen, an English inventor, Baptist preacher and ironmonger.
His engine was also used to draw water up from the mines, but was fundamentally different in its approach.

As mentioned, Newcomen's engine worked on the principle of pistons and cylinders. It had a main boiler that heated water, causing steam pressure to build up in a cylinder.
The steam would push up a piston that was attached to the main swinging arm of the machine. The piston was also connected to a valve, which was closing off a pipe that had a cistern of cold water at the top,
so when the piston reached its apex it would open the valve, allowing a cold spray of water to enter the cylinder, causing the steam to condense, bringing the piston down because of the pressure difference,
which is what would draw the water up from the mine.
The next big improvement in steam engines, and the first to involve rotational movement was Watt's Steam Engine, which was similar in principle to Newcomen's Atmospheric Engine, but differed in several ways.
It was "the first truly efficient steam engine" (Encyclopædia Britannica),
because of the changes that were made by James Watt. The main change James Watt made was to add a separate chamber for condensing the steam,
as he realised that it was inefficient to constantly be cooling and re-heating the main cylinder.
This, along with some other, smaller changes made the engine about 75% more efficient than Newcomen's Atmospheric Engine
(Wikipedia).

Steam engines weren’t ever practically used in vehicles until 1801 when Richard Trevithick introduced his steam carriage “The puffing devil” and drove it up a hill in Camborne, Cornwall. Later he built another steam carriage in 1803, and then built his first railway locomotive, the “penydaren”, in 1804. He built two other steam locomotives that ran on railways in 1805 and 1808, but then abandoned the project, because the rails, which were still the old cast-iron at this point in time, were too brittle and would often break under the weight of the steam locomotives.

There were various differences in the workings of this engine, among the most prominent being that it relied entirely on steam pressure, and didn’t require condensers to produce a vacuum to draw the piston. This meant that they could be much more light weight and were practical for use in locomotives. The workings of steam locomotives and their engines is described in greater detail on the “How it Worked” page.
To conclude this brief overview of railway vehicles and steam engines, suffice it to say that much effort and ingenuity from numerous notable figures over the years went into the steam locomotive, which is the predecessor of the modern train.