Java Class Libraries and Packages
- Categories Operators, Math Library, Java
Here we are going to learn above Java Class Libraries. You can watch our video to understand Java Class Libraries – Click Here
Q. 1 What is JCL?
Ans. Java Class Library (JCL) are dynamically loadable libraries that Java applications can call at run time. Some examples of JCL are java.lang, java.util, java.math, java.awt. etc.
Q. 2 What are packages? Why do we need packages?
Ans. Java contains an extensive library of pre-written classes (JCL) you can use in your programs. These classes are divided into groups called packages. A Package is a collection of related classes, providing access protection and name place management.
Java uses packages because
- It makes search and re-using packages and classes easier.
- It prevents naming conflicts. You can have a class with same name in two different package.
- Provides controlled access as you can specify protected and default access specifier for methods which work within a package
Q. 3 Which keyword is used to include packages in your source code?
Ans. import keyword is used to import built-in and user-defined packages into your java source file so that your class can refer to a class that is in another package by directly using its name.
Q. 4 Which package is automatically imported by Java?
Ans. “ java.lang“ Package is automatically imported by Java.
Q. 5 Name the package that contains – 1) BufferedReader 2) Scanner 3) Math?
Ans. 1) BufferedReader: java.io
2) Scanner: java.util
3) Math: java.lang
Q. 6 Which class is at root of Java Class Hierarchy?
Ans.
i) Object class is at the root class hierarchy and Class, instances of which represent classes at runtime.
ii) They are part of java.lang package.
Q. 7 What is JAR?
Ans.
- A java library is deployed in a jar file format.
- JAR or Java Archive is like a zipped file which contains many java classes and its associated resources such as images, text etc. into one file to distribute as libraries
Java Math Class :
The java.lang.Math class contains various methods for performing basic numeric operations such as the logarithm, cube root, and trigonometric functions etc. The various java math methods are as follows:
Method | Description |
---|---|
Math.abs() | It will return the Absolute value of the given value. |
Math.max() | It returns the Largest of two values. |
Math.min() | It is used to return the Smallest of two values. |
Math.round() | It is used to round of the decimal numbers to the nearest value. |
Math.sqrt() | It is used to return the square root of a number. |
Math.cbrt() | It is used to return the cube root of a number. |
Math.pow() | It returns the value of first argument raised to the power to second argument. |
Math.ceil() | It is used to find the smallest integer value that is greater than or equal to the argument or mathematical integer. |
Math.floor() | It is used to find the largest integer value which is less than or equal to the argument and is equal to the mathematical integer of a double value. |
Math.random() | It returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. |
Math.rint() | It returns the double value that is closest to the given argument and equal to mathematical integer. |
Math.log() | It returns the natural logarithm of a double value. |
Math.exp() | It returns E raised to the power of a double value, where E is Euler’s number and it is approximately equal to 2.71828. |
Math.sin() | It is used to return the trigonometric Sine value of a Given double value. |
Math.cos() | It is used to return the trigonometric Cosine value of a Given double value. |
Math.tan() | It is used to return the trigonometric Tangent value of a Given double value. |