# Look up a number with Java

You can quickly see how the Number Lookup API works by looking up a number using the API.

In this guide you will learn:
1. How to [set up](#set-up-your-java-application) your Java application.
2. [Look up](#look-up-your-phone-number) your phone number.


## What you need to know before you start

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

* Set all Number Lookup API [configuration settings](/docs/number-lookup-api-v2/getting-started).
* [JDK 8](https://www.oracle.com/java/technologies/downloads/) or later 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.


## Set up your Java application

To quickly get started setting up a simple client application using the Java SDK:

1. If you haven't already, clone the [sinch-sdk-java](https://github.com/sinch/sinch-sdk-java) repository.
2. Navigate to the `examples/snippets/src/main/resources` folder.
3. Open the `config.properties` [file](https://github.com/sinch/sinch-sdk-java/blob/main/examples/snippets/src/main/resources/config.properties). Using the [access key credentials](https://dashboard.sinch.com/settings/access-keys) from your Sinch Build Dashboard, populate the following fields with your values:


| Field | Description |
|  --- | --- |
| SINCH_PROJECT_ID | The unique ID of your Project. |
| SINCH_KEY_ID | The unique ID of your access key. |
| SINCH_KEY_SECRET | The secret that goes with your access key.  **Note:** For security reasons, this secret is only visible right after access key creation. |


Note:
This tutorial uses basic authentication for testing purposes. We recommend using OAuth for authentication in a production environment. You can follow the steps in this guide, but use the code samples from [here](/docs/number-lookup-api-v2/api-reference/authentication/oauth) to use OAuth authentication instead.

1. Save the file.
2. Navigate to the `examples/snippets/src/main/java/numberlookup` folder and open the `Lookup.java` [file](https://github.com/sinch/sinch-sdk-java/blob/main/examples/getting-started/numbers/rent-first-available-number/src/main/java/numbers/Snippet.java).


Lookup.java
```java Lookup.java
// Use this code to look up a phone number using the Number Lookup API. 
/**
 * Sinch Java Snippet
 *
 * <p>This snippet is available at https://github.com/sinch/sinch-sdk-java
 *
 * <p>See https://github.com/sinch/sinch-sdk-java/blob/main/examples/snippets/README.md for details
 */
package numberlookup;

import com.sinch.sdk.SinchClient;
import com.sinch.sdk.domains.numberlookup.api.v2.NumberLookupV2Service;
import com.sinch.sdk.domains.numberlookup.models.v2.request.LookupFeatureType;
import com.sinch.sdk.domains.numberlookup.models.v2.request.NumberLookupRequest;
import com.sinch.sdk.domains.numberlookup.models.v2.response.NumberLookupResponse;
import com.sinch.sdk.models.Configuration;
import java.util.Collections;
import java.util.logging.Logger;
import utils.Settings;

public class Lookup {

  private static final Logger LOGGER = Logger.getLogger(Lookup.class.getName());

  public static void main(String[] args) {

    String projectId = Settings.getProjectId().orElse("MY_PROJECT_ID");
    String keyId = Settings.getKeyId().orElse("MY_KEY_ID");
    String keySecret = Settings.getKeySecret().orElse("MY_KEY_SECRET");

    // The phone number you want to lookup in E.164 format
    String phoneNumber = "PHONE_NUMBER";

    Configuration configuration =
        Configuration.builder()
            .setProjectId(projectId)
            .setKeyId(keyId)
            .setKeySecret(keySecret)
            .build();

    SinchClient client = new SinchClient(configuration);

    NumberLookupV2Service numberLookupService = client.lookup().v2();

    NumberLookupRequest request =
        NumberLookupRequest.builder()
            .setNumber(phoneNumber)
            .setFeatures(Collections.singletonList(LookupFeatureType.LINE_TYPE))
            .build();

    LOGGER.info("Lookup for: " + phoneNumber);

    NumberLookupResponse response = numberLookupService.lookup(request);

    LOGGER.info("Response: " + response);
  }
}
```

1. Before you can run the code, you need to update the following parameters with your own values:
| Parameter | Your value |
|  --- | --- |
| `number` | The phone number that you want to look up in [E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537) format. |
2. Save the file.


## Look up your phone number

Now you can execute the code and look up your phone number. Open a terminal to the `examples/snippets` folder and run the following command:

```shell
launcher numberlookup/Lookup
```

You should receive a response in your console with details about the phone number you specified.

Troubleshooting tip
If after running your app you receive a 5000 error response, you may have forgotten to save your file after adding your authentication values. This is an easy mistake to make! Try saving the file and running the app again.

## Additional resources

- [API specification](/docs/number-lookup-api-v2/api-reference/)