Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

This project contains a "hello world" sentiment analysis example.

The pom.xml file defines a main class and some properties that allow us to run via Maven in the command line. The NaturalLanguageHelloWorld class fetches the sentiment analysis of a hard-coded string.

String text = "I love coding!";
Document doc = Document.newBuilder()

LanguageServiceClient languageService = LanguageServiceClient.create();
Sentiment sentiment = languageService.analyzeSentiment(doc).getDocumentSentiment();

System.out.println("Score: " + sentiment.getScore());

To run this example, first make sure your GOOGLE_APPLICATION_CREDENTIALS environment variable is set and that you've enabled the Natural Language API, and then execute this command:

mvn clean compile exec:java

Learn more at

You can’t perform that action at this time.