Beginners Programs :

Simple Java Program Internet Speed Test | Java Programs

Java program to calculate the internet speed test or connectivity. This is a simple java program to calculate the broadband speed along with detailed explanation. If you have any doubts just do leave a comment here.

What  exactly is internet speed?

Internet speed also known as bandwidth is the speed in which your data is transferred from your device to the internet and vice versa. There are two main types of bandwidth speed.

  1. Download speed – Download speed implies the speed by which information or data is travelling from the web to the device. The data can be of any kind, photos, videos, movies, anything. Higher the download speed, faster the information is received in your device.
  2. Upload speed – It implies the speed at which information or data travels from your device to the internet.

So how is the data speed measured?

Data now a days is measured mostly in terms of Mb or Gb. A few years back even Kb had some relevance left however with changing times the data became cheap and the gradual increase in bandwidth changed everything.

Kb = Kilobytes , Mb = Megabytes, Gb = Gigabytes

You might wonder what are these bytes? Well bytes are small packets of data and millions of such bytes make a megabyte.

How to check the internet speed?

There are several ways of finding the internet speed including executing a shell command on windows but that is a little complicated, especially when we have easier alternatives.

Java source code for internet speed test

To check the internet speed one can –

  1. Open your internet browser.
  2. Search for https://www.speedtest.net/
  3. Click the Go button(at least that’s what it was at the time of writing this article).
  4. Get to know the speed.

You see, getting to know the internet speed is easier than ever, but what about finding it in Java. Let’s find it out.

Java Program for Calculating Bandwidth Speed

There are certain steps to be followed so that clarity is maintained throughout the process of writing a code and makes it easier to arrive at our desired output.

First step is to understand the problem statement properly. After this, we need to see if there are any constraints mentioned in our problem.

Then, we need to fix on all our requirements and inputs.

Later, we’ll have to determine our expected output. Finally, we will write the logic and solution to determine the output based on gathered input.

Our problem statement is to find the speed of internet. For this, our required inputs will be data in mega bytes (d) and time in minutes (t). We will make use of Scanner class in Java to read these inputs at runtime. Since, they are generally integers, which are primitive datatype, we can make use of Scanner class as below:

Our expected output is speed of internet of double type. With inputs gathered in hand, we’ll now focus on the solution and main logic of the code.

Speed of internet= Data per time

But there are two units of measuring speed. One is in kilobytes per second or megabytes per second. Our input is taken in the format where, data is in megabytes and time is in minutes we’ll measure in the form kilobytes per second.

1 megabyte = 1000 kilobytes

1 minute = 60 seconds

Therefore, the formula finally used for finding the speed of the internet will be

double s=(d*1000)/(t*60);

This is our output speed of the internet of the form kilobytes per seconds which will be stored in the output variable (s). This is then displayed in our output console screen.

Output: