A trademark is the exclusive right to the use of a sign or design for the purpose of identifying the manufacturer of a product or supplier of a service. Trademarks are typically words or logos, but protection may extend to colors and even smells.
Trademarks protect brands and reputations, and serve to avoid confusion in the marketplace. Because of this, similar or even identical trademarks may coexist, if the corresponding companies sell different kinds of goods or services, or operate in different areas.
As an example, Apple Records and Apple Computer can co-exist peacefully despite the similar names, as it is obvious that an Apple laptop comes from Apple Computer, and an Apple CD from Apple Records. But when Apple Computer added a sound chip to the Apple IIGS, Apple Records sued them (and later sued them again over the Mac's system sound, and then about iTunes), because they were now in the same (music) market.
Getting a trademark
Trademarks can be registered with the patent and trademark office, after which they're marked with an ® symbol. In some countries, notably the US, this in not required, and just using it in practice to identify your products is in principle enough. Non-registered trademarks are marked with a ™ symbol.
Our Netherlands eScience Center logo is an example of a (non-registered) service mark (℠, although there is no legal protection for unregistered marks here). Service marks are essentially the same thing as trademarks, but they don't identify physical products (we don't make any) but services or intangible products, and as such are applied to equipment and uniforms and such. The idea is the same however.
Losing a trademark
Trademarks lose their protection if they no longer identify a particular manufacturer, but become general terms for a category of products. For instance, a walkman is a portable audio cassette player. Sony® owns a trademark on that word, but in 2002 an Austrian judge ruled that since the word was in the dictionary as describing any portable audio cassette player, it had become a general term that is therefore not eligible for trademark protection.
Companies do not want to lose their trademarks, so they're usually quite active about protecting them. Most companies have a trademark policy that is designed to protect their trademarks from becoming generic. Google®'s trademark policy for instance says that you should tell people to "do a Google search" for something rather than "Google it", as the latter uses the term generically to mean doing a web search. If you infringe on someone's trademark, you're likely to get a more-or-less friendly letter telling you to quit it or be sued.
Using a trademark
Using trademarked words to refer to the corresponding product or company is generally fine, just make sure that you use them together with the generic term, as in the example above. If you use a trademark, you should acknowledge that it is a trademark using one of those ubiquitous notices like "Sony® is a registered trademark of Sony Corporation". Almost all companies have rules on what to do exactly, a web search for "<company> trademark guidelines" will show you the way.
Software licenses (even Free Software licenses) typically do not give out trademark rights, so you may have to rename a fork if the origin considers your fork harmful to their brand. See e.g. Firefox® (a registered trademark of the Mozilla Foundation) and IceWeasel.
Apple is a trademark of Apple, Inc., registered in the U.S. and other countries.
Firefox® and Mozilla® are registered trademarks of the Mozilla Foundation.
Google™ is a trademark of Google, Inc.
Sony® is a registered trademark of Sony Corporation.