In Chapter XXVII of Great Expectations, Pip has decorated and reupholstered furniture in his and Herbert's apartment in London and even hired a servant boy so that the appearance of the place befits a gentleman. As Joe encounters Pip, he greets him heartily,
Which you have that growed...and that swelled and that gentle-folked...as to be sure you are a honor to your king and country.
He and Pip have a warm conversation that is interrupted by the entrance of Herbert. When Herbert extends his hand, Joe backs up from it, feeling not the equal of Herbert, whom he recognizes as a young gentleman. Lest Pip's standing with Herbert be mitigated by his acquaintance with Joe who now becomes aware of Herbert's social class, Joe acts as though he is of inferior social class to Pip, as well to Herbert. Besides, Joe senses his class consciousness.
When he departs, Joe explains to Pip,
"Pip, dear old chap....Diwisions among such must come, and must be met as they come....You and me is not two figures to be together in London; nor yet anywheres else but what is private, and beknown, and understood among friends."
Joe tells Pip that he is out of place in London, for he belongs on the forge:
"You won't find half so much fault in me if you find me in my forge dress...."
This scene exemplfies one of the themes of Charles Dickens who felt that society was a prison in which people were cast into their social standing. Since Joe has been brought into the world of those of a higher class than he, Joe feels awkward; then, out of love for Pip, whom he knows wants to be a gentleman, Joe is formal and respectful to Pip in order to prevent Pip's social ranking to be affected.
The basic reason why Joe calls Pip "sir" even though Joe is so much older than Pip is that Joe is intimidated by the surroundings and is sort of in awe of the fact that Pip is in the process of becoming a gentleman.
In this book, Joe knows that he is not high class. He knows that he is a mere blacksmith who does not belong (in the way people thought back then) with people who are gentlemen. Now Joe has come to London and he is hanging out with people who are "above" him. Because Pip seems like he belongs in that company, Joe calls him "sir."