Hamlet's soliloquy in Act 1, Scene 2 (Lines 131-161) provides a number of literary devices that offer insight into Hamlet's character.
One is found at the beginning, where Shakespeare uses a metaphor as Hamlet wishes he could just disappear:
O, that this too too solid flesh would melt,
Thaw and resolve itself into a dew (131-132)
Hamlet is wishing that he could become unsubstantial, like dew on the plants (which evaporates in the sun) or like a candle (which could just melt away). It is at this point that he bemoans God's laws against suicide ("self-slaughter"). This shows how unhappy Hamlet is after his father's recent death, and after his mother and step-father's criticism that he has mourned too long. As Claudius puts it, Hamlet's continued grief is sinful:
...'tis a fault to heaven (104)
Then Hamlet compares the world to a neglected piece of land, another metaphor:
'tis an unweeded garden
That grows to seed; things rank and gross in nature
Possess it merely. (137-139)
Here Hamlet speaks of how things used to be (implying that when his father lived, the world was a garden). He compares the world now to a rank place, where weeds abound (he could be referring to Claudius) and things that are "gross" have taken over. (This may well refer to the wedding between Claudius and Gertrude. In Elizabethan times, the marriage of a widow to her brother-in-law was considered incestuous.) There is also the sense here that his mother has turned her back not only on her dead husband's memory, but also on her son by marrying again so soon.
Hamlet lets his unhappiness over his mother's recent marriage be known in lines 140-159. He personifies "Frailty" when he speaks to it as if it were a person, something that could hear his words:
Frailty, thy name is woman! (148)
In this portion of the soliloquy, Hamlet uses allusion when he compares his mother's mourning to Niobe.
...she follow'd my poor father's body
Like Niobe, all tears (151-152)
This is a reference to Ovid's Metamorphoses and the story of Niobe and Anfione who ruled Thebes. Niobe angered the gods and lost all of her fourteen children; she cried until she turned to stone. We learn that Hamlet is disgusted with Gertrude's "show" of grief: he believes her tears were empty. He has lost faith in his mother.
Hamlet then compares his mother to an animal, noting that animals cannot reason but one that had lost its mate would have mourned longer than his mother did:
O God! a beast that wants discourse of reason
Would have mourn'd longer— (153-154)
Then Hamlet uses an allusion again to compare his uncle and his father, no more alike than Hamlet is to the demigod, Hercules:
...married with my uncle,
My father's brother, but no more like my father
Than I to Hercules. (154-156)
...who was able to...
surpass all mortal men in strength, size and skill...
In these last two examples, Hamlet is puzzled: how could his mother (1.) lower herself first to act with less reason than an animal and (2.) marry a man so much less than the husband she buried? This shows that Hamlet loved his mother, but it also reveals jus how devoted he was to his father.