First of all, Twitter and thus Twitter4J requires us to set up credentials so that we can access Twitter's API. If you have done that already, it will be easy to proceed further. If not, go to https://apps.twitter.com/ to create an application that can be used to obtain the credentials.
When the credentials are obtained, we will need to create a special Configuration object where the credentials will be stored:
final Configuration configuration = new ConfigurationBuilder() .setDebugEnabled(true) .setOAuthConsumerKey("enterYourDataHere") .setOAuthConsumerSecret("enterYourDataHere") .setOAuthAccessToken("enterYourDataHere") .setOAuthAccessTokenSecret("enterYourDataHere") .build();
That's it. The following line is useful ...