0% found this document useful (0 votes)
87 views

Past Paper - IP Phase Test 1

The document contains a Java practice test with 5 sections: Section A contains 5 multiple choice questions about Java features. Section B contains 6 true/false questions about Java concepts. Section C provides 4 coding exercises to declare variables, write expressions, and conditional prints. Section D has 3 code snippets with errors to identify and correct. Section E analyzes a sample program with 2 questions about its output and behavior.

Uploaded by

Man Runner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

Past Paper - IP Phase Test 1

The document contains a Java practice test with 5 sections: Section A contains 5 multiple choice questions about Java features. Section B contains 6 true/false questions about Java concepts. Section C provides 4 coding exercises to declare variables, write expressions, and conditional prints. Section D has 3 code snippets with errors to identify and correct. Section E analyzes a sample program with 2 questions about its output and behavior.

Uploaded by

Man Runner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

Section A

Select the most appropriate answer for the questions given below:

1. Which one of the following is correct with respect to the features of Java
Programming Language?

(a) Reusable, Secure, Platform dependent, Multithreaded


(b) Reusable, Platform independent, Multithreaded, Robust
(c) Reusable, Secure, Object oriented, Architecture neutral
(d) Reusable, Less secure, Distributed, Multithreaded

2. A successfully compiled java application can be run on any platform


(operating system) because

(a) Java programming is derived from C++.


(b) The Java Virtual Machine(JVM) interprets the program for the
native operating system.

(c) The compiler is platform independent.

(d) The APIs do all the work.

3. Java applications begin execution at method

(a) init
(b) main
(c) paint
(d) showMessageDialog

4. What will be the result of the expression a % b when a and b are of type
int and their values are a = 10 and b = 6?

(a) 1.66
(b) 1
(c) 4
(d) None of the above.

5. ___________________ is/are small program/s that can be embedded into


html files and interpreted by the browser.

(a) Java compiler


(b) Java applets
(c) Java debugger
(d) Java Virtual Machine

[5 marks]
Section B

State whether the following statements are either TRUE or FALSE.

1. All variables must be given a type when they are declared. (TRUE)

2. Class Graphics is located in package javax.awt that allows draw graphics


in a java program. (FALSE)

3. By convention, all classes start with lower case first letter. (FALSE)
Eg JOptionPane, Graphics g

4. Class String is in the package java.lang.(FALSE)

5. Variables declared in the body of a particular method are known as


instance variables and can be used in all methods of the class. (FALSE)

6. A set of statements contained within a pair of parentheses, ( ), is called a


block. (FALSE)
{}

[6 marks]
Section C

Write Java statements to accomplish each of the following tasks:

1. Declare variables c, intNumber, q763 and number to be of type int.

= Int C, intNumber, q763;

2. Arithmetic expression r = (p2 + q)

r = MattPow(p,2) = q; OR
r = p*p + q;

3. Print “This is my Java program” on two lines in the command window or


the message box. The first line should end with my.

System.out.println(“This is my + \n Java program”);

4. Test if the value of the variable count is greater than 10. If it is, print
“Count is greater than 10”.

If (count > 10) {


System.out.printIn(“Count is greater than or equal to 10”);
}
else {
System.out.printIn(“Count is less than 10);
}

[4 marks]
Section D

Identify and correct the errors in each of the following sets of code
1. x = 1;
while (x >=4)
x ++; = x++; x = x+ 1;

loop can never be executed.

2. If (gender == 1)
System.out.println(“Women”);
else;
Syste.out.println(“Men”);
If (gender == 1)
System.out.println(“Women”);
else
System.out.println(“Men”);

3. for(counter = 1; counter <= 10.0; counter++)


{
x = x * counter;
}

for(intcounter = 1; counter <= 10; counter++) {

x = x * counter;
}

[3 marks]

Section E
1. Carefully read the following program and answer the following questions
below:
public class MainClass {

  public static void main(String[] arg) {
    int limit = 10;
    int sum = 0;
    for (int i = 1; i <= limit; i++) {
      if (i % 3 != 0) 
      sum = sum + i;
    }
    System.out.println(sum);
  }
}

(a) What does the following program output?

= 1 + 2 + 4 + 5 + 7 + 8 + 10
= 37
[2 marks]

(b) How many times the statement “sum = sum + I;” will execute?

= 7 times

[2 marks]

2. Identify the class, package, object, method and variable from the
highlighted words of the program below:

// Maximum.java
// Finding the maximum of three doubles
import java.awt.Container;
import javax.swing.*;

public class Maximum extends JApplet {


public void init()
{
JTextArea outputArea = new JTextArea();

String s1 = JOptionPane.showInputDialog(
"Enter first floating-point value" );
String s2 = JOptionPane.showInputDialog(
"Enter second floating-point value" );
String s3 = JOptionPane.showInputDialog(
"Enter third floating-point value" );

double number1 = Double.parseDouble( s1 );


double number2 = Double.parseDouble( s2 );
double number3 = Double.parseDouble( s3 );
double max;

if ((number1>number2) && (number1>number3))


max = number1;
else if ((number2>number1) && (number2>number3))
max = number2;
else
max = number3;

outputArea.setText( "number1: " + number1 +


"\nnumber2: " + number2 +
"\nnumber3: " + number3 +
"\nmaximum is: " + max );

// get the applet's GUI component display area


Container c = getContentPane();

// attach outputArea to Container c


c.add( outputArea );
}
}

java.awt = package
init() = method
showInputDialog =
JOptionPane = class
number2 = variable
c = variable

(6 marks)

Section F
1. Develop and run a Java Application or Java Applet that accepts student
scores (0 to 100) from a user through an input box and displays the
summary as shown below. Pass mark is 50 and above.

Class Grade Summary


Number of students 10

Average marks 76.0

Number failed 1
Number passed 9

(12 marks)

You might also like