When people mention ulcers they're usually referring to peptic ulcers. Peptic ulcers can occur in the oesophagus, the stomach, and the duodenum (the upper part of the small intestine - where they're called duodenal ulcers).
The most common symptoms of a peptic ulcer are indigestion or heartburn. Other symptoms are nausea and vomiting, loss of appetite, or black, tarry stools. If you have any of these symptoms it's important to see a doctor.
Sometimes the main symptom of stomach cancer is a stomach ulcer, another reason to see your doctor if you have chronic ulcer-type symptoms.
Ulcers do have a tendency to heal on their own, but there's no known way to prevent them. However here are some ways to help.
Stop smoking
Smoking can double your chance of getting an ulcer and also slow healing, increasing the likelihood your ulcer will return.
Nicotine is a highly addictive drug but in time you can quit.
Take an antacid
Over-the-counter antacids can heal an ulcer, because they relieve symptoms and neutralize stomach acid.
However, long-term use has side effects so antacids should be taken under a doctor's supervision.
Limit acid-forming foods
All food makes your stomach produce acid but some do so more than others.
Coffee, with or without caffeine, is a known acid stimulant.
Milk is as well even though it used to be used for ulcers. It can be individual so test to see which foods make your ulcer flare up and avoid them accordingly.
Don't drink beer or wine
Beer and wine stimulate acid production, however spirits do not.