You take Airtrain from your terminal to either Howard Beach Station for the A subway or Jamaica Station for the E and J subways and LIRR. You purchase the Metrocard to pay for Airtrain and subway from a self-service machine when you exit Airtrain. At JFK I believe you can purchase a Metrocard at the newsstand in Terminal 4 only.
You take Airtrain from your