Apples (and other fruits and vegetables) have within their cells enzymes and other chemicals that naturally turn the fruit brown when the cell wall is ruptured. This is actually a way the apple protects itself from insect or attack or microbial diseases. The dark brown colour comes from chemicals called quinones which are poisonous to insects and bacteria. These only form when the outer skin of the fruit is punctured. Here's how it works. Enzymes are big complicated molecules. They are proteins and if you could see them they would look like big tangled up chains. The way the chain is tangled is very important becausee it creates unique places along the enzyme molecule where other much smaller molecules can fit in. The enzyme in apples (and many other fruits and vegetables) that causes browning is called polyphenol oxidase and it works by grabbing a phenol molecule and adding oxygen to it which ultimately turns the phenol (which is a type of alcohol) into quinone which is a chemical that has antimicrobial properties and is also unatractive to insects. This reaction is called oxidation because it adds oxygen which it gets from the air. The enzyme is able to cause this chemical reaction because of its special shape. It has this shape because it consists of a long chain of components that tangle up in a special way due to certain chemicals located in strategic parts of the chain. When the enzyme is in an acid environment such as would be created if you put lemon juice on the apples, the acid causes some of the chemical parts of the chain to be altered (ionized), and this makes the chain tangle up in a slightly different fashion. Because of this, the phenol molecule won't fit properly in the enzyme and the oxidation reaction which turns the apple brown is prevented.
The skin of apples ( and many other fruits and vegetables) contains a waxy substance that prevents air and microbes from getting into the body of the fruit. You can see this wax if you take an apple and polish it on your shirt or a cloth. It will become bright and shiny.
making a small donation to science.ca.