Level up your Twilio API skills in TwilioQuest, an educational game for Mac, Windows, and Linux. Download Now
Build the future of communications.
Start building for free

Java posts

  • By Matthew Gilliard
    How to send SMS at scale with Twilio Title: How to send SMS at scale with Twilio

    If you want to send a single SMS using Twilio you'll need a Twilio account, a phone number to send them from, and of course you'll need to know the destination phone number and the content of the message. Once you have these you can send your message with a single API call either with a direct HTTP request, or using any of our helper libraries. Check out our Programmable SMS Quickstarts for more details.

    What if you need to send a hundred messages? Or a thousand? Or even more? In this post I'll talk through the challenges you may face as you scale up and how to get past them. Code samples will be in Java but the same principles apply with any programming language.

    Sending a single SMS

    Sending one SMS with Java is covered in this blog post. Feel free to go and read it, …

    Read More
  • By Liz Moy
    Build a Stock Quote WhatsApp Bot with Java and Twilio Build a Stock Quote WhatsApp Bot with Java and Twilio

    Photo courtesy of Pixabay (CC BY 2.0)

    Whether you are a seasoned investor, downloaded RobinHood when the r/wallstreetbets events overtook the news cycle, or are keen to play with a new API, you can never have too many methods of checking the latest stock prices. You will build a bot for WhatsApp that will message a user basic stock quote information when they send in a valid ticker symbol.

    You’ll use the Finnhub.io Stock API to do so. They also have a Forex and Crypto API, so check those out if you want to add on to what you will build here.


    • A Twilio Account - sign up for a free one here and get $10 when you upgrade your account
    • Java 8 or above (for simpler installation, check out SDKMAN! This tutorial uses version 11.0.10.hs-adpt.
    • API Key for the Finnhub.io API -  Register for a free …
    Read More
  • By Matthew Gilliard
    Sending SMS with Java with Twilio Title: Sending SMS with Java and Twilio

    Did you know you can code a Java app in under 5 minutes to send an SMS using the Twilio API? Probably closer to 2, once you've got the tools installed. You'll need:

    The easiest way to call the Twilio API is with the Twilio Java Helper Library. In this I'll give examples using the Apache Maven build tool which will download and manage the dependency and packaging the project. You can get up to speed with Maven in 5 Minutes, …

    Read More
  • By Matthew Gilliard
    Receiving and Responding to SMS with Java and Twilio Title: Receiving and Responding to SMS with Java and Twilio

    If you're wondering how to send SMS from Java code, we've got you covered already. However, people are increasingly expecting to be able to converse with companies and services rather than just get a never-ending stream of notifications. To build really engaging and interactive apps you're going to want to respond to incoming messages too.

    To do that, you will need to configure a URL in your Twilio console. Incoming messages will trigger HTTP requests to that URL, and the response to those webhook requests will determine what happens next, including sending responses. Responses should be written in an XML dialect called Twilio Markup Language, or TwiML.

    In this post I'll walk you through setting up a web server using Spring Boot to do just that.

    Getting set up

    Before we get started, you'll need:

    Read More
  • By Matthew Gilliard
    Comment Lire et Comprendre la Stacktrace en Java ? lire-comprendre-stacktrace-java

    Lorsque quelque chose ne tourne pas rond dans une application Java en cours d'exécution, le premier indice est souvent l'impression de lignes à l'écran qui ressemblent à peu près à ce qui suit :

    Exception in thread "main" java.lang.RuntimeException: Something has gone wrong, aborting!
        at com.myproject.module.MyProject.badMethod(MyProject.java:22)
        at com.myproject.module.MyProject.oneMoreMethod(MyProject.java:18)
        at com.myproject.module.MyProject.anotherMethod(MyProject.java:14)
        at com.myproject.module.MyProject.someMethod(MyProject.java:10)
        at com.myproject.module.MyProject.main(MyProject.java:6)

    Ceci est une Stacktrace, et dans ce blog post, je vais vous expliquer de quoi il s'agit, comment ils sont générés et comment les lire et les comprendre. Si ça à déjà l’air pénible, lisez la suite...

    Anatomie d'une Stacktrace

    Habituellement, une Stacktrace s'affiche lorsqu'une Exception n'est pas gérée correctement dans le code. Il peut s'agir d'un des types d'exception intégrés de base dans Java, ou d'une exception customisée créée par un programme ou une librairie.

    La Stacktrace contient le type d'exception et un message, ainsi qu'une liste de tous les …

    Read More
  • By Diane Phan
    How to Send an SMS with Java header - How to Send an SMS with Java

    Twilio is all about powering communication and doing it conveniently and fast in any language.  

    With the help of Twilio and Java, you can deliver a quick message to someone without having to pick up your mobile device.

    In this article, you'll be using your handy dandy command line and writing a couple of lines of Java code to send an SMS in an insanely fast manner. So why wait? Let's get started!

    Tutorial requirements

    • A free or paid Twilio account. If you are new to Twilio get your free account now! (If you sign up through this link, Twilio will give you $10 credit when you upgrade.)
    • Some prior knowledge of Java or a willingness to learn.
    • A smartphone with active service, to test the project


    We’ll start off by creating a directory to store the files of our project. Inside your favorite terminal, enter:

    $ …
    Read More
  • By Matthew Gilliard
    Handling Webhooks with Java, Spring Cloud Function and Azure Functions Title: Handling Webhooks with Java, Spring Cloud Function and Azure Functions

    When you want to send an SMS or a WhatsApp message using Twilio's API, the programming model is straightforward: You call the API and the message gets sent. Responding to incoming messages is a different question. When the message arrives Twilio needs to find out how to handle it, and the mechanism we use is the Webhook. You configure your Twilio number with a URL and the platform makes a request to it passing some details about the incoming message - your app's response decides what happens next.

    This means your app needs a public URL, which in turn means that you need some hosting. In the last few years serverless platforms have become popular for this, because they alleviate many of the pains of hosting. You provide code, which can handle an individual request, and the platform takes care of routing, scaling and most other concerns. Java's no …

    Read More
  • By Matthew Gilliard
    Building Voicemail with Twilio and Java Building Voicemail with Twilio and Java

    One useful and common way to use Twilio is to create a phone number which forwards to your real phone. You can hand out the Twilio number to colleagues or customers and take business calls on your personal phone without worrying about handing out your real phone number. This also gives you a lot of options for how to handle these calls - you have the full power of Twilio at your disposal.

    In this post I'll show you how to create a voicemail system that will jump in when your cell number is busy, or when you don't answer the call. It will play a message to your caller, then record their message and text you a link to the recording when it's done.

    Primer: How Twilio Handles Calls

    When someone dials your Twilio number, an HTTP request is sent to a URL that you provide. The web server …

    Read More
  • By Matthew Gilliard
    How to make asynchronous API requests in Java using CompletableFutures Title: How to make asynchronous API requests in Java using CompletableFutures

    Java 8 was released in 2014, and introduced a raft of new language features such as Lambdas and the Streams API. A lot has happened since 2014 - Java is now at version 15, but industry surveys consistently report 8 as the most widely-used version, with very few developers using 7 or lower.

    In October this year, the Twilio Java Helper Library was updated to use Java 8 features in release 8.0.0. This new major version reflects the fact that the library no longer supports Java 7.

    One Java 8 API which sometimes gets overlooked is the CompletionStage API, usually accessed through the CompletableFuture class. The CompletionStage API lets programmers define pipelines of asynchronous operations for data, and handles the asynchronous behaviour for you. You define what you want to happen, and Java takes care of when it can happen.

    In this post I'll show how you …

    Read More
  • By Matthew Gilliard
    What's new for developers in Java 15? Title: What's new for developers in Java 15?

    [header image credit: NASA Astronomy Picture Of the Day, Sep 15 2020]

    Happy Java 15 release day! This release marks three years since the start of the six-monthly release schedule and I am still appreciating the speed of new features and the insight it's giving into what's coming up in Java's future.

    In Java 15 there are improvements to tooling, security, cross-platform consistency, efficiency and performance. You can read the full release notes and the list of major features, which are designated a Java Enhancement Proposal (JEP) number. In this post I've selected a few features which I think are interesting for developers.

    The features I've selected are a mix of fully-released and "preview" features (more on these later).

    How to use these features

    You can download Java 15 from https://jdk.java.net/15/ - downstream builds will be available from places like AdoptOpenJDK soon after. You can also install it …

    Read More
  • Newer
    Sign up and start building
    Not ready yet? Talk to an expert.