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: 
Any G lens is a D lens. Not all D lenses are G lenses.  

The difference is that a G lens lacks an aperture ring for manually setting the aperture on the lens (rather than the camera). This isn't very important on modern cameras (everything producedin the last 20 years or so) except sometimes in full manual mode it can be more convenient than using the camera controls.  

The reason he advised that lens is not that it's a D rather than a G lens, but because its far wider maximum aperture makes it much more capable in low light situations than the lens you already have (it can capture a lot more light, meaning shorter exposure times). It's also optically far superior to your kit lens, giving better photos with less distortion and lens artifacts. Neither is related to D vs. G, it's just differences in the design and materials used in the lens construction.  

The main reason to omit an aperture ring on many current lenses is cost (it's extra construction, materials, etc.), and there being no space for one on a lens that has VR (the number of contacts on the electronic linking between the lens and body means Nikon could not design a lens that has both VR and an aperture ring without changing their lens mount, which would break compatibility between new and existing lenses and bodies, which they've always avoided).
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>