Page 136 - Computer science 868 Class 12
P. 136

4.7 JAVA COMPILATION PROCESS                                                      Program
              Java is a platform-independent programming language. Its execution is divided into
              two steps:                                                                          (Source Code

              Step 1:  The program code is compiled into bytecode through an Operating System
                      independent compiler.
              Step 2:   This  bytecode needs to be converted into machine code to execute on        Compiler
                      an individual device. This is done by Java Virtual Machine(JVM). The JVM
                      performs all the tasks of the Java run-time system. It loads the Java class
                      file and interprets the compiled bytecode.
                                                                                                    Bytecode
              4.7.1 Java Compiler and Interpreter
              The Java compiler, also known as JAVAC, converts the Java program codes (source
              code) into executable files (Java bytecode). The extension of Java source code is        JVM
              .java. The Java compiler (JAVAC) is used to convert the java source file to a class file      (Window, MacOS, Linux)
              under the extension .class.

              This is quite different from other languages such as C/C++. As in C/C++, the source
              file is converted directly to the machine code using a compiler. But in Java, after
              the compiler translates it to a .class file, the Java Virtual Machine which acts as an   Machine Code
              Interpreter converts it to Machine Language. JVM is designed in such a way that it
              can read the source program and translate the source code line by line.
              The Java compiler translates the entire program together. It generates the intermediate object code. If there is any error,
              the  errors are shown at once at the end of the compilation, which unless debugged the .class file will not be created.
              The advantage of Java over other OOP languages is that the bytecode that is generated by the compiler can run on any
              platform of operating systems where there is JVM found. This is why Java is a platform-independent language.


                  4.8 DIFFERENT LIBRARIES USED IN JAVA
              Libraries in Java consist of different built-in classes that help the programmer to write the code. These classes are
              included in Java Development Kit (JDK).
              Some of the useful libraries (packages) in JDK are:

              •  java.lang   :  It is used to support classes containing String/Characters, Math, Integers, etc.
              •  java.io     :  It includes the input and output statements.
              •  java.applet  :  It contains all the required materials to develop applets.
              •  java.math   :  It contains all mathematical methods such as sqrt(), cbrt(), pow(), max(), etc.

              To include the library classes, we need to write the below code before starting the program code.
              Syntax:

                  import java.<packagename>.*;
              For example,

                  import java.util.*;
                  import java.io.*;
                  4.9 JAVA RESERVED WORDS
              Some words are used by Java for coding. These words cannot be used in the program for other purposes such as the
              names of variables, classes, functions, etc. If used, it will be treated as an error by the compiler.



                134134  Touchpad Computer Science-XII
   131   132   133   134   135   136   137   138   139   140   141