How can pilots identify threats ahead of them if they don't have front lights like cars?
Short answer: they do have front lights!
Longer answer: There's lots of stuff for a ground vehicle (such as a car) to hit, because there's lots of stuff close to the ground. There's not much in the air for an aircraft to hit, besides other aircraft. Lights on an aircraft in flight are to help the airplane be seen, not to help the airplane see.
On landing, forward-pointed lights are nice to have, but since runways are illuminated, it's possible to land safely without them. Airliners in particular will probably never be landing on a darkened runway and need to worry about hitting invisible terrain or obstacles ahead, because they're always either above the obstacles or they're on a known safe descent path.
Pretty much anything you want to avoid in the air is (or should be) lit. Other airplanes, radio towers, that sort of thing. If it's not lit, then either you couldn't have done much to avoid it anyway (bird), or you should be able to anticipate it (terrain).
Airplanes do have landing lights, which are quite bright and point forward. In the US, commercial flights are required to have them on under 10,000 feet. They are used to illuminate the runway for takeoff and landing. Planes should not be close enough to illuminate anything with their landing lights until landing though, and they are required to be on to allow aircraft to see each other more easily.
Taxi lights are similar but generally less bright, and help the pilots see where they are going when taxiing on the ground without airport lighting.
This diagram of lights on the MD-11 shows the main areas illuminated by the taxi and landing lights. The other lights help to make the aircraft more visible as well. Runway turnoff lights on airliners also help to light up areas to the side of the aircraft after landing to more easily see upcoming runway turnoffs.
They don't really need to.
Hills and other man-made static obstacles are mapped and lit and height limitations are published to which the pilot can follow to stay safe as long as he knows were he is. Landing strips will be lit up for them.
Other planes will be lit up with navigation lights (red and green) and a pulsing beacon to draw the eye. Also during the night pilots will be flying IFR, which means the Air traffic control will be keeping planes away from each other.
And they hope no birds will be flying in their path.
A light on the plane won't be enough to light for obstacle any way and provide a nuisance on the ground for the people trying to sleep.
Many other answers have covered lights for seeing on the ground, which are invaluable during taxiing, takeoff and landing. They've also covered how most obstacles (like other planes) should be illuminated to be seen (according to Advisory Circular 70/7460-1L in the US). I'm going to cover the other ways that an aircraft can "see" what's around it. IFR navigation and avoiding controlled flight into terrain are related topics.
The answer depends somewhat on whether we're talking about visual flight rules or instrument flight rules. Visually spotting lit obstacles is far more important if you're not instrument-rated. Of course, planes don't have to visually see obstacles to avoid them. Properly trained pilots can fly IFR in zero visibility, so they have plenty of tools to identify threats ahead that they can't see.
Aircraft can fly in low visibility situations where even lights won't do you much good. This is done in large part using careful navigation and reference to charts. Sectional charts are required to show peaks, towers, and other obstructions as shown in the legend below. Approach plates and procedures may also list smaller obstacles particularly close to the runway.
You'll notice that the sectional below has the obstructions marked, as well as a big 07 in the right hand bottom. That 07 means that the highest terrain or obstruction in the right hand box on the image below (basically everything east of Logan Intl Airport, outlined by straight lines with tick marks) is 700 feet, including a small margin and rounding, so if you're flying safely above that altitude you can avoid obstacles.
A new emerging technology is synthetic vision, as mentioned in SierraSkyport's answer. This system combines precision location information with very detailed terrain and obstacles databases to provide a view of the surrounding area.
This is sometimes combined an enhanced vision system with an near-IR camera to see in darkness and through fog and clouds, and this clear camera-based view of the surrounding area is often overlaid on the center of the synthetic vision display. I've seen a near-IR camera in action and you can actually make out features like the edge of the runway and buildings, even in very low visibility. (Image by Honeywell, provided with Permission)
TCAS and ADS-B
Your major obstacles when above the ground are other aircraft (I don't know what else you'd hit in the air, meteorites?) Any aircraft equipped with a mode-C or mode-S transponder is "visible" to a plane with TCAS, and the TCAS system will provide traffic alerts for nearby aircraft (and guidance for how to resolve the conflict if the intruder gets close enough and it's a TCAS II system).
ADS-B in also provides a traffic information for any nearby aircraft equipped with ADS-B out (which thanks to mandates is becoming very common). If you have ADS-B out as well as ADS-B in, you'll additionally receive radar information for all aircraft from ATC over a service called TIS-B. ADS-B is often supplied integrated into a mode-s transponder, but this is not always the case, so you could have ADS-B out and ADS-B in but not a TCAS-compatible transponder.
TAWS, GPWS, and Radar altimeter
For avoiding the ground these systems provide some information to avoid a controlled flight into terrain. Terrain awareness warning systems (TAWS) and ground proximity warning systems (GPWS) (the two are sometimes synonymous) are now required by the FAA on all large turbine and turbojets. These systems warn if you're descending too fast, below the glideslope, or flying too close to terrain, based on a radar altimeter. Even without this system, you may have a radar altimeter to monitor your height above terrain.
Weather Radar (or Stormscopes), XM radio, and ADS-B all provide excellent information about weather ahead that you can't see. Most non-military aircraft do not have primary radar for seeing things other than weather. Since ATC provides their own primary radar information over TIS (ADS-B traffic information), there is not much need to have a primary radar on the aircraft.
In a worst case scenario ATC has tools like minimum safe altitude warning systems and short-term conflict alerts and may alert you if you're about to run into terrain or another aircraft. As far as I understand, this isn't supposed to be your primary method of avoiding obstacles though, even in IFR conditions.
Night Vision Goggles
Of course, if you really need to see far ahead of you in dangerous terrain, you can use night vision goggles. Your aircraft needs to meet certain requirements and you need training, however.
For civil aviation, planes are lit to make them visible, not so much to illuminate obstacles.
Military aviation is (or was) another matter, in WWII operations were sometimes conducted at night with upwards of a thousand unlit planes. Moonlit nights were to be avoided where possible, because moonlight made it rather too easy for pilots to see other aircraft, and the full moon was called a "fighter's moon". However, especially hazardous operations were sometimes scheduled for the full moon (e.g. see "The Dam Busters", Paul Brickhill) despite the extra risk to the pilots.
Maybe someone can ... illuminate us, as to whether this is still a consideration.
Headlights on a plane are pretty worthless (other than near the ground).
Just as your car headlights don't help you see a mile down the road, headlights on a plane aren't useful for illuminating objects beyond a few hundred yards.
It is more important that planes, towers, and other obstacles have lights on them to be seen, not to see.
That is why planes have red and green lights (as well as a beacon on top, and a white light on the tail).
In addition, once your eyes adjust to night, you can see plenty from the cockpit. Starlight, moonlight, and ground-light can give good visibility of terrain, coastlines, clouds, and other things pilots need to see, without any light coming from the airplane.
For landing and take off, lights are essential. It's possible to do both with just runway lights.
In the air, VFR pilots can still see ground lights and objects in the sky that are lit (other planes). This allows them to see the horizon and keep the plane properly oriented. Navigation is the same as it is during the daytime, with the only exception being that pilotage (flying by reference to objects on the ground) is limited.
During a full moon or nearly full moon and cloudless sky, flying at night is only marginally more difficult than flying during the day.
On a moonless night, or overcast, things are much more difficult. Flying in an area where the horizon can't be discerned is particularly dangerous and should be avoided. For those situations, flying IFR is the only safe alternative.