0

I'm new to Java development and android. I need to implement functionality for the currency convector. I need to know how to take information from the Internet (and periodically update it) and save it in a database.

Artur347
  • 15
  • 5
  • see this link: https://stackoverflow.com/questions/3202305/web-scraping-with-java – ssmraj21 Nov 12 '19 at 09:28
  • 1
    Sorry, this question is even broader than [the one you have already asked](https://stackoverflow.com/questions/58799719/how-to-implement-a-currency-converter) about this topic. – deHaar Nov 12 '19 at 09:29

1 Answers1

0

For making a currency converter, you would need to fetch the conversion rates in real time.these are a some ways to achieve this in your client-

1)Make ajax calls to apis(find some 3rd party service to fetch the conversion rates at real time , something like this - How do I get currency exchange rates via an API such as Google Finance? ) or alternatively use something like - (Web scraping with Java - which needs you to write your own back end which is responsible for making the google search and retrieving the exchange rates)

2)Whenever a conversion is executed by an end user, make a call to the decided apis in the step 1 and use the updated exchange rate to calculate and provide results- I would say, don't go for persisting the values in the database, as the foreign exchange market is constantly “live”, meaning that it never closes, even at night, so the exchange rate is always changing.(https://www.purefx.co.uk/foreign-currency-exchange-insight/view/do-exchange-rates-change-daily )

3) You could save the results in cache and update the cache at some periods of time using a cron job (maybe use Executorservice if you are writing a back-end in java) but in this case the rates might not be the latest ones and any satisfactorily "live" values means very noisy api calls at the server-side even when there are no users actively using the client.You might want to trade off accurate conversion with your resource usage and update the server side cache in intervals of 1 hour say)

4) Same apis could also be used to fetch the current rates ,if end user just wants to check the exchange rates

5)If you at all want to save the values in a database, you could use a key value type of database like Redis (https://redis.io/topics/client-side-caching)

Hope this helps.

soumitra goswami
  • 818
  • 6
  • 29