Exchange Rate API Java Documentation

How To Use Our Java Exchange Rates API

We offer an easy to use, accurate and reliable currency conversion API for Java that's perfect for both personal and professional use.

Fetching exchange rates using our Java exchange rates API is as easy as making GET requests. This means you can easily integrate our API into your Java project however you'd prefer.

For more details on the different types of request we support please see our Main Documentation.

Alternatively simply use the Java library code below to get started with our currency data as fast as you can copy & paste!

You'll need to sign up for a free account to get your API key. Visit this link to get started.

Simple Java Currency Conversion Example

This example relies on Google's GSON library.

// Setting URL
String url_str = "";

// Making Request
URL url = new URL(url_str);
HttpURLConnection request = (HttpURLConnection) url.openConnection();

// Convert to JSON
JsonParser jp = new JsonParser();
JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
JsonObject jsonobj = root.getAsJsonObject();

// Accessing object
String req_result = jsonobj.get("result").getAsString();

This will return the exchange rates from USD to all other currencies we support:

	"result": "success",
	"documentation": "",
	"terms_of_use": "",
	"time_last_update_unix": 1585267200,
	"time_last_update_utc": "Fri, 27 Mar 2020 00:00:00 +0000",
	"time_next_update_unix": 1585353700,
	"time_next_update_utc": "Sat, 28 Mar 2020 00:00:00 +0000",
	"base_code": "USD",
	"conversion_rates": {
		"USD": 1,
		"AUD": 1.4817,
		"BGN": 1.7741,
		"CAD": 1.3168,
		"CHF": 0.9774,
		"CNY": 6.9454,
		"EGP": 15.7361,
		"EUR": 0.9013,
		"GBP": 0.7679,
		"...": 7.8536,
		"...": 1.3127,
		"...": 7.4722, etc. etc.

Please see our main documentation for further information on this query type & error response details.

Additionally, please email us if you'd like to submit a better code example, we'll credit you!