In this Psalm David haMelekh explains that for a Jew the pursue of happiness begins by avoiding the company of bad or shallow people. Why? Because consciously or not bad people will impact us negatively and will drive us away from the path to happiness.
For a Jew, true happiness consists in following the ways of HaShem our God, by studying and following His Tora.
The third verse of this Psalm says that the man who follows the path of HaShem...
"...will be like a tree planted on streams of water, bearing fruits each season, its leaves will never wither, and he will prosper in all he will do"
PLANTED
David haMelekh compares a happy man with a tree. Why? First, because both grow. There is probably no bigger frustration than realizing our own stagnation. If we see that we are in the same spot year after year, we will become depress. Happiness is the effect of realizing that we have grown. When we study Tora, King David says, we are constantly growing. Emotionally, intellectually and in perfecting our character. The ideal tree is "planted" on watered ground. This is a strong tree, which will withstand to destructive winds. Water is constantly feeding its roots and stimulating its development. The ideal Jew constantly absorbs the waters of Tora, allowing the words of HaShem to nurture his soul and strengthen his principles.
FRUITS
This tree will bring forth its fruits. "Fruits" are the biggest reward for a man's life of virtue. The fruits are man's children, those who will continue the path of HaShem. As oppose to the feelings of stagnation and unproductiveness of those who live idle lives, when a man bears fruits, he sees that his path will continue, even after he is gone.
LEAVES
Unlike fruits which are beneficial to the tree itself and its continuity, leaves produce a shadow that can be enjoyed by others. Man's happiness consists not just in assuring the perpetuity of his actions, beliefs and principles but also by becoming kind and productive to others. Like a tree that freely offers its shadow to everyone that needs it, a good man practices charity and offers helps to those in need.
For David HaMelekh, a happy man is the one who nurtures from Tora, develops strong principles, sees his children following the right path and is generous with those who seek his help, "He will prosper in everything he does".