ICSE Board Computer Application Syllabus (2012-2013)
[1] Elementary Concept of Objects and Classes, [2] Values and types, [3] Conditionals and non-nested loops, [4] Class as the Basis of all Computation, [5] Constructors, [6] Functions, [7] Class as a User Defined Type, [8] Iterations, [9] Using Library Classes, [10] Encapsulation, [11] Arrays, [12] Input/Output.

Tuesday, October 18, 2011

Chapter 1 Syllabus

Elementary Concept of Objects and Classes
Modeling entities and their behavior by objects, a class  as a specification for objects and as an object factory, computation as message passing/function calls between objects (many examples should be done to illustrate this). Objects encapsulate state (attributes) and have behavior (functions). Class as a user defined type.

A class may be regarded as a blueprint to create objects. It may be viewed as a factory that produces similar  objects. A class may also be considered as a new data type  created  by  the  user,  that has  its  own functionality. All the four features  of Object Oriented Programming should  be  defined  and  explained  using  real  life examples. Analyze  each  object  and  show  how  each  contains attributes  and  responds  to  certain  messages  or permits certain operations. Emphasize  that an object is an instance  of a  class. A single object  is  just  a  bundle  of  values,  one for each attribute in the class.

Values and Types
Tokens  and  its  types,  Primitive  types,  operations  on primitive values,  expressions, assignment  (assignment is also an expression).

Introduce the  primitive  types and  the  range  of values each represents. Discuss all the operations that can be done  with  primitive  types  namely  mathematical, relational  and  logical. Discuss  precedence  and associativity  of  operators.  Introduce  the  concept  of type casting.

Introduce  System.out.println  and  System.out.print, for simple output. Discuss  different  types  of  errors  occurring  during execution  and  compilation  of  the  program  (syntax errors, runtime errors and logical errors).


Conditionals and non-Nested Loops
Application of if  else, if else if ladder, switch-case (default, break). Fixed  number  of  iterations - the  for  loop.  Unknown number of iterations - while loop, do-while loop. The  conditional/ternary  operator  (?  :  )  should  be introduced at this point. Loops are  fundamental  to  computation and  their need should be shown by examples. Examples:  various  number  based  problems:  prime numbers,  composite  numbers,  perfect  numbers, Fibonacci numbers, etc.
 

Sunday, October 9, 2011

Iterations

Q. What are iteration statements? Name the iteration statements provided by Java?
Ans: Iteration statements are statements that allows a set of instructions to be executed repeatedly till some condition is satisfied. The iteration statements provided by Java are: for loop, while loop, do-while loop.

Q. What is the difference between entry controlled and exit controlled loop?                          
or
What is the difference between while and do-while loop?
Ans: while loop is known as entry controlled loop and do-while loop is known as exit-controlled loop. The differences between these two loops are: (1) In while loop the test expression is evaluated at the beginning where as in do-while loop test expression is evaluated at the bottom, after the body of the loop. (2) In while loop if the test expression is false loop does not continued but in do-while what ever the test expression the loop execute at least once.

Q. Explain the difference between break and continue with an example.
Ans: Both statements are used as a jumped statement. But there is a difference between Break and Continue statement. The break statement terminate the loop, but the continue statement skip the rest of the loop statement and continued the next iteration of the loop.e.g. of Break Statementint i=0;while(i<=10){  i++;  if(i==5)    break;  System.out.println(i);}e.g. of Continue Statementint i=0;while(i<=10){  i++;  if(i==5)    continue;  System.out.println(i);}

Q. Compare and discuss the suitability of three loops in different situation?
Ans: (i) The for loop should be preferred if number of iteration is known beforehand. (ii) The while loop should be preferred if the number iteration is dependent upon some control variable. (iii) The do-while loop should be preferred if the number of iterations is dependent upon user response.

Q. Explain the term for loop with an example.
Ans: In Java the 'for' statement is the most common iterative statement. the general syntax of the for loop is,for(initialization; test-expression; increment){  body of the loop}This loop is executed at initial value, condition and increment. Three statement separated by semi colons are placed with in the parenthesis. for example:for(int i=1;i<=10;i++){  System.out.println(i);}

Q. State one similarity and one difference between while and do-while loop.
Ans: Similarity: In both loops there is a chances to forget the increment statement inside the loop. Difference: In while loop the test expression is evaluated at the beginning where as in do-while loop test expression is evaluated at the bottom, after the body of the loop.

Q. What do you meant by an infinite loop? Give an example. [2008]   ORQ. What do you meant by an endless loop? Give an example.
Ans: Infinite loop is an endless loop whose number of iterations are not fixed.eg: for(;;)     System.out.println("java");

Q. Differentiate fixed and variable iterative type of loops.
Ans: Fixed type of iterative loop is created when the process is to be repeated for defined number of times. Variable iterative loop repeats the process till a given condition is true.

Q. Differentiate Null loop and Infinite loop.
Ans: A Null loop does not contains any statement to repeat where as infinite loop repeats execution of the statements for endless iterations.e.g. of null loops  for(int i=1;i<=10;i++);e.g. for infinite loop  for(int i=10;i>=1;i++)

