# Send an SMS Message with Java

Note:
Before you can get started, you need the following already set up:

- 
- [JDK 11 or later](https://www.oracle.com/java/technologies/downloads/) and a familiarity with how to create a new Java application.
- [Gradle](https://gradle.org/install/) and a familiarity with how use the Gradle build tools.


Learn how to quickly send SMS messages in a Java application with the Sinch API.

Steps:
1. [Install](#install-the-sinch-java-library) the Sinch Java library.
2. [Send](#send-your-first-sms-message) your first SMS message.


## Install the Sinch Java library

1. If you don't have a java project already, create one:

```shell
gradle init
```
2. Select application, and then accept all default values.
3. Paste the following code into your `build.gradle` file:

```javascript
dependencies {
implementation 'com.sinch:sdk-sms:1.0.5'
implementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.31'
}

//Sinch SDK is hosted by maven so make sure you have MavenCentral in your repositories
repositories {
    mavenCentral()
}
```


## Modify the application

Open `App.java` in your favorite editor and copy/paste in this sample. Remember to keep your own `package com.`

Send an SMS message
```java Send an SMS message

// Find your serviceplan_id and Token at https://dashboard.sinch.com/sms/api
// Install the Java helper library at https://developers.sinch.com/docs/sms/sdks/java-legacy/
// Find your sinch number at // https://dashboard.sinch.com/numbers/your-numbers/numbers
import com.sinch.xms.*;
import com.sinch.xms.api.*;

public class App {
	private static final String SERVICE_PLAN_ID = "YOUR_servicePlanId";
	private static final String TOKEN = "YOUR_API_token";
	private static ApiConnection conn;

	public static void main(String[] args) {
		String SENDER = ""; //Your sinch number
		String[] RECIPIENTS = { "" }; //your mobile phone number

		ApiConnection conn = ApiConnection
								.builder()
								.servicePlanId(SERVICE_PLAN_ID)
								.token(TOKEN)
								.start();
		MtBatchTextSmsCreate message = SinchSMSApi
										.batchTextSms()
										.sender(SENDER)
										.addRecipient(RECIPIENTS)
										.body("Test message from Sinch.")
										.build();
		try {
			// if there is something wrong with the batch
			// it will be exposed in APIError
			MtBatchTextSmsResult batch = conn.createBatch(message);
			System.out.println(batch.id());
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		System.out.println("you sent:" + message.body());
	}
}
```

### Fill in your parameters

1. Assign the following parameters in `App.java` with your values:
| Parameter | Your value |
|  --- | --- |
| `SERVICE_PLAN_ID` | The service plan ID found on your [Sinch Build Dashboard](https://dashboard.sinch.com/sms/api/rest). |
| `TOKEN` | The API token found on your [Sinch Build Dashboard](https://dashboard.sinch.com/sms/api/rest). Click Show to reveal your API token. |
| `SENDER` | Any number you've assigned to your Sinch account. Find the number on your [Sinch Build Dashboard](https://dashboard.sinch.com/sms/api/rest) by clicking the service plan ID link and scrolling to the bottom of the page. |
| `RECIPIENTS` | The number to which you want to send the SMS message. |
Double check that the region is correct on your base URL. Learn more about [regional options here](/docs/sms/api-reference#base-url).
2. Save the file.


## Send your first SMS message

Now that your Java project is ready and the Sinch SDK is installed, send a text message to your mobile phone.

To send the message, run the following code:

```Shell
gradle run
```

You should receive an SMS message to the number you assigned to your `RECIPIENTS` parameter.

## Next steps

The code used in your Java application sends a POST request to the Sinch API `/batches` endpoint to send the SMS message. Click [here to read more about the batches endpoint](/docs/sms/api-reference/sms/batches).

- [Learn how to recieve SMS](/docs/sms/getting-started/java/receive-sms)


## Additional resources

- Explore the [API specification](/docs/sms/api-reference/) to test more endpoints.