The ending is a "happy one", so there is some optimism in this at least. We might say that if the "right" side perseveres it will also survive and so we should never give up our ideals even in the face of the most intimidating circumstances.
Also, Piggy, Simon and Ralph maintain a moral integrity throughout the novel, never giving way to the pressures they face to bend to savagery or bow to the wildly juvenile authority of Jack. This integrity is important and uplifting, I'd say.
If it were truly pessimistic, Ralph, after running for his life, would have been killed by the tribe. Although contrived, the officer appearing at the end at least supports the idea of a glimmer of redemption.
One reason that William Golding wrote Lord of the Flies was as an answer to the sugar-coated optimistic Coral Island written by Ballantyne. Golding's allegory is very dark: the Christ-like figure of charity and spirituality, Simon, is beaten to death by boys in an orgiastic frenzy. At the narrative's end, the island is destroyed, Ralph is running for his life and is only saved by the deus ex machina of the warship and Naval officer that appear "just in the nick of time." A painted savage appears out of the carnage, starts to come forward, "then changed his mind and stood still."
When the officer speaks to him, Ralph sobs uncontrollably as he thinks of the former glamour of the beaches, but "the island was scorced up like dead wood."
He wept for the end of innocence, the darkness of man's heart, and the fall through the air of the true, wise friend called Piggy.
Uncomfortable with Ralph's display of emotion, the officer turns away. The last line of the novel reads,
He turned away to give them time to pull themselves together; and waited, allowing his eyes to rest on the trim cruiser [warship] in the distance.
These are the final images of the novel: a filthy blond-headed boy running in terror, a red-haired boy with paint on his face, holding the remnants of a pair of glasses, a scorched island billowing black smoke, and a warship. There is no optimism.
I think that the point of optimism is that these are children. Children may be savage if left to their own devices, but that is what adults are for. They are NOT left to their own devices. We can guide them and teach them right from wrong, and help them become better human beings.
I wonder whether there is a note of optimism when we think about the ending of the story. The boys in the end do return to civilisation, and perhaps they will be able to take the dire truths they have learned about themselves and mankind with them to give them greater wisdom and understanding about life and humanity in general. Otherwise, the story would be pretty bleak and unyielding without this hope!
I like to think that Simon's character is a glimmer of optimism. He behaves unselfishly and wants to help others. He helps the littluns and he learns the truth about the Lord of the Flies. He is one of the older boys and he could have been drawn into the conflict between Jack and Ralph, but he is able to remain aloof from it. His death is tragic and senseless, and that can happen to good people, but at least Simon proves that not everyone is drawn to power and control and that perhaps in other circumstances that goodness could prevail.
To me, the only real hope is in the fact that Ralph does not actually end up getting killed. Maybe Golding is saying that, in the end, civilization will win out in some way. Otherwise, this is a pretty pessimistic book.
It can be argued that the advent of the naval officer, at the end of Golding's novel, offers a ray of hope in the infernal darkness of the prevailing savage condition of the island. The boys wanted to be rescued from the very first, after the aircrash and having no other way some of them got deviated into savagery and found themselves as the blood-thirsty rivals of one another. But the fact that the boys, who are in the age-group of nearly 6-12 years have lost their innocence completely must also have to be accepted. It is a crude reality that the boys, after tasting power, will show disobdience not only to their parents but also to the social code of conduct. Viewing from this angle the novel ends with a pessimistic outlook and questions about the future of the mankind.
Hmm... I think it could be optimistic only because the children have now gained wisdom and an understanding of the brutal and gruesome capabilities of man. They are prepared for the real world because they have endured the hardships and savagery of the island. When they enter the real world, they have an opportunity to change the others' thinkings. ...However (here comes the pessimistic view again!)... They could also increase the horror (the beast of human nature) in man leading to an even more defective society.