ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2014 ICSE Computer Science Paper



Share with a Friend

Solved 2014 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Short Questions/Answers - ICSE 2014 Computer Science

Question 1

(a) Which of the following are valid comments?
(i) /*comment */
(ii) /*comment
(iii) //comment
(iv) */comment*/

/*comment*/

(b) What is meant by a package? Name any two Java Application Programming Interface package.

Packages are means of defining modules in Java and are used to group logically related classes together. They help in avoiding name conflicts. Two examples are java.io and java.util.

(c) Name the primitive data type in Java that is:
(i) a 64-bit integer and is used when you need a range of values wider than those provided by int.
long
(ii) a single 16-bit Unicode character whose default value is ‘\u0000’.
char

(d) State one difference between floating point literals float and double.

The float literal occupies 32 bits whereas the double literal occupies 64 bits.

(e) Find the errors in the given program segment and re-write the statements correctly to assign values to an integer array.

int a = new int(5);
for(int i = 0; i <= 5; i++) a[i] = i;
int a[] = new int[5];
for(int i = 0; i < 5; i++)
    a[i] = i;

Question 2

(a) Operators with higher precedence are evaluated before operators with relatively lower precedence. Arrange the operators given below in order of higher precedence to lower precedence.
(i) &&
(ii) %
(iii) >=
(iv) ++

++, %, >=, &&

(b) Identify the statements listed below as assignment, increment, method invocation or object creation statements.
(i) System.out.println(“Java”); Method invocation
(ii) costPrice = 457.50; Assignment
(iii) Car hybrid = new Car(); Object creation
(iv) petrolPrice++; Increment

(c) Give two differences between switch statement and if-else statement.

(i) The switch statement tests for one variable, whereas the if-else statement tests for multiple variables.
(ii) The switch statement only tests for equality, whereas the if-else statement can test for any type of condition.

(d) What is an infinite loop? Write an infinite loop statement.

An infinite loop is one that keeps on executing repeatedly because its terminating condition is either missing or is never reached.

for(;;)
    System.out.println("Java");

(e) What is a constructor? When is it invoked?

A constructor is a member function with the same name as its class. It is used to initialize the objects of the class with legal initial values.
It is invoked at the time of object creation.

Question 3

(a) List the variables from those given below that are composite data types.
(i) static int x;
(ii) arr[i] = 10; (Composite)
(iii) obj.display(); (Composite)
(iv) boolean b;
(v) private char chr;
(vi) String str; (Composite)

(b) State the output of the following program segment:

String str1 = "great"; String str2 = "minds";
System.out.println(str1.substring(0, 2).concat(str2.substring(1)));
System.out.println(("WH" + (str1.substring(2).toUpperCase())));
grinds
WHEAT

(c) What are the final values stored in variables x and y below?

double a = -6.35;
double b = 14.74;
double x = Math.abs(Math.ceil(a));
double y = Math.rint(Math.max(a, b));

x = 6.0
y = 15.0

(d) Rewrite the following program segment using the if-else statements instead of the ternary operator.

String grade = (marks >= 90)? "A" : (marks >= 80)? "B" : "C";
String grade = "";
if(marks >= 90)
    grade = "A";
else if(marks >= 80)
    grade = "B";
else
    grade = "C";

(e) Give the output of the following method:

public static void main(String[] args){
    int a = 5;
    a++;
    System.out.println(a);
    a -= (a--) - (--a);
    System.out.println(a);
}

6
4

(f) What is the data type returned by the library functions:
(i) compareTo()
int
(ii) equals()
boolean

(g) State the value of characteristic and mantissa when the following code is executed:

String s = "4.3756";
int n = s.indexOf('.');
int characteristic = Integer.parseInt(s.substring(0, n));
int mantissa = Integer.valueOf(s.substring(n + 1));

characteristic = 4
manissa = 3756

(h) Study the method and answer the given questions:

public void sampleMethod(){
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 2; j++){
            int number = (int)(Math.random() * 10);
            System.out.println(number);
        }
    }
}

(i) How many times does the loop execute?
6 times.
(ii) What is the range of possible values stored in the variable number?
The range is 0 to 9.

(i) Consider the following class:

public class myClass{
    public static int x = 3, y = 4;
    public int a = 2, b = 3;
}

(i) Name the variables for which each object of the class will have its own distinct copy.
a and b.
(ii) Name the variables that are common to all objects of the class.
x and y.

(j) What will be the output when the following code segments are executed?

String s = "1001";
int x = Integer.valueOf(s);
double y = Double.valueOf(s);
System.out.println("x = " + x);
System.out.println("y = " + y);

x = 1001
y = 1001.0

System.out.println("The King said\"Begin at the beginning!\" to me.");
The King said "Begin at the beginning!" to me.