Q. What do you mean by delay loop?
Ans: A null loop is also called delay loop which does not repeat the execution of any statement but keeps the control engaged until the iterations are completed.

Class as a User Defined Types

Q. What is data type?
Ans: Data types are means to identify the type of data and associated operations of handling it.
Q. What is composite (user define) data type? Explain with an example? [2007] [2009]
Ans: A composite datatype is that datatype that are based on fundamental or primitive datatypes. A 'class' is an example of composite datatypes.class Date{  int dd, mm, yy;  public Date()  {    dd=1;    mm=1;    yy=2005;  }}
Q. What is user define datatype?
Ans: A user defined datatype is a data type that is not a part of the language and is created by a programmer.
Q. Can you refer to a class as a user defined (composite) data type? [2009]
Ans: Yes, we can refer to a class not having a main() method as user-defined data type.
Q. What is the difference between primitive data types and composite data types?
Ans: (i) primitive data types are built-in data types. Java provides these data types. User-defined data types are created by users. (ii) The size of primitive data types are fixed. The size of user-defined data types are variable. (iii) Primitive data types are available in all parts of Java programs. The availability of user-defined data types depends upon their scope.
Q. Compare a class as a user defined data type and class as an application?
Ans: In Java, all functionality is enclosed in classes. But in order for a class to be user-defined data type, it should be act different from that of an application. i.e. it should not include main() method in it. Although we can create instance of classes containing main method, they should not be referred to as used-defined data type. Such classes (containing main() method) are more analogues to application than a data type.
Q. How are private member different from public member of a class.
Ans: Private members of a class are accessible in the member function of the class only, where as public members are accessible globally.
Q. How are protected members different from public and private members of a class.
Ans: Protected members of a class are accessible in all the classes in the same package and subclass in the other packages. private members of a class accessible in the member functions in the class only. Where as public members are accessible globally.
Q. Mention any two attributes required for class declaration. [2008]
Ans: The two attributes for class declaration are: 1. Access Specifier  2. Modifier 3. Class Name

Functions

Q. What is Function? Why do we use functions while programs handling?
Ans: A named unit of a group of programs statements. This unit can be invoked from other parts of the program.
Q. Define Function prototype?
Ans: The function prototype is the first line of the function definition that tells the program about the type of the value returned by the function and the number and types of arguments.
Q. What is the use of void before function name? [2007]
Ans: void data type specifies an empty set of values and it is used as the return type for functions that do not return a value. Thus a function that does not return a value is declared as follows. void <functions name> (parameter list)
Q. Explain Functions/Methods Definitions with syntax?
Ans: A function must be defined before it is used anywhere in the program.[access specifier][modifier]return-type function-name (parameter list){  body of the function}[access specifier] can be either Public, Protected or Private. [modifier] can be one of final, native, synchronize, transient, volatile. return-type specifies the type of value that the return statement of the function returns. It may be any valid Java data type. parameter list is comma separated list of variables of a function.
Q. Why main() function so special?
 Ans: The main() function is invoked in the system by default. hence as soon as the command for execution of the program is used, control directly reaches the main() function.
Q. Explain the function prototype and the signature?
Ans: The function prototype is the first line of the function definitions, that tells the program about the type of the value returned by the function and the number and type of the arguments. Function signature basically refers to the number and types of the arguments, it is the part of the prototype.
Q. Explain the function of a return statement? [2006]
Ans: The return statement is useful in two ways. First an immediately exit from the function is caused as soon as a return statement is encountered and the control back to the main caller. Second use of return statement is that it is used a value to the calling code.
Q. Write advantages of using functions in programs. [2010]
Ans: (i) functions lessen the complexity of programs (ii) functions hide the implementation details (iii) functions enhance reusability of code
Q. Difference between Actual argument and Formal argument? [2007,2008]
Ans: The parameter that appears in function call statement are called actual argument and The parameter that appears in function definition are called formal parameter.
Q. What are static members?
Ans: The members that are declared static is called static members. These members are associated with the class itself rather then individual objects, the static members and static methods are often referred to as class variables and methods.
Q. What is the use of static in main() methods? [2007]
Ans: (i) They can only call other static methods. (ii) They can only access static data. (iii) They can not refer to this or super in any way.
Q. What is call by value?   [2005]
Ans: (i) In call by value, the called functions creates its own work copy for the passed parameters and copies the passed values in it. Any changes that take place remain in the work copy and the original data remains intact.
Q. Explain the term "passed by reference"? [2007]
Ans: In passed by reference, the called function receives the reference to the passed parameters and through this reference, it access the original data. Any changes that take place are reflected in the original data.
Q. Differentiate between call by value and call by reference?
Ans: In call by value, the called functions creates its own work copy for the passed parameters and copies the passed values in it. Any changes that take place remain in the work copy and the original data remains intact. In call by reference, the called function receives the reference to the passed parameters and through this reference, it access the original data. Any changes that take place are reflected in the original data.
Q. Define an impure functions? [2006]
Ans: Impure Function change the state of the object arguments they have received and then return. The following functions is the example of an impure function: public static Time increment(Time obj, double secs){  time.seconds+=secs;  return(Time);}
Q. What is the difference between pure and impure functions? [2009]
Ans: Pure Function: These functions takes objects as an arguments but does not modify the state of the objects. The result of the pure function is the return value. Impure Function: These functions change the state of the object arguments they have received.
Q. How are following passed in Java?              [2005]    (i) primitive types    (ii) reference types
Ans: (i) By value,     (ii) By reference.
Q. What does function overloading mean? What is its significance?
Ans: A Function name having several definitions in the same scope that are differentiable by the number or type of their arguments, is said to be an overloaded function. Function overloading not only implements polymorphism but also reduce the number of comparisons in a program and there by makes the programs run faster.
Q. Illustrate the concept of function overloading with the help of an example.  [2006]
Ans:- A function name having several definitions that are differentiable by the numbers or types of their arguments is known as function overloading. For example following code overloads a function area to computer areas of circle rectangle and triangle.float area (float radius)            //circle{        return (3.14 * radius * radius);}float area (float length, float breadth)  //rectangle{    return (length*breadth);}float area (float side1, float  side2, float side3) //area of triangle{    float s = (side1 + side2 + side3)/2;    float ar = Math.sqrt(s * (s- side1)*(s-side2) *(s-side3));    return (ar);}
Q. What is ‘this’ keyword? What is its significance? [2009]
Ans: The “this” keyword is used to refer to currently calling objects. The member functions of every objects have access to a sort of magic keyword name this, which points to the object itself. Thus any member function can find out the address of the object of which it is a member. The ‘this’ keyword represents an object that invokes a member function. It stores the address of the object that invoking a member function and it is an implicit argument to the member function being invoked. The ‘this’ keyword is useful in returning the object of which the function is a member.
Q. What do you mean by recursive function?
Ans: When a method is called inside its own definition the process is known as functions recursion and this function called recursive function.
Q. What is the difference between Methods and Functions?
Ans: The major difference between methods and functions is that methods called by the reference variables called objects where as the functions do not having any reference variables.

