Sitemap
Yalini Kathirgamanathan

Yalini Kathirgamanathan

Associate Software Engineer

Using the Java Library

3 min readJul 19, 2022

Java API

The Java API which is the set of code that included with the Java Development Environment. Java API include classes, interfaces, and user Interfaces. It enable developers to create and integrate several applications and websites. This API is full if code that we don’t even have to type, and just need to learn how to use it.

Array in Java

Arrays which are used to store multiple values in a single variable, instead of using separate variables for every value. Define the variable type with square brackets to declare an array, for example String[] cars; We have declared a variable which holds an array of strings.

ArrayList in java and why we need ArrayList

ArrayList which is a class in the Java API. This ArrayList class is a resizable array, that can be found in java.util package, the size of an array cannot be changed incase if you want to add or remove elements to/from an array, you have to create a new one.the elements can be added and removed from an ArrayList however you want that’s what makes the ArrayList unique from the Array.

ArrayList are objects where we can call methods on them and these methods are particular to the elements of the array, not the array itself. Here are some methods we can use for ArrayList.

ArrayList

add(Object elem) — it adds the object parameter to the list.

remove(int index) — it removes the object at the index parameter

remove(Object elem) — it removes this object (if it’s in the ArrayList).

contains(Object elem) — it returns ‘true’ if there’s a match for the object parameter

Get Yalini Kathirgamanathan’s stories in your inbox

Join Medium for free to get updates from this writer.

isEmpty() — it returns ‘true’ if the list has no elements

indexOf(Object elem) — it returns either the index of the object parameter, or -1

size() — it the number of elements currently in the list

get(int index) — it returns the object currently at the index parameter

Advance Boolean Expressions

Here we will learn about some advanced Boolean expression which you may use when you solve a complex type of problems

AND operator and OR operator (&&, ||)

The && operator is true only if both the sides of the && are true, therefore if the JVM sees that the left side of a && expression is false it doesn’t even check the what’s in the right side.

Similarly, with || operator, the expression is true if either side is true, So if the JVM sees that the left side is true it declares the entire statement to be true.

Not equals ( != and !)

The != operator is true only if both sides are not equal and ! Operator is used to invert the value (NOT). For an example, if we get a “true” result we can use ! Operator and change it to false.

Non-circuit operators (&, |)

They act the same as the short circuit operators but they push the JVM to always check both sides of the expressions.

Using the Java Library (Java API)

Every class in java belongs to a package and these packages have a name. To use a class in the API, we have to know which package the class is in.

To use a class in a package other than java lang, w must tell java the full name of the class. We can either use an import statement at the top of the source code or you can type the full name everyplace where you want to use the class in your code.

--

--