I am trying to figure out which 'Library' the BigDecimal Class resides in. When I read the referencing information it says this:
java.lang.Object
java.lang.Number
java.math.BigDecimal
which I don't totally understand. I am familiar with the java.lang.Math class. I assume this is entirely different - so here are my sub-questions:
First - am I correct in saying that the java Math class resides in the java.lang library
second - Does java.math.BigDecimal extend java.lang.Number, and if not, how are they related?
Third - is there a relationship to java.lang.math and java.math?
You speak of packages, not libraries.
A package is a place where many class files go. A class has two names. One simple name, Math
, and one qualified name with the package as a suffix, java.lang.Math
. This makes it possible for Java developers to use in their program many classes of the same simple name, say "Stream" for example. Many different "streams" may share the same simple name but be logically grouped into different namespaces, or packages if you will. A package must not be mapped to folders, but for most Java projects, that's how they are mapped and hence you may call this practice a "de facto standard".
A library is basically a file that contains compiled class files so that you can use these Java types in your program without having to reinvent the wheel.
The Java Development Kit (JDK) include a lot of libraries for you, most notably rt.jar
. On my Windows x64 machine, it is located here:
C:\Program Files\Java\jdk1.8.0_20\jre\lib
If you open rt.jar
using any program that knows how to open ZIP files, you'll find the compiled class file Math.class
in subfolder ./java/lang/
.
The answer to both your two first questions is yes. Let code be the judge:
// package java.lang, Java Platform API Specification, version 1.8
System.out.println(Math.class.getPackage());
// class java.lang.Number
System.out.println(BigDecimal.class.getSuperclass());