In Hamlet, as in almost any other stage play, Shakespeare had the problem of introducing his characters and identifying them by names. In Act 1, Scene 1, notice how the actors keep calling each other by the names of the characters they are playing. Shakespeare does not introduce Hamlet here. He introduces Francisco, Marcellus, Bernardo, Horatio, and the Ghost. There are also many references to Fortinbras. A playwright cannot introduce too many characters at once because the introductions are solely for the sake of the audience, who can only absorb so much information at one time.
The mood of Act 1, Scene 1 from the beginning is one of tension related to the possibility of war and even of a surprise attack. The very first lines are:
Nay, answer me: stand, and unfold yourself.
These guards are expecting trouble. Their apprehensions about the Ghost are secondary. They are more worried about a surprise attack on Elsinore. Marcellus describes some of Denmark's warlike preparations:
Good now, sit down, and tell me, he that knows,
Why this same strict and most observant watch
So nightly toils the subject of the land,
And why such daily cast of brazen cannon,
And foreign mart for implements of war;
Why such impress of shipwrights, whose sore task
Does not divide the Sunday from the week;
What might be toward, that this sweaty haste
Doth make the night joint-labourer with the day:
Who is't that can inform me?
When the Ghost makes his appearance he is wearing full armor. This conveys a strong suggestion that his appearance is connected with the threat of war with Norway--although this is definitely not the case.The arrival of the Ghost of the dead king, who won the disputed territory from Norway, seems logically to be connected with the growing hostilities between the two nations. This is intentionally misleading. Shakespeare wants to introduce the Ghost but wants the audience to be completely unprepared for the revelations he will make to his son in Act 1, Scene 5.
The Ghost has to be there for some reason, so Shakespeare introduces the hostile maneuvers of Fortinbras to keep the audience from guessing he is there because he is concerned about personal revenge against Claudius. Once Shakespeare has invented a potential war to beguile the audience, he decides to keep it as a theme throughout the play. At the very end of the play, it looks as if Fortinbras will become king of Denmark, which makes for a nice conclusion, since somebody has to inherit the throne.
Hamlet is introduced in Act 1, Scene 2, dressed all in black, still mourning his father. But it is not until Act 1, Scene 5 that the real reason for the Ghost's appearance is made known--both to Hamlet and to the audience. In Act 1, Scene 2 Shakespeare introduces Hamlet, Claudius, Gertrude, Polonius and Laertes. But he still has to introduce Ophelia, which he does in Act 1, Scene 3.
Then, with the introductions of all the principal characters completed, Shakespeare finally brings Hamlet together with his deceased father in Act 1, Scenes 4 and 5. The audience has already met Claudius in Act 1, Scene 2, where he played the dominant role. They know he is the king and that he married Gertrude hastily and that he managed to steal the crown from Prince Hamlet, who was the heir apparent. It is essential that the audience know these things so that they will fully appreciate the astonishing revelations the Ghost makes to his son on the battlements.
It is really kind of obvious. Simply read Horatio's dialogue after the Ghost's first entrance/exit right up to where the Ghost enters for the second time. Horatio tells us of King Hamlet's fight with Norway. He tells us of young Prince Fortinbras' attempts to raise an army to take back the land his father lost to King Hamlet. He then touches briefly on Julius Caesar before the Ghost then reappears. Horatio's explanation is in answer to Marcellus' question of why Denmark appears to be preparing for war.