Constructors

Q. What is constructor?
Ans: A constructor is a Member function that automatically called, when the object is created of that class. It has the same name as that of the class name and its primary job is to initialise the object to a legal value for the class.
Q. Why do we need a constructor as a class member?
Ans: Constructor is used create an instance of of a class, This can be also called creating an object.0
Q. Why does a constructor should be define as public?
Ans: A constructor should be define in public section of a class, so that its objects can be created in any function.
Q. Explain default constructor?
Ans: The constructor that accepts no parameter is called the default constructor. If we do not explicitly define a constructor for a class., then java creates a default constructor for the class. The default constructor is often sufficient for simple class but not for sophisticated classes.Example:  class ant  {    int i;    public static void main()    ant nc=new ant();  }the line new ant() creates an object and calls the default constructor, without it we have no method to call to build our objects. once you create a constructor with argument the default constructor becomes hidden.
Q. Explain the Parameterised constructor?
Ans: If we want to initialise objects with our desired value, we can use parameters with constructor and initialise the data members based on the arguments passed to it . Constructor that can take arguments are called Parameterised constructor.Example:  public class result  {    int per;    int tot;    public result (int percentage)    {      per=percentage;      tot=0;    }  }
Q. Give a syntax/example of constructor overloading. Define a class, which accept roll number and marks of a student. Write constructor for the class, which accepts parameter to initialise the data member. Also take care of the case where the student has not appeared for the test where just the roll number is passed as argument.
Ans: class student  {    int roll;    float marks;    student(int r, float m)                 // constructor with two argument.    {      roll=r;      marks=m;    }    student(int r)                            // constructor with one argument    {      roll=r;      marks=0;    }    student()                                  // default constructor    {      roll=0;      marks=0;    }  }
Q. Mention some characteristics of constructors.
Ans: The special characteristics of constructors are:(i) Constructors should be declared in the public section of the class. (ii) They are invoked automatically when an object of the class is created. (iii) They do not have any return type and cannot return any values. (iv) Like any other function, they can accept arguments. (v) A class can have more than one constructor. (vi) Default constructor do not accept parameters. (vii) If no constructor is present in the class the compiler provides a default constructor.
Q. State the difference between Constructor and Method.  [2005]
Ans: The function has a return type like int. but the constructor has no return type. The function must be called in programs where as constructor automatically called when the object of that class is created.
Q. Enter any two variables through constructor parameters and write a program to swap and print the values.   [2005]
class swap{  int a,b;  swap(int x,int y)  {    a=x;    b=y;  }  public void main(String args[])  {    int t=a;    a=b;    b=t;    System.out.println("the value of a and b after swaping : "+a+" "+b);  }}
 Q. What are the types of Constructors used in a class?
Ans: The different types of constructors are as follows:i. Default Constructors.ii. Parameterized Constructor.iii. Copy Constructors.
Q. Define Copy constructors.
Ans: A copy constructors initializes the instant variables of an object by copying the initial value of the instant variables from another objects. e.g.class xyz{  int a,b;  xyz(int x,int z)  {    a=x;    b=y;  }  xyz(xyz p)  {    a=p.x;    b=p.y;  }}