Java Language Package
A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time. Programmers also typically use packages to organize classes belonging to the same category or providing similar functionality.
* A package provides a unique namespace for the types it contains.
* Classes in the same package can access each other's package-access members.
The Java language package, a.k.a. java.lang, provides classes that are core to the Java language. If you are writing stand-alone Java applications, you are likely to encounter and use the classes and interfaces in this package first. The classes in this package are grouped in the following manner:
* Object: - The grand-daddy of all classes--the class from which all others derive.
* Data Type Wrappers: - A collection of classes used to wrap variables of a simple data type: Boolean, Character, Double, Float, Integer and Long. Each of these classes are subclasses of the abstract class Number.
* Strings: - Two classes that implement mutable and immutable character data. The String and StringBuffer Classes is a thorough lesson on the use of both types of strings.
* System and Runtime: - These two classes provide let your programs use system resources. System provides a system-independent programming interface to system resources and Runtime gives you direct system-specific access to the runtime environment. Using System Resources describes both the System and Runtime classes and their methods.
* Threads: - The Thread, ThreadDeath and ThreadGroup classes implement the multi-threading capabilities so important to the Java language. The java.lang package also defines the Runnable interface. Runnable makes it convenient for Java class to be active without subclassing the Thread class. Through an example-oriented approach Threads of Control will teach you about Java threads.
* Classes: - The Class class provides a runtime description of a class and the ClassLoader class allows you to load classes into your program during runtime.
* Math: - A library of math routines and values such as pi.
* Exceptions, Errors and Throwable: - When an error occurs in a Java program, the program throws an object which indicates what the problem was and the state of the interpreter when the error occurred. Only objects that derive from the Throwable class can be thrown. There are two main subclasses of Throwable: Exception and Error. Exceptions are a form of Throwable that "normal" programs may try to catch. Errors are used for more catastophic errors--normal programs should not catch errors. The java.lang package contains the Throwable, Exception and Error classes, and numerous subclasses of Exception and Error that represent specific problems.
* Processes: - Process objects represent the system process that is created when you use Runtime to execute system commands. The java.lang packages defines and implements the generic Process class and two of its subclasses that represent processes on specific platforms: UNIXProcess and Win32Process.
1. java.lang :— basic language functionality and fundamental types
2. java.util :— collection data structure classes
3. java.io :— file operations
4. java.math :— multiprecision arithmetics
5. java.nio :— the New I/O framework for Java
6. java.net :—networking operations, sockets, DNS lookups, ...
7. java.security :— key generation, encryption and decryption
8. java.sql :— Java Database Connectivity (JDBC) to access databases
9. java.awt :— basic hierarchy of packages for native GUI components
10. javax.swing :— hierarchy of packages for platform-independent rich GUI components
11. java.applet :— classes for creating an applet
Note*: - The java.lang package is available without the use of an import statement.
java.Lang Math
The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
Sno | Method & Description |
---|---|
1 | static double abs(double a) This method returns the absolute value of a double value. |
2 | static float abs(float a) This method returns the absolute value of a float value. |
3 | static int abs(int a) This method returns the absolute value of an int value. |
4 | static long abs(long a) This method returns the absolute value of a long value. |
5 | static double acos(double a) This method returns the arc cosine of a value; the returned angle is in the range 0.0 through pi. |
6 | static double asin(double a) This method returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2. |
7 | static double atan(double a) This method returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2. |
8 | static double atan2(double y, double x) This method returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). |
9 | static double cbrt(double a) This method returns the cube root of a double value. |
10 | static double ceil(double a) This method returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer. |
11 | static double copySign(double magnitude, double sign) This method returns the first floating-point argument with the sign of the second floating-point argument. |
12 | static float copySign(float magnitude, float sign) This method returns the first floating-point argument with the sign of the second floating-point argument. |
13 | static double cos(double a) This method returns the trigonometric cosine of an angle. |
14 | static double cosh(double x) This method returns the hyperbolic cosine of a double value. |
15 | static double exp(double a) This method returns Euler's number e raised to the power of a double value. |
16 | static double expm1(double x) This method returns ex -1. |
17 | static double floor(double a) This method returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer. |
18 | static int getExponent(double d) This method returns the unbiased exponent used in the representation of a double. |
19 | static int getExponent(float f) This method returns the unbiased exponent used in the representation of a float. |
20 | static double hypot(double x, double y) This method returns sqrt(x2 +y2) without intermediate overflow or underflow. |
21 | static double IEEEremainder(double f1, double f2) This method computes the remainder operation on two arguments as prescribed by the IEEE 754 standard. |
22 | static double log(double a) This method returns the natural logarithm (base e) of a double value. |
23 | static double log10(double a) This method returns the base 10 logarithm of a double value. |
24 | static double log1p(double x) This method returns the natural logarithm of the sum of the argument and 1. |
25 | static double max(double a, double b) This method returns the greater of two double values. |
26 | static float max(float a, float b) This method returns the greater of two float values. |
27 | static int max(int a, int b) This method returns the greater of two int values. |
28 | static long max(long a, long b) This method returns the greater of two long values. |
29 | static double min(double a, double b) This method returns the smaller of two double values. |
30 | static float min(float a, float b) This method returns the smaller of two float values. |
31 | static int min(int a, int b) This method returns the smaller of two int values. |
32 | static long min(long a, long b) This method returns the smaller of two long values. |
33 | static double nextAfter(double start, double direction) This method returns the floating-point number adjacent to the first argument in the direction of the second argument. |
34 | static float nextAfter(float start, double direction) This method returns the floating-point number adjacent to the first argument in the direction of the second argument. |
35 | static double nextUp(double d) This method returns the floating-point value adjacent to d in the direction of positive infinity. |
36 | static float nextUp(float f) This method returns the floating-point value adjacent to f in the direction of positive infinity. |
37 | static double pow(double a, double b) This method returns the value of the first argument raised to the power of the second argument. |
38 | static double random() This method returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. |
39 | static double rint(double a) This method returns the double value that is closest in value to the argument and is equal to a mathematical integer. |
40 | static long round(double a) This method returns the closest long to the argument. |
41 | static int round(float a) This method returns the closest int to the argument. |
42 | static double scalb(double d, int scaleFactor) This method returns d × 2scaleFactor rounded as if performed by a single correctly rounded floating-point multiply to a member of the double value set. |
43 | static float scalb(float f, int scaleFactor) This method return f × 2scaleFactor rounded as if performed by a single correctly rounded floating-point multiply to a member of the float value set. |
44 | static double signum(double d) This method returns the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero. |
45 | static float signum(float f) This method returns the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, -1.0f if the argument is less than zero. |
46 | static double sin(double a) This method returns the hyperbolic sine of a double value. |
47 | static double sinh(double x) This method Returns the hyperbolic sine of a double value. |
48 | static double sqrt(double a) This method returns the correctly rounded positive square root of a double value. |
49 | static double tan(double a) This method returns the trigonometric tangent of an angle.r |
50 | static double tanh(double x) This method returns the hyperbolic tangent of a double value. |
51 | static double toDegrees(double angrad) This method converts an angle measured in radians to an approximately equivalent angle measured in degrees. |
52 | static double toRadians(double angdeg) This method converts an angle measured in degrees to an approximately equivalent angle measured in radians. |
53 | static double ulp(double d) This method returns the size of an ulp of the argument. |
54 | static double ulp(float f) This method returns the size of an ulp of the argument. |
Primitive | Wrapper Class | Constructor Argument |
boolean | Boolean | boolean or String |
byte | Byte | byte or String |
char | Character | char |
int | Integer | int or String |
float | Float | float, double or String |
double | Double | double or String |
long | Long | long or String |
short | Short | short or String |