Page 142 - CA_Blue( J )_Class9
P. 142

07                      MATHEMATICAL LIBRARY




                                                                                  METHODS














                            Learning Objectives



                      7.1 “java.lang” Package                             7.2 Mathematical Methods






                  To make programming in Java easy and simple, we need to create methods. Methods contain blocks of code written
                  to perform a specific task. Methods are generally used to solve complex problems; that doesn't mean they cannot
                  be used for simpler tasks. The advantage of using a method is that it can be reused. Methods are generally separate
                  from the main program, so if an error occurs in a method or if the code needs change, it is easy to make such changes.

                  There are two types of methods in Java: user-defined methods and library/system methods.

                                                          TYPES OF METHODS




                                      USER DEFINED                                 BUILT-IN/LIBRARY

                  1.  User-defined methods: These methods are defined by the programmer as per requirements of the program.
                  2.   Built-in/Library methods: These methods are already defined in the Java compiler and are stored as packages,
                     which are required to be imported before using them.
                  Let us learn about different types of built-in/library methods, which are string methods, mathematical methods,
                  graphic methods, etc.

                       7.1 "JAVA.LANG" PACKAGE
                  As you know, Java provides a wide variety of packages that contain a huge library of built-in classes. For example,
                  the “java.lang” package is a default package that contains classes and interfaces for the basic language functions.
                  In general, we have to import packages in our program to fetch the classes and interfaces that are defined in that
                  package. As “java.lang” is a default package, it is automatically imported by the Java compiler.


                       7.2 MATHEMATICAL METHODS
                  In  Java, the Math  class  provides  different types of  mathematical  methods.  To  use mathematical  methods  in
                  programs, we need to use the ‘Math’ class, which resides in the “java.lang” package.


                   140    Touchpad Computer Applications-IX
   137   138   139   140   141   142   143   144   145   146   147