In Shakespeare's As You Like It, the character of Jaques is remembered most for his famous ”All the world's a stage" speech, also known as the "seven ages of man" speech.
Jaques isn't important to the plot of the play—nothing of consequence in the play happens because of Jaques—but he serves most effectively as a contrast to the other characters.
Whereas Duke Senior, his followers in the forest of Arden, and those who venture into the forest, like Orlando, Rosalind, and Celia, strive to be happy, Jaques delights in being melancholy. He enjoys feeling miserable.
It's difficult to know if Jaques is truly melancholy or if he simply enjoys the attention that comes with being "melancholy Jaques." Nevertheless, he's assumed the role of the "odd man out," and his melancholy is a characteristic by which he's recognized among the Duke's followers, and, in time, by everyone else in the forest.
Jaques likes to remind other characters about how melancholy he is.
JAQUES. I can suck melancholy
out of a song, as a weasel sucks eggs. (2.5.12-13)
ROSALIND. They say you are a melancholy fellow.
JAQUES. I am so; I do love it better than laughing. (4.1.3-4)
Jaques also seems to have studied his own melancholy.
JACQUES. I have neither the scholar's melancholy, which is emulation; nor the musician's, which is fantastical; nor the courtier's, which is proud; nor the soldier's, which is ambitious; nor the lawyer's, which is politic; nor the lady's, which is nice; nor the lover's, which is all these: but it is a melancholy of mine own, compounded of many simples, extracted from many objects: and, indeed, the sundry contemplation of my travels; in which my often rumination wraps me in a most
humorous sadness. (4.1.12-22)
The "melancholy Jaques" is renowned far and wide not only for his sadness but also for his predisposition to "moralize" and philosophize on any occasion to whoever will listen.
DUKE SENIOR. But what said Jaques?
Did he not moralize this spectacle?
FIRST LORD. O, yes, into a thousand similes. (2.1.45-47)
Jaques isn't content to be melancholy on his own. He seems to want to inflict his melancholy on others.
Jacques's "All the world's a stage" speech is a prime example of his unsolicited philosophizing. Duke Senior and his followers are having a meal, and Jaques is regaling his captive audience at length about a "motley fool" who he just met in the forest. The meal is interrupted by Orlando who, with sword drawn, demands food for his ancient servant, Adam.
The kindly Duke Senior invites Orlando and Adam to share their food, and Orlando goes back into the forest to bring Adam to the Duke's table.
While the Duke and his friends are waiting for Orlando to return with Adam, the Duke makes a casual remark to the effect that he and his followers aren't the only unhappy and disenfranchised people in the world.
DUKE SENIOR. Thou seest we are not all alone unhappy;
This wide and universal theatre
Presents more woeful pageants than the scene
Wherein we play in. (2.7.142-145)
This affords Jaques the opportunity to launch into his "seven ages of man speech," and who better to fill the time waiting for Orlando and Adam than Jaques and his philosophizing?
Whether Jaques is truly melancholy or merely playing at being melancholy, by the end of the play, he's decided not to inflict himself any further on his fellow men and women, and he goes to live in a monastery with Duke Frederick. If Jaques is searching for another captive audience, what better place to find one than in a monastery?