Willie  Beier

Willie Beier

1597528320

Common pitfalls of the BigDecimal class and how to avoid them

When doing business calculations in Java, especially when it comes to currencies, you would preferably use the_ java.math.BigDecimal_ class to avoid the problems related to floating-point arithmetic, which you might experience if using one of the two primitive types float or double (or one of their boxed type counterparts).

Indeed, the _BigDecimal _class contains a number of methods that can meet most of the requirements of common business calculations.

However, I would like to draw your attention to the most common pitfalls in the use of the _BigDecimal _class and show you how to avoid them, by using the regular _BigDecimal _API on the one hand and a new, customized class that extends _BigDecimal _on the other.

So, let’s start with the regular _BigDecimal _API.

Pitfall #1: The double constructor

Consider the following example:

BigDecimal x = new BigDecimal(0.1);
System.out.println("x=" + x);

Console output: x=0.1000000000000000055511151231257827021181583404541015625

#programming #java #coding #pitfalls #software-development

What is GEEK

Buddha Community

Common pitfalls of the BigDecimal class and how to avoid them

Yashi Tyagi

1617449307

CA Classes - Best CA Classes Online

Chartered Accountancy course requires mental focus & discipline, coaching for CA Foundation, CA Inter and CA Finals are omnipresent, and some of the best faculty’s classes have moved online, in this blog, we are going to give the best way to find online videos lectures, various online websites provide the CA lectures, Smartnstudy one of the best site to CA preparation, here all faculty’s video lecture available.

check here : ca classes

#ca classes online #ca classes in delhi #ca classes app #ca pendrive classes #ca google drive classes #best ca classes online

Willie  Beier

Willie Beier

1597528320

Common pitfalls of the BigDecimal class and how to avoid them

When doing business calculations in Java, especially when it comes to currencies, you would preferably use the_ java.math.BigDecimal_ class to avoid the problems related to floating-point arithmetic, which you might experience if using one of the two primitive types float or double (or one of their boxed type counterparts).

Indeed, the _BigDecimal _class contains a number of methods that can meet most of the requirements of common business calculations.

However, I would like to draw your attention to the most common pitfalls in the use of the _BigDecimal _class and show you how to avoid them, by using the regular _BigDecimal _API on the one hand and a new, customized class that extends _BigDecimal _on the other.

So, let’s start with the regular _BigDecimal _API.

Pitfall #1: The double constructor

Consider the following example:

BigDecimal x = new BigDecimal(0.1);
System.out.println("x=" + x);

Console output: x=0.1000000000000000055511151231257827021181583404541015625

#programming #java #coding #pitfalls #software-development

Joseph  Murray

Joseph Murray

1624048020

How to Find All the Classes of a Package in Java

In this article let’s take a look at how to find all classes of a package in Java

To find all classes of a package in Java we can use the ClassHunter of Burningwave Core library. So we start by adding the following dependency to our pom.xml:

XML

1

<dependency>2
    <groupId>org.burningwave</groupId>3
    <artifactId>core</artifactId>4
    <version>8.4.0</version>5
</dependency>

The next steps are the following:

  • retrieving the ClassHunter through the ComponentContainer
  • defining a regular expression that we must pass to the **ClassCriteria **object that will be injected into the **SearchConfig **object
  • calling the **loadInCache **method that loads in the cache all loadable classes of the indicated paths, then applies the criteria filter and then returns the **SearchResult **object which contains the classes that match the criteria

#java #classes #class #packages #package #how to find all the classes of a package in java

Target Class Does Not Exist In Laravel 8

As you all know laravel 8 already released and you can see there are many changes and update in laravel 8 version. many laravel users are facing issue in their new Laravel 8 version when they try to load their routes in web.php and they run into an Exception that says something like “Target class postController does not exist”.

Target Class Does Not Exist In Laravel 8

https://websolutionstuff.com/post/target-class-does-not-exist-in-laravel-8

#target class does not exist in laravel 8 #error #target class controller does not exist #target class not found #laravel #target class does not exist error solved

Joseph  Murray

Joseph Murray

1624063200

Creating an Immutable Class in Java

In this article, we’ll define the typical steps for creating an immutable class in Java and then implement it.

Steps to create Immutable class in java

  1. Make your class final, so that no other classes can extend it.
  2. Make all fields private so that direct access is not allowed.
  3. Don’t provide “setter” methods — methods that modify fields or objects referred to by fields.
  4. Special attention when having mutable instance variables
  5. Inside the constructor, make sure to use a clone copy of the passed argument and never set your mutable field to the real instance passed through the constructor.
  6. Make sure to always return a clone copy of the field and never return the real object instance.

#java #class #objects #immutable #creating an immutable class in java #immutable class in java