AF Lenses
The AF lens is an older style of lens. This type of lens uses the camera's internal auto focus motor to focus the lens on the subject. There is a mechanical coupling between the lens and the camera which needs to be aligned for the auto focus feature to work. These lenses may also contain electronic components for metering light and aperture control.
AF-S Lenses
The AF-S lens is a self-contained auto-focus lens. This lens contains its own auto focus motor, so that even on cameras without an auto focus drive, such as the D40, the auto focus will still function. These lenses are a later creation than the AF lens, and can function with most Nikon camera bodies from about 1988 onward.
Compatibility
Because Nikon's lens and camera body system is rated highly for the compatibility between components, it's important to note which lenses work best with which bodies. Certain lenses may have reduced functions when coupled with a camera body which does not have the same features. Such differences can result in reduced capabilities, such as manual focusing or the inability to use the built-in light meter.
Advantages to AF-S
AF-S lenses are compatible with a wide range of cameras, and given that the auto focus motor is in the lens, the auto focus function works well on most cameras. All Nikon digital SLR cameras work with AF-S lenses and they are especially useful on entry-level consumer cameras such as the D40, which do not have their own auto focus drive. These lenses will still work well in manual focus mode, making them handy and versatile for anyone with more than one camera body.
Advantages of AF Lenses
AF lenses are older, and therefore can often be found secondhand for low prices. Entry-level photographers can build up an arsenal of quality lenses for a smaller investment than new equipment would require. Cameras made prior to the introduction of automatic indexing, introduced in 1977, do not work with these lenses, but you can easily install a meter-coupling prong, which will update the technology.