Java.util.* versus API
util*
In the Java programming language, a utility class is a class that provides common functionality that is not provided by the language itself; it is stateless class. Utility classes are also known as helper classes. They are an efficient way to create methods that can be reused. the code we need over and over again can be placed in util.* class. You invoke them through import jave.util.* If you want to be more specific, you can specify something like (import java.util.Arrays) is an example.
API
Java API stands for Java Application Programming Interface. It is usually a prewritten package, class or interface complete with its own constructors, fields, methods and allows access to the functionality of Java.
Get Alex Zuniga’s stories in your inbox
Join Medium for free to get updates from this writer.
I will discuss classes later on.
API are some kinds of integrators or connections or links between java as a language (and its connection to MySQL or mongo database for example). On the web you can link to Facebook, twitter or other apps through the APIs provided by them.
I just want to clear this up before I venture on simple codes using java utility versus manually programming the same utility. I am using Arrays as an example.
import java.util.Arrays;//TAKE NOTE of USING Arrays utility. You can also use * for all
import java.util.Scanner;//TAKE NOTE of Scanner utility to faciliate input of data from screen.
public class Myarray{
public static void main(String[] args){
//An array of people
int[] people = new int[10];
int amount;
for(int i = 0; i<10; i ++)
{
//int row,r;
//creating object
Scanner s = new Scanner(System.in);
// entering the number of row
System.out.print("How many candies a person took : ");
amount = s.nextInt();
people[i] = amount;
}
for(int person : people){
System.out.println(person);}
}
}
//this project populates the array data via input from screen.import java.util.Arrays;
public class Mysorting{
public static void main(String[] args){
int[] myarray = {4, 9, 45, 31, 6, 5};
Arrays.sort(myarray);
for(int x : myarray){
System.out.println(x);
}
}
}
// using the same Arrays utility, you can automatically sort your data from min to max//This time we will not use the utility array. We will manually code the sort fucntion.
public class Mysorting{
// Main driver method
public static void main(String[] args)
{
// Custom input array
int arr[] = { 4, 3, 2, 1 };
// Outer loop
for (int i = 0; i < arr.length; i++) {
// Inner nested loop pointing 1 index ahead
for (int j = i + 1; j < arr.length; j++) {
// Checking elements
int temp = 0;
if (arr[j] < arr[i]) {
// Swapping
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
// Printing sorted array elements
System.out.print(arr[i] + " ");
}
}
}So there is the difference and ease of programming using the utilities provided by java. But this doesn’t mean we need to abandon the learning of basic algorithms like sort().










