Grails Cookbook - A collection of tutorials and examples

Maximum Value of Integer in Java

We've discussed in the previous post that an integer is a data type in Java, and we've determined that it's one of the main tools to use in calculations. Although with this information, it's necessary to remember that integers do not have a random large value, the Java Integer Maximum Value is 2,147,483,647. Check out below for more details.

Maximum Value of Long in Java

In Java, the data type integer is commonly used to calculate numbers. An integer with bigger range of values is efficient for some programs. Which will bring us to bits, an integer can only hold 32 bits whereas Java Long is capable of holding 64 bits. Now come to think of it, when you're creating a program that's required an integer exceeding 32 bits, you would realize Java Long is more effective to utilize. Understand that even though Java Long has bigger capacity than an integer, it still has a boundary limit for maximum value which is 9,223,372,036,854,775,807.

Check If String Contains Substringin Java

In Java, we can confirm if one String holds a specific substring. For example, we would like to check if the substring "rhapsody" is in the String "Bohemian rhapsody movie". Check out the examples on how to use Java String's contains method.

Read Text File in Java

When we are programming, we typically face the scenario where we need to read text files. For example, reading data from a file or reading configuration. There are some long methods, and there are some short methods. Below are some examples on how we can read text files in Java.

Float To Integer In Java

For most cases, we wish to work with Float than Integers because floats gives more precision and larger range of values. But sometimes there are reasons why we would want to work with integers with no decimal places. For example, when performance is very important, as working with integers is much faster than floats. This post will show some examples on how we could convert from float to Integer.

Check out the written examples of converting float to integer.

Double To Integer In Java

Now we use double for it's conviency on calculations and flexibility in precision. Like most of the time, some of us wants to take out the integral part of the output once we are finished with complicated computations. And now, we will discuss the process of converting java double to integer. Check out the examples given for extracting the integral portion from the output:

String Replace In Java

The Java String Replace is a method which can be applied if there's a new value of character or a String sequence that needs replacement. This method is valuable when you decide changes in Java String, and this post will introduce how to operate such method. By the end of this, we shall be able to use it.

Convert Java Float To String With 2 Decimal Place

Remember we've discussed about double and integer? Now let's go to java Float, and this topic will cover the conversion of java float to String with 2 Decimal Places. But first, we know that Java Float is a data type that's commonly used for representing numerical data with decimal places. Some of us are required to transform the value of float to String for our programs, this post will help you how to operate such process.

Check out the written examples below:

Java Math.Round()

The java.lang.Math class contains many static method for performing various math related functions. One useful utility is the Round() method, which is used to round a float or double number to the closest whole number representation. This post will give explain and give examples on how to use the Java Math.Round() method.

Java 5 For Loop String Array

No matter how advanced programming will be in the future, the basics will always be important. Cornerstone are basic data structure such as String Array, which is very simple to understand and use. One typical thing we wish to do with a String Array is to loop through all of it's values. Below is an example on how to loop to all values of a String Array, using for loop introduced in Java 5.