There is a key word and a key phrase that explain what Ecclesiastes is all about.
The key word is translated “vanity” in the KJV. Recent study of the language indicates that the term is richer than that. It points to something vain (“empty”), it is true, but also carries with it the idea that what makes it useless is that what is done will not last. If we would coin a term to translate it, we would have to say that “All is impermanence.” Throughout the book evidence of every kind is adduced to prove this fact. For instance, a man slaves throughout his life, but what it gains him, only those who follow can enjoy. He dies before he can benefit from it.
The key term is “under the sun.” This phrase refers to the world as it is presently constituted–a world of sin and its consequences. And, in particular it refers to the life of those who live only for this world. It is a world under the sun rather than a world under His Son.
Pessimism? Is that the theme of the book? Yes and no. Is there a pessimistic attitude on the part of the writer? Yes, for those who live their lives merely “under the sun,” where all is impermanent. No, for those who see the hand of God even in the midst of the useless lives of those who don’t recognize His goodness. Throughout the book, God is said to give good things (with an emphasis on the blessings of food and marriage) to those who love him, in order to sustain such persons in the midst of a world where all goes to pot.
And the factor that changes all is God’s warning that this world is not the end—He will bring our thoughts and deeds into judgment. He advises youth to make the most of the body they possess while they can because in this world, under the sun (the curse of sin), it will soon fall apart.
So, Ecclesiastes (in its essence) is a tract for the times, calling men to repentance and faith.