Hello Ranjith,
In fact only option 1) from you example gets credentials. At point 2), a set of credentials is used by means of your copied statement. You have acquired an OAuth 2.0 access_token from another place in that case, such as a JavaScript client or another web application, and wish to use it from Java or Python.
Other ways supported, in the line of programmatic authentication: through a user account, authenticating from a mobile app, from a desktop app. You may connect programmatically using a developer account, service account, or mobile app credentials. All these options are described in more detail in the "Programmatic authentication"
online document. An extensive Java example is provided on that page, that should help you as well.