Question: I recently bought a Nikon D5100. And along with this camera, I got the AF-S DX NIKKOR 18-55mm f/3.5-5.6G VR lens as kit. It's "G" type lens, right?

One of my friend suggested to buy a 50mm f/1.8D prime lens for a good aperture. I bought it too, and it's "D" type lens.

Main thing is I'm confused about what these "G" and "D" type lens means. I know it's a common question but I didn't find any solid answer.

Answer: 
The Nikon D5100 camera body does not have an in-built focus motor.

The G lenses are AF-S lenses which include a focus motor inside the lens - these lenses can be used with entry level camera bodies such as the D3100, D3200, D5xxx series.
AF-S lenses also do not include an aperture ring and will not be compatible with older Film cameras.

The D lenses are older lenses. These lenses would include an aperture ring and would be compatible with older Film cameras. 

Few D lenses are AF lenses which do not include an auto-focus motor inside the lens. If auto-focus is a requirement, these lenses require a camera, generally in the mid-to-high-pro-level body range which include a screw-drive focusing motor (auto-focus motor) inside the camera. These lenses will work on the entry level Nikon cameras but focusing will need to be done manually.

Few of the D lenses range also have AF-S. These lenses will be able to auto-focus on the entry level Nikon cameras including the D5100. The 300mm f/4D AF-S is an example of this which is currently available.

The D lenses are also somewhat cheaper compared to the G lenses. However, to use auto-focus on the D lenses with AF, you need to invest more on the higher level camera body - D7000 and above.

If you are currently using the 50mm 1.8D on your D5100 camera, you are probably using manual focus for taking your photographs.

List of Nikon F-mount lenses with integrated autofocus motor - Wiki Link - <http://en.wikipedia.org/wiki/List_of_Nikon_compatible_lenses_with_integrated_autofocus-motor>
50mm 1.8 d has no auto focus motor. If you want to auto focus with this lens use d7000 or higher because this camera has built in auto focus, use 50mm 1.8 G if you want auto focus to the camera d5000 below. Because 50 mm 1.8 G is designed for cameras d5000 and below for auto focus. Ok