Get Salesforce Session Id in Visualforce Page And Apex Class

Visualforce Page:

{!$API.Session_ID}

Apex Class:

String sessionId = UserInfo.getSessionId();