A holodeck is a room, usually on a starship, that is made up of a hologrid that enable holographic projections to be created inside the room. Similar areas on a space station or planetary surface are referred to as holosuites.
Prior to the 2370s, holodecks installed aboard Federation starships produced objects that users could manipulate using simple holograms and force fields. In the 2370s, engineers had enhanced the holodeck to replicate an item when a user wanted to manipulate it, so that it would feel as real as possible.
However, when the objects wasn't being manipulated, the replicated item would be removed and it would be produced with holograms and force fields again. A replicated object would also revert to a hologram if it was to be used as a weapon, such as a sword. (TNG eBook: A Sea of Troubles)
In an alternate timeline where Montgomery Scott went back in time to rescue James T. Kirk before his absorption into the Nexus, Scott and Geordi La Forge altered the holodeck aboard the USS Enterprise-D to route the holographic imaging output to the ship's external deflector shield system, projecting a sensor image; although the ship would not visually change, it was sufficient to distract the Borg long enough to return Kirk to the Nexus and return the timeline to normal. (Star Trek novel: Engines of Destiny)
The origins of the holodeck go back to the beginning of humanity's mission into space. In 2151, the Enterprise (NX-01) encountered a Xyrillian vessel that had encountered engine problems. While aboard the Xyrillian ship, the Enterprise crew discovered a holographic chamber aboard which enabled the Xyrillians to program any environment they desired. A holographic chamber was later installed aboard a Klingon battle cruiser as a bargain for the Xyrillians' lives. (ENT episode: "Unexpected")
One of the key aspects of the creation of the Federation's own Holodeck systems was work done by Doctor Caroline Ravenwood who made a breakthrough in psychotherapuetic engineering which was in turn responsible for the creation of the holodecks. This work resulted in her being awarded the Cochrane Medal and allowed Holodecks to be used throughout the Federation as a therapeutic tool in the treatment of mental disorders as well as for instructional and even entertainment purposes. (FASA module: Star Trek: The Next Generation Officer's Manual)
By the late 23rd century, Starfleet had reached a reasonable level of holographic projection and rec rooms aboard Constitution-class starships came equipped with holographic projectors. (TAS episode: "The Practical Joker"; TOS comics: "The Final Voyage", "Mortal Gods") They were so widespread at other orbital and terrestrial facilities, that James T. Kirk recreated his ill-fated, final USS Farragut mission. With much the same hindsight after facing the Kobayashi Maru scenario, Kirk was absorbed with finding out how differently the consequences of his actions may have been. The computer simulated the best estimate had he not hesitated at Captain Garrovick's order. The resulting destruction of the starship with all hands, with himself and Ensign Drake stranded on the planet surface, protected only by phasers. (TOS comic: "The Ashes of Eden")
By the year 2373, the Vulcan government had installed a variation of the holodeck in their detention facilities. Once a prisoner was placed inside the holocell, the environment changed to match the meditation gardens outside the Surak Memorial. (TOS novel: Avenger)