Provide Best Programming Tutorials

Using Classes from the Java Library

Java is an object oriented programming language, so in java programming, main two features are supported that is class and object. Basically we know that class is collection of objects and object is an instance of class. The uses of the java libraries of class spread the programmer efficiency by allowing computer programmer to focus on the functionality unique to their job. The library classes are generally planned with some typical usage pattern in observance, and the performance may be suboptimal if the actual usage differs. We deliver an approach for rewriting applications to use different customized versions of library classes that are generated using a combination of static analysis and profile information.

The java programming supports different type of classes as User defines class [A class which is created by user is known as user defined class.] and also there are some classes available with java system that provide some important support to the java programmer for developing their programming logic as well as their programming architecture with very smooth and very fine way. These classes are called Library Classes. In Java support thousands of library classes and also each class contains various types of functions. The availability of a large numbers of libraries of standardized classes is a vital reason for popularity of Java as a standard programming language in modern software world. The use of class libraries grows for the programmer productivity by allowing programmers to focus on the characteristics for that are unique to their application without being burdened with the unexciting task of building and debugging of the standard infrastructure. This java library classes are often designed and executed with some typical usage pattern in real life job profile.

The common case of unnecessary overhead occurs when single-threaded applications are used by library classes that are modified with multi-threaded clients in concept. For example, we find out that many Java programs frequently concatenate with strings via calls to the synchronized method/function like java.lang.StringBuffer.append()[Java compiler translate using +- operator on String manipulated objects is called StringBuffer.append()]. This points show that a lock must be developed for each call to this method, which is unnecessary for single-threaded applications. The performances of the programming concept can better-quality in such cases by rewriting the application to use convention, unsynchronized String Buffers.

Some major advantages present in java library classes are following.

Advantages of Library Classes in Java:

  • The type constraints are used to control where the java library classes can be replaced with routine versions without affecting type perfection of programs.

  • Static analysis is then used to control those applicants for which unused library functionality and synchronization can be removed safely from the allocated types.

  • The profile data is collected about the usage features of the customization candidates to determine where the allocation of custom library classes is likely to be cost-effective.

  • To base on the static analysis results and the profiling information the custom library classes are automatically generated from a template.

  • The bytecode of the client application is rewritten to use the generated custom classes. This bytecode rewriting is completely see-through to the programmer.

List of Library Classes in Java:

Library classes Purpose of the class
Java.io Use for input and output functions.
Java.lang Use for character and string operation.
Java.awt Use for windows interface.
Java.util Use for develop utility programming.
Java.applet Use for applet.
Java.net Used for network communication.
Java.math Used for various mathematical calculations like power, square root etc.

We will come across different library classes, which basically deal with input/output operation, which can be applied for characters and string manipulations.

Process to Input/Output operation in JAVA:

Java languages do not provide specific statement to input a value from the keyboard or to print the result on the visual display unit [VDU]. It uses the functions read() to accept a character from the keyboard and print() or println() to display the result on the screen. To input a character the function can be written as shown below:

a= System.in.read();

The Sytem.in.read() is an input stream belonging to the system class, which is, in turn an object of the input stream class available in Java.io Package.

To print the result the print function can be written as shown below:

System.out.print(x);

Here, System.out is an output stream of a system class, which is in turn an object of print stream class available in Java.io library package. Print stream class allow the users to display the result either by using print() or println() function.

Listing 1: Sample showing Example using package import java.util

import java.util.*;
class WordUtil{
    public static void main(String[] args){
        Scanner input=new Scanner(System.in);
        System.out.println("Enter Word: ");
        String word = input.next();
        char ch=word.charAt(0);
        String newWord=word+Character.toString(ch);
        System.out.println(newWord);
    }
} 

Listing 2: Sample showing Example using package import java.io

import java.io.*;
class WordImport{
    public static void main(String[] args){
       int a,b,c;
        InputStreamReader isr=new InputStreamReader(System.in);
       BufferedReader br=new BufferedReader(isr);
       Sytem.out.println(“Enter Digit”);
       a=Integer.parseInt(br.readLine());    
       Sytem.out.println(“Enter Digit”);
   b=Integer.parseInt(br.readLine());    
       c=a+b;
       System.out.println(“Sum of the data is..+c);        
    }
} 

In the above two example we show that this packages are using for communication of data from keyboard as well as display on the Visual Display Unit.

Now we know that Java has defined many library classes for the use of the computer programmer. They contain highly useful methods/function. We are familiar with number crunching and mathematics, now have a look at methods found in class Math

Methods Summary: Class Math

Library classes function Purpose of the class
abs(double a) Used to return the absolute value of the double value.
abs(float a) Used to return the absolute value of the float value.
abs(int a) Used to return the absolute value of an int value.
abs(long a) Used to return the absolute value of a long value.
acos(double a) Used to return the arc cosine of an angle, in the range of 0.0 through pi
asin(double a) Returns the arc sine of an angle, in the range of −pi/2 through pi/2
atan(double a) Used to return the arc tangent of an angle, in the range of −pi/2 through pi/2
atan2(double y, double x) Converts rectangular coordinates (x, y) to polar (r, theta)
cbrt(double a) Used to return the cube root of a double value
ceil(double a) Used to return the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer
cos(double a) Used to return the trigonometric cosine of an angle
cosh(double x) Used to return the hyperbolic cosine of a double value
exp(double a) Used to return Euler’s number e raised to the power of a double value
expm1(double x) Used to return ex−1
floor(double a) Used to return the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer
hypot(double x, double y) Used to return sqrt(x2 + y2) without intermediate overflow or underflow
IEEEremainder(double f1, double f2) Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard
log(double a) Used to return the natural logarithm (base e) of a double value
log10(double a) Used to return the base 10 logarithm of a double value
log1p(double x) Used to return the natural logarithm of the sum of the argument and 1
max(double a, double b) Used to return the greater of two double values
max(float a, float b) Used to return the greater of two float values
max(int a, int b) Used to return the greater of two int values
max(long a, long b) Used to return the greater of two long values
min(double a, double b) Used to return the smaller of two double values
min(float a, float b) Used to return the smaller of two float values
min(int a, int b) Used to return the smaller of two int values
min(long a, long b) Used to return the smaller of two long values
pow(double a, double b) Used to return the value of the first argument raised to the power of the second argument
random() Used to return a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
rint(double a) Used to return the double value that is closest in value to the argument and is equal to a mathematical integer
round(double a) Used to return the closest long to the argument
round(float a) Used to return the closest int to the argument
signum(double d) Used to return the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, and −1.0 if the argument is less than zero
signum(float f) Used to return the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, and −1.0f if the argument is less than zero
sin(double a) Used to return the trigonometric sine of an angle
sinh(double x) Used to return the hyperbolic sine of a double value
sqrt(double a) Used to return the correctly rounded positive square root of a double value
tan(double a) Used to return the trigonometric tangent of an angle
tanh(double x) Used to return the hyperbolic tangent of a double value
toDegrees(double angrad) Converts an angle measured in radians into an approximately equivalent angle measured in degrees
toRadians(double angdeg) Converts an angle measured in degrees into an approximately equivalent angle measured in radians
ulp(double d) Used to return the size of an ulp of the argument
ulp(float f) Used to return the size of an ulp of the argument

Conclusion

So, from the above data we can find that the Library Classes in Java is totally very much important to us for developing a nice and standard software programming. The upper methods are very much helpful for all java programmers.

Leave a Reply

Close Menu