In the current lesson, we take a closer look at the most frequently used Java API classes. Svetlin Nakov will explain all about the Math class, how to generate random numbers, the need for BigInteger and BigDecimal in programming, and how to work with date and time in Java. We will also look at two of the main Java classes – Arrays and Formatter.
The Math class contains methods for performing basic numeric operations, such as round, min, max, abs, ceil, etc.. The Arrays class contains various methods which facilitate array manipulation. String.format() allows us to return the formatted string by given locale, format, and arguments.
In this lesson you will find many helpful examples and exercises, so make sure to practice what you’ve learned! That’s the only way to grasp the concept at hand.
BigInteger and BigDecimal are used for handling large and small numbers with great precision. BigInteger will throw an exception when the result is out of range. BigDecimal gives the user complete control over the rounding behavior.
Importing a single package allows us to work with the date and time API.
In this lesson you will find many helpful examples and exercises, so make sure to practice what you’ve learned!
As always, we advise you to pause the video right before the solving part of each problem and try to do the exercises on your own first. Then, if you have difficulties, just watch the provided solutions in the video. If you still have questions, we’re always here to help!
*The exercise descriptions are to be found in the PDF document at the end of this post.
This video covers the following topics:
1. The Judge System
- The Exception class
- Types of exceptions and their hierarchy
2. The Math Class
3. The Random Class
4. The Arrays Class
- Methods of the Arrays Class
- Example of Sorting an Array
5. String Formatter
6. BigInteger and BigDecimal
7. Java Date and Time
Watch the video and solve the problems. To better understand the material, do the coding exercises and implement the knowledge you acquired. Writing code is the only way to master the skill of code.
Submit your code in the SoftUni Judge System: