Page 7 - CA_Blue( J )_Class9
P. 7

JAVA COMPILATION PROCESS
                  Java is a platform independent programming language. Its execution is divided into two steps.
                  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 in individual device. This is done by
                         Java Virtual Machine. The platform performs all the tasks of the Java run-time system. It loads the Java
                         class file and interprets the compiled byte-code.
                  As you know, compiler translates High level language program to a lower-level language to create an executable
                  program and  Interpreter  reads the input  source  program and  then translate to machine  code instruction  by
                  instruction.
                  Java Compiler
                  Java Compiler converts the source code into an intermediate code called byte code. The Java Compiler is also
                  known as javac.
                  Java bytecode further is converted by Java Virtual Machine to machine dependent code.
                  These Bytecode has resemblance with Assembly language. The only difference between Byte code and Assembly
                  language is byte code is used by JVM and Assembly language is directly used by the hardware (CPU).
                        Note: The extension of Java source code is .java and the converted bytecode has the extension .class.
                   Note: This section provides a tip to the user which is relevant to the current topic.
                  Java Virtual Machine (JVM)
                  Java Virtual Machine converts Java byte code to machine code so that it could be executed. Also it can run on any
                  operating system. It follows the principle of “Write Once, Run Anywhere”. It manages and optimizes the program
                                                  Assessment Resources
                  so that memory uses can be minimized. The Java Programs written by programmers are called Java Source Code.
                  They are saved with the extension .java. When Java Source Code is compiled by Java Compiler (javac), the resultant
                  code is called Java bytecode which is further converted by Java Virtual Machine to machine code.
                                                                                        MODEL TEST PAPER
                                                                                         COMPUTER APPLICATIONS
                                     MIND DRILL     6.  Refer a class structure as shown below:  Maximum Marks : 100   Interpreter    Time allowed: Two hours
                                                    class subject

                                                                                                 for Mac
                                                    {                           JVM Answers to this Paper must be written on the paper provided separately.
                                                                                      You will not be allowed to write during the first 15 minutes.
                                                         sub_name                      This time is to be spent on reading the question paper.
                      Solved Questions                   book_name                The time given at the head of this Paper is the time allowed for writing the answers.
                          Source Code        Complier          Byte Code                 This Paper is divided into two Sections.
                                                                                               Interpreter

                     A.  Tick ( ) the correct answer.            getData();     JVM Attempt all questions from Section A and any four questions from Section B.
                            (.java file)
                                                        showData();
                                                                                              for Windows
                                              (Javac)
                        1.   Which loop contains initialisation, condition for testing and increment or decrement in the same line?  (.class file)  The intended marks for questions or parts of questions are given in brackets [ ].
                                                     }

                        a.  for          b.  while     subject computer = new subject();    SECTION A
                        c.   do while    d.  None of these                              Attempt all questions from this Section.
                                                 With reference to the above class declaration, fill in the blanks:
                        2.   While writing ascending order program we use ………………… relational operator in condition for testing.  Question 1.   [20]
                                                                                               Interpreter
                                                                                JVM
                        a.  >            b.  <     a.  ………………… is the characteristic of the class that starts with letter “s”.     (i)  Which of the following paradigm follows the Top-down approach?
                        c.   >=          d.  All of these     b.  Book_name  is ………………… of the class.  (a)  Procedural-Oriented Programming
                                                                             (b)  Object-Oriented programming

                        3.   Java for loop executes a set of statements repeatedly for a ………………… number of times. c.  ………………… and ………………… are the common behaviour of the objects of class “subject”  for Linux
                        a.  Uncertain    b.  Fixed      d.  Name of class is ………………….  (c)  Both a and b
                        c.   Unfixed     d.  Same                            (d)  None of these
                                                  e.  Creating ………………… objects of class is possible.    Ans.  (a)  Procedural-Oriented Programming
                        4.   ………………… is example/s of "entry control loop”.     f.  Name of the object is ………………….     (ii)  Which of the following converts the Java byte code into the machine code?
                                                                              Model Test Paper: This section
                        a.  for          b.  do-while                        (a)  JVM          (b)  JMV
                         FEATURES OF JAVA         g.  To create the object computer, we use ………………… keyword.  (c)  MVJ   (d)  VJM
                       c.   while
                                         d.  both a and c
                 Mind Drill: This section contains objective                 Ans.  (a)  JVM
                                                                           contains sample question paper with
                      5.   If the test condition is checked after executing the body of the loop, then it is called ………………….

                                               C.  Short Answer type question.

                                                                            (iii)  Which of the following is called template used to create objects that share common characteristics and behaviour?
                                         b.  entry control loop

                       a.  exit control loop
                  Java is a versatile language and provides many features. Let us take a look at some the features  provided by Java:

                                                 1.  In the real world, if "Car" is a class, then name some objects in it.
                                                                                               (b)  Object
                 and subjective questions for assessment.                    (a)  Instance   solution for practice.
                                         d.  iterative control loop
                       c.   both of these


                                                 2.  Name some components of classes.
                                                                             (c)  Class
                                                                                               (d)  Methods
                      6.   Continue statement is used as ………………… statement.

                                                 3.  How do you define class in java?

                                                                             Ans.  (c)  Class
                       a.  jump

                                         b.  return
                  •  Simple: Java has relatively simple structure and clearly defined syntax.  (b)  ASCII code

                                                 4.  How an object is an instance of a class?

                                                                            (iv)  Which of these made up of 128 symbols consisting of letters, digits and numbers, punctuation marks, and special characters?
                                         d.  all of these
                       c.   break

                                                 5.  How Class is a user-defined data type?
                                                                             (a)  UNICODE

                        7.   Which loop ends with a semicolon (;)?     6.   Write a short note on objects. Give examples.  (c)  Identifier   (d)  Separator
                  •  Case Sensitive: Java is a case sensitive language. In Java, ‘pay’ and ‘PAY’ are not the same. They are interpreted
                                         b.  while

                       a.  for
                                                                             Ans.  (b)  ASCII code

                                                 7.   Why is class call a factory of objects? Explain with two examples.

                                         d.  all of these
                       c.   do-while
                                                                            (v)  A                         is the smallest unit which depicts the smallest part of a program.

                        8.   for(i=1;i>=0;i++)     8.   Justify the following statement: "Classes are also known as user-defined data type. (a)  literal   (b)  token
                     differently.              D.  Assertion and Reasoning based question.  (c)  punctuator   (d)  separators
                          {
                         System.out.println("Loop");                         Ans.  (b)  token
                          }                       Assertion(A): A Java program is made up of classes.      (vi)  What is the result stored in x, after evaluating the following expression?
                                                                             int x = 5;
                       It is a/an ………………….        Reason(R): Each class is made up of some attributes (Data members) which are predefined data types.
                                                                             x = x++ * 2 + 3 * --x;
                        a.  finite loop   b.  infinite loop     (a)   Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
                                                                             (a)  22
                        c.   Null loop   d.  body less loop     (b)  Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion (A).   (b)  24
                                                                             (c)  26
                                                                                               (d)  25
                        9.   int i=5; This part is the ………………… of a loop      (c)   Assertion (A) is true and Reason (R) is false.     Ans.  (d)  25  Introduction to JAVA   27
                        a.  Increment    b.  Condition      (d)  Assertion (A) is false and Reason (R) is true.      (vii)  What will be the output of:
                        c.   Initialisation   d.  job                        int a = -1;
                        10.   How many times the loop will execute?          System.out.println(-a++);
                         int i=45;                                           (a)  1            (b)  -1
                         for(;i>=5;i=i-5)                                    (c)  0            (d)  None of these
                                         Assertion and Reasoning Based Question: This
                                                                             Ans.  (d)  1
                         {
                                        contain assertion and reasoning based questions                  Model Test Paper  289
                     228  Touchpad Computer Applications-IX
                                        to develop logical reasoning skills of the students.
                                                                       Elementary Concept of Objects and Classes  43
                                                                               SAMPLE PROJECTS
                    INTERNAL ASSESSMENT
                                                                                                      21 st   #Creativity & Innovativeness
                                                                                                      Century   # Collaboration & Teamwork
                   Marks: 100                                                                         Skills
                                               21 st   #Problem Solving & Logical Reasoning   Project  1  Write a project to display the electricity bill.
                                              Century
                                               Skills  #Creativity & Innovativeness
                   [Important: These programs are indicative only. Teachers and students should use their imagination to create
                   innovative and original assignments.]
                   (i)   Programs using Assignment statements
                          Write a program to print the area and perimeter of a rectangle whose length is 8 cm and
                    Program 1
                          breadth is 5 cm.
                     1  class rectangle        //Class Name
                     2  {
                     3      public static void main()
                     4      {                                              1  public class ElectricityBill
                     5        int l,b,a,p;     //Variable Declaration      2  {
                     6        l=8;                                         3       public static  void  main(String customerNumber, String customerName,
                  Internal Assessment: This segment is                     4      { int oldReading, int currentReading)
                            b=5;
                     7
                            a=l*b;
                     8
                                               // Calculation of area
                  totally practical-oriented and helps the               Sample Projects: This section contains
                                                                                      int RENTAL_AMOUNT = 250;
                                                                           5
                                               //Calculation of perimeter
                     9
                            p=2*(l+b);
                                                                                      int  unitsUsed;
                            System.out.println("Area of a Rectangle : " + a);  //Displaying Area
                 students in acquiring basic programming                   6 7  a real-life application to use the
                    10
                                                                                      double userAmount;
                                                                                     concepts learnt.
                          System.out.println("Perimeter of a Rectangle : " + p);  //Displaying Perimeter
                    11
                    12      } skills quickly and efficiently.              8          double Tax;
                                               //Close of main()
                    13  }                      //Close of class            9          double Bill;
                   You will get the following output:                     10
                      Area of a Rectangle : 40                            11          if (oldReading > currentReading)
                      Perimeter of a Rectangle : 26                       12          {
                                   VARIABLE DESCRIPTION                   13                System.out.println("Old reading cannot be greater than the current
                                                                               reading");
                        NAME   DATATYPE      DESCRIPTION                                  System.out.println("Exiting...");
                      l          int  Length of the rectangle             14
                      b          int  Breadth of the rectangle            15              System.exit(0);
                      a          int  Area of a rectangle                 16          }
                      p          int  Perimeter of a rectangle            17          //Calculate the bill amount
                                                                          18              unitsUsed = currentReading-oldReading;
                                                                          19          if ( unitsUsed <= 100)
                                                                          20              userAmount =  unitsUsed*3.25;
                                                                                                           Sample Projects  301
                    276  Touchpad Computer Applications-IX
   2   3   4   5   6   7   8   9   10   11   12