ContentCon is almost full! Reserve your spot in Austin on 5/23

Join us at ContentCon
Register Now

Java Sample App

To help you get started, we have provided Java code snippet below. This snippet shows how to make queries and fetch entries from Contentstack.

class App {
   public static void main(String[] args) {
       try {
           final Stack stack = Contentstack.stack("blt7979d15c28261b93", "cs17465ae5683299db9d259cb6", "production");
           ContentType contentType = stack.contentType("news");
           Query query = contentType.query();
           query.find(new QueryResultsCallBack() {
            @Override
           public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
                   if (error == null) {
                       List<Entry> result = queryresult.getResultObjects();
                       for (Entry entry : result){
                           System.out.println("Title: " + entry.toJSON().getString("title"));
                       }
                   }
               }
           });
 
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }
   }
}

Result:

Title: Modi in Nepal LIVE UPDATES: PM arrives in temple town Janakpur, will ‘rebuild’ on gains from K P Oli’s India visit
Title: IPL 2018, DD vs SRH: Rishabh Pant’s heroics could not save Delhi Daredevils against Sunrisers Hyderabad

Additional Resource: Now that you are familiar with using Java SDK for fetching content from Contentstack, you can refer to the implementation guide of a sample web application using the Spring Boot framework.

Was this article helpful?

Thanks for your feedbackSmile-icon

On This Page

^