First, follow the Twilio Setup guide for creating a Twilio account and setting up environment variables with the proper credentials.
Then, install the Twilio Helper Library by following the installation steps.
Finally, send a message.
String accountSid = System.getenv("TWILIO_ACCOUNT_SID");
String authToken = System.getenv("TWILIO_AUTH_TOKEN");
Twilio.init(accountSid, authToken);
Message message = Message.creator(
new PhoneNumber("+15558881234"), // To number
new PhoneNumber("+15559994321"), // From number
"Hello world!" // SMS body
).create();
System.out.println(message.getSid());
For more information, please visit the Twilio SMS Java documentation.