David's early life

Michelangelo's David
His early occupation was that of tending his father's sheep on the
uplands of Judah. From what we know of his later story, doubtless
he frequently spent his time, when watching sheep, with his
shepherd's musical instruments (flute and harp), while he drank in
the many lessons taught him by the varied scenes spread around him.
His first recorded exploits were his encounters with the wild
beasts. He mentions that with his own unaided hand he slew a lion
and also a bear, when they came out against his flock, beating them
to death, in open conflict, with his club (1 Samuel
17:34,35).
While David was thus engaged with his flocks, Samuel paid an
unexpected visit to Bethlehem. There he offered up sacrifice, and
called the elders of Israel and Jesse's family to the sacrificial
meal. Among all who appeared before him he failed to discover the
one he sought. David was sent for, and the prophet immediately
recognized him as the chosen of God, chosen to succeed King Saul,
who was now departing from the ways of God, on the throne of the
kingdom. He accordingly poured on his head the anointing oil. David
went back again to his shepherd life, but "the Spirit of the Lord
came upon David from that day forward," and "the Spirit of the Lord
departed from Saul" (1 Sam. 16:13, 14).
Not long after this David was sent for to soothe with his harp the
troubled spirit of King Saul, who suffered from a strange
melancholy dejection. He played his harp before the king so
skillfully that Saul was greatly cheered, and began to entertain
great affection for the young shepherd. After this he went home to
Bethlehem. But he soon again came into prominence. The armies of
the Philistines and of Israel were in battle array in the valley of
Elah, some 16 miles south-west of Bethlehem; and David was sent by
his father with provisions for his three brothers, who were then
fighting on the side of the king. On his arrival in the camp of
Israel, David, now a youth (1Sam17:42), was made aware of the state
of matters when the champion of the Philistines, Goliath of Gath,
came forth to defy Israel. David took only his sling, and with a
well-trained aim threw a stone "out of the brook," which struck the
giant's forehead, so that he fell senseless to the ground. David
then ran to cut off Goliath's head with Goliath's own sword (1 Sam.
17). The result was a great victory for the Israelites, who pursued
the Philistines to the gates of Gath and Ekron. However, 2 Samuel
credits Elhanan with Goliath's death. See Goliath.
David's popularity following this heroic exploit awakened Saul's
jealousy (1 Sam. 18:6-16), which he showed in various ways. He
conceived a bitter hatred toward him, and by various stratagems
sought his death (1 Sam. 18:29). The deep-laid plots of the enraged
king, who could not fail to observe that David "prospered
exceedingly," all proved futile, and only endeared the young hero
the more to the people, and very specially to Jonathan, Saul's son,
who shared a deep, lifelong relationship with David that some
scholars contend was romantic (see Jonathan and David).
During the period of his persecution by Saul, David lived as an
exile and accepted the city of Ziklag as a fief from the Philistine
King Achish of Gath (1 Sam 27:2-6). Until Saul's death at Gilboa,
David worked as a mercenary general for the Philistines, and may
have adopted iron technology (as opposed to bronze) from them at
this time.