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
    5 ways to make HTTP requests in Java 5 ways to make HTTP requests in Java

    [header image credit: Iron in the Butterfly Nebula, NASA Astronomy Picture of the Day July 21 2020 (modified)]

    Making HTTP requests is a core feature of modern programming, and is often one of the first things you want to do when learning a new programming language. For Java programmers there are many ways to do it - core libraries in the JDK and third-party libraries. This post will introduce you to the Java HTTP clients that I reach for. If you use other ones, that’s great! Let me know about it. In this post I’ll cover:

    Core Java:
    • HttpURLConnection
    • HttpClient
    Popular Libraries:
    • ApacheHttpClient
    • OkHttp
    • Retrofit

    I’ll use the Astronomy Picture of the Day API from the NASA APIs for the code samples, and the code is all on GitHub in a project based on Java 11.

    Core Java APIs for making Java http requests

    Since Java 1.1 there has …

    Read More
  • By Matthew Gilliard
    Take control of incoming calls with Twilio, Java and Google Sheets Take Control of Incoming Calls with Twilio, Java and Google Sheets

    We understand how phone numbers work, don’t we? Someone calls your number and your phone rings. But wouldn't it be nice to have more control - to screen incoming calls and treat them differently depending on who is calling?

    Gif of a man answering a phone call

     

    In this post I’ll show you how to set up a Twilio phone number to handle incoming calls using a Spring Boot app. Your app will look up the caller in a Google Sheet to decide what to do. There are options for blocking calls or forwarding them to other numbers. Any changes made to the Google Sheet will take effect immediately. The sheet looks like this:

    Screenshot of a Google Sheet with Columns for "Caller's Number" and "Action". Action is either "Block" (with a message) or "Forward" (to another phone number)

    Once you’ve set this up you can hand out your Twilio phone number freely, knowing that you can easily block unwanted callers, or redirect people to any other number depending on who they are.

    To set this up you will need:

    • A Google account …
    Read More
  • By Matthew Gilliard
    Three ways to use Jackson for JSON in Java Three ways to use Jackson for JSON in Java

    If you’re working in a statically-typed language like Java then dealing with JSON can be tricky. JSON doesn’t have type definitions and is lacking some features which we would like - there’s only strings, numbers, booleans and null, so to store other types (like dates or times) we’re forced to use a string-based convention. Despite its shortcomings, JSON is the most common format for APIs on the web so we need a way to work with it in Java.

    Jackson is one of the most popular Java JSON libraries, and is the one I use most frequently. In this post I’ll pick a fairly complex JSON document and three queries which I want to make using Jackson. I’ll compare three different approaches:

    1. Tree model
    2. Data binding
    3. Path queries

    All the code used in this post is in this repository. It’ll work with Java 8 onwards.

    Other Java Libraries …

    Read More
  • By Matthew Gilliard
    Two ways to use Gson for JSON in Java Two ways to use Gson for JSON in Java

    If you’re working in a statically-typed language like Java then dealing with JSON can be tricky. JSON doesn’t have type definitions and is lacking some features which we would like - there’s only strings, numbers, booleans and null, so to store other types (like dates or times) we’re forced to use a string-based convention. Despite its shortcomings, JSON is the most common format for APIs on the web so we need a way to work with it in Java.

    Gson is one of the most popular Java JSON libraries. In this post I’ll pick a fairly complex JSON document and three queries which I want to make using Gson. I’ll compare two different approaches:

    1. Tree model
    2. Data binding

    All the code used in this post is in this repository. It’ll work with Java 8 onwards.

    Other Java Libraries for working with JSON

    The most popular Java libraries for …

    Read More
  • By Matthew Gilliard
    Open and Click Tracking for Email using Java and Twilio SendGrid Open and Click Tracking for Email using Java and Twilio SendGrid

    I covered sending emails from Java using the Twilio SendGrid API before, but for important emails it can be vital to know whether recipients have opened your mail, and whether they have clicked on the links in it. You can do this using the SendGrid Event Webhook, which works by sending HTTP requests to a URL you provide. In this post I’ll show how to configure this with Twilio SendGrid and build a Java web application to handle the webhooks and record your recipients’ activity.

    Before you start

    You will need

    • Java - version 8 or newer. I like to use SDKMAN! to manage Java installations
    • Ngrok
    • A Twilio SendGrid account - sign up here if you don’t have one already.

    Creating the application

    If you prefer to skip the coding and instead try things out you can find the code for this application on GitHub, and …

    Read More
  • By Matthew Gilliard
    Validating phone numbers in a Spring Boot app using the Twilio Lookup API Validating phone numbers in a Spring Boot app using the Twilio Lookup API

    Many user registration flows these days require a user to provide a phone number, either for two-factor authentication or to provide notifications and updates.

    To check that the number provided by your user is valid, you might reach for a regular expression, but that won’t be reliable - phone numbers are complicated, and it won’t tell you if the number provided is actually reachable. There are multiple levels of validation possible - in this post I’ll show how to use the Twilio Lookup API to check if a real phone number is real.

    The demo application will use Spring Boot and I will show how to use the Bean Validation framework to create a @ValidPhoneNumber annotation that can be used like you would @NotNull.

    Starting out

    What you will need before you start

    • A Twilio account. Sign up using this link and you can get an extra $10 …
    Read More
  • By Matthew Gilliard
    How to build a Conference line with Twilio and Java How to build a Conference line with Twilio and Java

    Another conference call, another app, another PIN, another log-in. Joining conference calls should be as easy as dialing a phone number, without the hassle of so many extra digits. This post will show how you can build a conference line that anyone and everyone can join, using Twilio with Java and Spring Boot.

    Java Development Environment Setup

    Start by making sure you have the right software installed that you'll need to use for the rest of this post. You will need:

    • Java - You’ll need at least Java 8. My preferred way to install it is using SDKMAN!
    • A free Twilio account and a Twilio phone number

    Starting out with Spring Boot

    You can use SDKMAN! to install the Spring Boot cli tool with sdk install springboot. Use this to create a new project in an empty directory with:

    spring init \
      --dependencies web \
      --build maven \
      --groupId …
    Read More
  • By Aaron Alaniz
    Implementa tu Propia Aplicación de Vídeo Conferencia en Menos de Cinco Minutos programmable-video-translate-conference

    Nos complace anunciar que hemos creado tres aplicaciones de vídeo conferencia en código abierto, una para iOS, otra para Android y una tercera en ReactJS para Web. Sea porque estás construyendo una solución de colaboración para salud, educación o en vídeo en general, estas aplicaciones pueden acelerar el desarrollo al proporcionar una base funcional implementada en la nube en minutos. Además, pueden actuar de referencia para todo desarrollador que quiera mostrar las posibilidades que tiene el video programable. Las aplicaciones están disponibles en Github bajo licencia Apache 2.0:

    Read More
  • By Aaron Alaniz
    Deploy your own video collaboration app in five minutes or less Deploy your own video collaboration app in 5 minutes or less

    Today we are excited to announce that we are open sourcing three video collaboration applications, one for iOS, one for Android, and a ReactJS one for the Web. Whether you are building a healthcare, education, or general video collaboration solution, these apps can accelerate development by providing you with a fully functioning video app that can be deployed to the cloud in minutes. In addition, they provide a canonical reference for developers building out their communication solutions by showcasing the Programmable Video capabilities. These applications are available today on Github under the Apache 2.0 license:

    At Twilio we strive to build a reliable, extensible platform so that our customers can build high quality communication experiences in their applications. Our Video SDKs provide the API building blocks for mobile and web developers to create custom communications experiences in their apps. We believe …

    Read More
  • By Matthew Gilliard
    Using SDKMAN! to work with multiple versions of Java Using SDKMAN! to work with multiple versions of Java

    If you code in Java, you might be coding against Java 11, or 8, or maybe an even older version. You may also be prototyping code against newer versions of Java, the current version is 13. Java 14 will be released this month, and 15 later this year. At the same time, you might be investigating different builds of OpenJDK - there are several free alternatives. I use AdoptOpenJDK’s builds of OpenJDK which is an increasingly popular choice according to the JVM Ecosystem Report 2020.

    You could also be trying out different build tools like Maven and Gradle. I use both, depending on the project.

    Put bluntly, managing all this can be difficult. It’s not impossible to manage by hand, but it’s fiddly and if you get it wrong the error messages can be hard to understand.

    Enter SDKMAN! It’s a tool for managing the installation and selection …

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