Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 103

mportant Java question for ICSE Class X Board Exam

Introduction to Java & Blue Environment

1. Why is Java often termed as a platform?

Ans: Platform is the environment in which programs execute. Instead of


interacting with the Operating System directly, Java programs runs on a virtual
machine provided by Java, therefore Java is often referred to as a platform
also.

1. What is a bytecode?
Ans: Bytecode is a set of pseudo mechanic language instructions that are
understood by the JVM (Java Virtual Machine) and are independent of the
underlying hardware.

1. What do you understand by JVM?

Ans: JVM or Java Virtual Machine is an abstract machine designed to be


implemented on top of existing processors. It hides the underlying OS from
Java application. Programs written in Java are compiled into Java byte-code,
which is then interpreted by a special java Interpreter for a specific platform.
Actually this Java interpreter is known as Java Virtual Machine (JVM).

1. What is JDK (Java Development Kit)?


REPORT THIS AD

Ans: The Java development kit comes with a collection of tools that are used
for developing and running java programs.

1. What are Java APIs?

Ans: The Java APIs (Application Program Interface) consist of libraries of pre-
compiled code that programmers can use in their application.

1. Write the five characteristics of Java/BlueJ?

Ans: 1. Write Once Run Anywhere 2. Light weight code 3. Security 4. Built in
Graphics 5. Object Oriented Language 6. Support Multimedia 7. Platform
Independent. 8. Open Product.

1. What do you know about BlueJ?


Ans: BlueJ is a Java development environment. It is an IDE (Integrated
Development Environment), which includes an editor a debugger and a
viewer.

1. How you create, compile and execute a program in Java or BlueJ? Explain
your answer?

Ans: Create: Click on new class button from BlueJ editor, then type the class
name a program icon will be created. double click on it, a program editor will
be open, erase the code and type your program coding. Compile: click the
compile button on the left of the window or right click on the class icon and
select compile from the menu options. Execute: Right click on the class icon
and select new class name option. A dialogue box appears type the name of
the object. A object icon will be created at the bottom. Right click on the object
icon and select the method we want to execute.

1. The two types of Java programs/applications are? [2007]

Ans: The two types of Java Applications are ‘Internet Applets’ and ‘Stand
alone application’.

1. State the distinguishing features of Java and C++?

Ans: (i) Java does not support operator overloading.

(ii) Java does not use pointers.

(iii) There are no header files in Java.

(iv) Java does not have template classes as in C++.

1. State the differences between Syntax errors and Logical errors.


Ans: The compiler can only translate a program if the program is syntactically
correct; otherwise the compilation fails and you will not be able to run your
program. Syntax refers to the structure of your program and the rules about
that structure.

The second type of error is a run-time error, so-called because the error does
not appear until you run the program. In Java, run-time errors occur when the
interpreter is running the byte code and something goes wrong.

1. “Object is an instance of a class”, explain

Ans: Object of a class contains data and functions provided in a class. it


possesses all the features of a class. Hence object is termed as instance of a
class.

1. Name four basic features of JAVA.

Ans: Basic features of Java as follows:

1. i) It is an object oriented language.


2. ii) Java program is both compiled and interpreted.

iii) Java program can be application or applet.

1. iv) java is case sensitive language, i.e. it distinguished upper and lower case
letters.
2. Differentiate between Compiler and Interpreter.

Ans: Compiler convert source code to machine language whole at a time.


Interpreter converts program from high level language to machine level
language line by line or statement by statement.

1. Java uses compiler as well as interpreter, explain.


Ans: Java compiler converts Java source code to byte code. This byte code is
further converted into machine code to make it applicable for the specific
platform by using interpreter.

1. Differentiate between Source code and Byte code.

Ans: Source code is the program developed in Java Language, which is input
to a computer through the keyboard. Compiler converts source code to byte
code for interpretation.

1. Differentiate between Testing and Debugging.

Ans: Testing is the process of checking program logic manually to ensure


whether it contains any error or not. Debugging is the process of removing
errors from a program.

Elementary Concepts of Object & Class

[ICSE Syllabus on this Topic]

Modeling entities and their behavior by objects. A class as a specification of


objects and as an object factory, computation as message passing/function
call between objects (many example should be done to illustrate this). Object
encapsulate state (attribute) and have behaviors (functions). Class as a user
defined type.

1. What is an Object? [2006]


Ans: An Object is an identifiable entity with some characteristics and behavior.
E.g. take a class ‘Car’. A car class has characteristics like colour, gears,
power, length etc. now we create the object of that class ‘Car’ namely ‘Indica’.

1. What is OOP? What are the features/concepts in OOP’s? [2007]

OR

Name any two OOP’S principles. [2005]

Ans: The Object Oriented Programming Paradigm is the latest in the software
development and the most adopted one in the programming development.
The Paradigm means organising principle of a program. It is an approach to
programming. The concepts of OOP’s are: (1) Data Abstraction (2) Data
Encapsulation (3) Modularity (4) Inheritance (5) Polymorphism.

1. Explain all the Concepts of OOP’s?

Ans: Abstraction: It refers to the act of representing essential features without


including the background details or explanation. Encapsulation: It is the way of
combining both data and the function that operates on the data under a single
unit. Modularity: It is the property of a system that has been decomposed into
a set of cohesive and loosely couple modules. Inheritance: It is the capability
of one class of thing to inherit properties from another class. Polymorphism: It
is the ability for a message or data to be processed in more then one form.

1. What are the advantages of OOP’s?

Ans: (1) Elimination of redundant coding system and usage of existing classes
through inheritance. (2) Program can be developed by sharing existing
modules. (3) Possibilities of multiple instance of an objects without any
interference. (4) Security of data values from other segment of the program
through data hiding.

1. What is Class? How Object is related to the Class?

Ans: A Class represent a set of Objects that share common characteristics


and behavior. Objects are instance of a class. The Object represents the
abstraction representation by the class in the real sense.

1. What is the need of a class in Java?

Ans: Classes in Java are needed to represent real-world entities, which have
data type properties. Classes provide convenient methods for packing
together a group of logical related data items and functions that work on them.
In java the data items are called fields & the functions are called methods.

1. What are Methods? How are these related to an Objects?

Ans: A Method is an operation associated to an Object. The behavior of an


Object is represented through associated function, which are called Methods.

1. Point out the differences between Procedural Programming and Object


Oriented Programming.

Ans: Procedural programming aims more at procedures. The emphasis is a


doing things rather then the data being used. In procedural Programming
parading data are shared among all the functions participating thereby risking
data safety and security. Object Oriented Programming is based on principles
of data hiding, abstraction, inheritance and polymorphism. It implements
programs using classes and objects, In OOP’s data and procedure both given
equal importance. Data and functions are encapsulated to ensure data safety
and security.
1. What is an abstraction?

Ans: An abstraction is a named collection of attributes and behaviors required


to represent an entity or concept for some particular problem domain.

1. What is inheritance and how it is useful in Java. [2008]

Ans: It is process by which objects of one class acquire the properties of


objects of another class. Inheritance supports the concepts of hierarchical
representation. In OOP the concepts of inheritance provides the idea of
reusability.

1. What role does polymorphism play as java feature?

Ans: It mean the ability to take more than one form. For example, an
operation, many types of data used in the operation.

1. What is Data hiding?

Ans: Data Hiding means restricting the accessibility of data associated with an
object in such a way that it can be used only through the member methods of
the object.

1. What are nested classes?

Ans: It is possible to define a class within another class, such classes are
known as nested classes. A nested class has access to the members
including private members of the class in which it is nested. However the
enclosing class not have access to the members of the nested class.

1. Differentiate between base and derived class. [2008]


Ans: BASE CLASS – A class from which another class inherits (Also called
SUPER CLASS)

DERIVED CLASS – A class inheriting properties from another class. (Also


called SUB CLASS)

Class as the Basis of all Computation

[ICSE Syllabus on this Topic]

Objects encapsulates state and behavior- numerous example, member


variables, attributes or features. Variable define states, Member
functions/operation/methods/messages defines behaviors. Class as
abstractions for set of objects, class as an object factory, concept of type,
primitive data types, composite data types. Variable declaration for both types,
difference between the two types. Objects as instance of a class. Modeling by
composition.

1. What are keywords? can keywords be used as a identifiers?

Ans: Keywords are the words that convey a special meaning to the language
compiler. No, keywords can never be used as identifiers.

1. What is an identifier? What is the identifier formatting rule of Java? OR What


are the rules for naming a variable?
Ans: Identifiers are names given to different parts of a program e.g. variables,
functions, classes etc. The identifiers in Java.

(i) Can contains alphabets, digits, dollar sign and underscore.

(ii) Must not start with a digit.

(iii) Can not be a Java keywords.

(iv) Can have any length and are case-sensitive.

1. Why keyword is different from identifiers?

Ans: Keywords are predefine sets of words that have a special meaning for
the Java compiler. Identifiers on the other hand are created by Java
programmers in order to give names to variables, function, classes etc.

1. State the difference between Token and Identifier.[2008]

Ans: The smallest individual unit of a program is known as Token. The


following Tokens are available in Java: Keywords, Identifiers, Literals,
Punctuations, Operators.

Identifiers are names given to different parts of a program e.g. variables,


functions, classes etc. The identifiers in Java.

1. What are literals? How many types of integer literals are available in Java?

Ans: A literal is sequence of characters used in a program to represent a


constant value. For example ‘A’ is a literal that represents the value A of type
char, and 17L is a literal that represents the number 17 as value of type long.
Different types of literals available in Java, they are: Integer literal, Float literal,
Boolean literal, Character literal, String literal and null literal.

1. What is an integer constant? Write integer forming rule of Java.

Ans: Integer constants are whole numbers without any decimal part. The rule
for forming an integer constants is: An integer constant must have at least one
digit and cannot contain a decimal point. It may contains + or – sign. A
number with no sign is interpreted to be positive.

1. What do you mean by Escape sequence and name few escape sequences in
Java?

Ans: Java have certain nongraphic characters (nongraphic characters are


those characters that can not be typed directly from keyboard e.g. backspace,
tab, carriage return etc.). Those nongraphic character can be represented by
escape sequence. An escape sequence is represented by backslash followed
by one or more character. The few escape sequence characters are: \n for
new line, \t for Horizontal Tab, \v for Vertical Tab, \b for Backspace, \” for
Double Quotes etc.

1. How many integer constants are allowed in Java? How are they written?

Ans: Java allows three types of integer constants: Octal (base 8), Decimal
(base 10), and Hexadecimal (base 16). An Octal integer must be started with
a zero ‘0’, a Hexadecimal integer starts with a ‘0X’, all others are treated as
decimal integer constant.

1. What is meant by a floating constant in Java? How many ways can a floating
constant be represented into?
Ans: Floating constants are real numbers. A floating constant can either be a
fractional or in exponent form.

1. Differentiate between Integer and Floating type constants.

Ans: Integer constants are the whole numbers (without decimal points). e.g.
1231. Floating point constants are fractional numbers (number with decimal
points). e.g. 14.2356

1. Write the following real constants into fractional form: 0.113E04, 0.417E-04,
0.4E-05, 0.123E02

Ans: 0.113E04 becomes 1130, 0.417E-04 becomes .0000417, 0.4E-05


becomes .000004, 0.123E02 becomes 12.3

1. What is a type or ‘Data Type’? How this term is related to programming?

Ans: A type or datatype represents a set of possible values. When we specify


that a variable has certain type, we are saying what values the expression can
have. For example to say that a variable is of type int says that integer values
in a certain range can be stored in that variable.

1. What is primitive data type? Name its different types.

Ans: Primitive data types are those that are not composed of other data types.
Numeric Integral, Fractional, character and boolean are different primitive data
types.

1. State the two kind on data types? [2006]

Ans: The two types of data types are: Primitive and non-
primitive/composite/user define data types. The primitive data types are: byte,
short, int, long, float, double, char and Boolean. The non-primitive/reference
data types are: class, array and interface.

1. Write down the names of three primitive and three non-primitive/reference


data types in Java/BlueJ.

Ans: The primitive data types are: byte, short, int, long, float, double, char and
Boolean. The non-primitive/reference data types are: class, array and
interface.

1. How many bytes occupied by the following data types: byte, short, int, long,
float, double, char, boolean.

Ans: char-2 byte, byte-1 byte, short-2 bytes, int-4 bytes, long-8 bytes, float-4
bytes, double-8 bytes, boolean-Java reserve 8 bits but only use 1 bit.

1. What is the range of the following data types: byte, short, int, long, float,
double, char, boolean.

Ans: byte -> -128 to 127

short -> -32768 to 32767

int -> -231 to 231-1

long ->-263 to 263-1

float -> -3.4×1038 to 3.4×1038

double -> -1.7×10308 to 1.7×10308

char -> 0 to 65536


boolean – > true or false

1. What is the largest and smallest value for floating point primitive data types
float?

Ans: The smallest value is -3.4E+38 and largest values is 3.4E+38 of floating
point data type.

1. What is Token? What are the tokens available in Java? [2008]

Ans: The smallest individual unit of a program is known as Token. The


following Tokens are available in Java:- Keywords, Identifiers, Literals,
Punctuations, Operators.

1. What do you mean by variables? [2006]

Ans: A variable is a named memory location, which holds a data value of a


particular data types. E.g. double p;

1. What do you mean by variables? What do you mean by dynamic initialization


of a variable?

Ans: A variable is a named memory location, which holds a data value of a


particular data types. When a method or functions is called and the return
value is initialise to a variable is called dynamic initialisation. example double
p=Math.pow(2,3);

1. What is the function of an operator?

Ans: Operators are special symbols that represent operations that can be
carried out on variables, constants or expressions.

1. What do you mean by operator and write the name of all operators given in
your textbook.
Ans: The operations are represented by operators and the object of the
operations are referred to as operands. The types of Operators available in
Java are: 1. Arithmetic 2. Increment/Decrement 3. Relational 4. Logical 5.
Shift 6. Bitwise 7. Assignment 8. Conditional 9. [] operator 10. new operator
11. (type) cast Operator 12. () operator. 13. dot operator.

1. What are arithmetic operators?

Ans: Arithmetical operators are used for various mathematical calculations.


The result of an arithmetical expression is a numerical values. Arithmetical
operators are of following types: Unary and Binary operators.

1. Write major difference between the unary and binary operators?

Ans: The operators that acts on one operand are referred to as Unary
Operator. There are two Unary operators Unary + operator and Unary –
operator. The operators that acts upon two operands are referred to as Binary
Operator. The Binary Operators are Addition(+), Subtraction (-), Multiplication
(*), Division (/) and Modulus (%).

1. What is increment operator? What are postfix and prefix increment operators?

Ans: The ‘++’ operator is called increment operator. The increment operators
add 1 to its operand. These are two types (i) Prefix and (ii) Postfix The prefix
version comes before the operand for e.g. ++a, where as postfix comes after
the operand e.g. a++

1. Find the value of x after evaluating x += x++ + –x + 4 where x=3 before the
evaluation. Explain your answer.
Ans: Result is 13, because x++ is 3, –x is 2 + 4 the answer is 9 add this with x
that is 3 it becomes 12 and due to pre increment of x++ the result becomes
13.

1. What do you mean by Relational Operators.

Ans: Relational operators are used to determine the relationship between


different operands. These are used in work of compression also. The
relational expression (condition) returns 0 if the relation is false and return 1 if
the relation is true. < (less then), > (greater then), <= (less then equals to), >=
(greater then equals to), == (equals to), != (not equals to).

1. What is Logical operators?

Ans: The logical operators combine the result of or more then two
expressions. The mode of connecting relationship in these expressions refers
as logical and the expressions are called logical expression. The logical
expression returns 1 if the result is true otherwise 0 returns. The logical
operators provided by Java are && Logical AND, || Logical OR, ! Logical NOT.

1. What do you man by Assignment Statement or Assignment Operator?

Ans: Assignment operator is represent by symbol ‘=’. It takes the value on the
right and stores it in the variable on the left side. for example x = y + 30

1. What do you mean by Shift operators? OR Differentiate between Shift LEFT


and Shift RIGHT operators.

Ans: A Shift operators performs bit manipulation on data by shifting the bits of
its first operand right to left. The shift operators available in Java are:

(1) >> shift bits of right by distance. (signed shifting)


(2) << shift bits of left by distance. (signed shifting)

(3) >>> shift bits of right by distance (unsigned shifting)

1. Differentiate between Shift LEFT and Shift RIGHT operators.

Ans: Shift LEFT (<<) operatr shifts the bit pattern of the operand towards left
by defined number of bits. Shift RIGHT (>>) operator shifts the bit pattern of
the operand towards right by defined number of bits.

e.g. 13>>2 is 3

binary value of 13 is 1101>>2 is 0011 is equivalent to 3. Similarly LEFT shift


(<<) operator is also work.

1. What do you mean by Bitwise operators?

Ans: The Bitwise operations are performed by Bitwise operator. The Bitwise
operations calculate each bit of their result by comparing the corresponding
bits of the two operands.

(a) The AND operator &

(b) The OR operator |

(c) The XOR operator ^

(d) The compliment operator ~

1. Illustrate ‘?’ operator with an example? [2009]


Ans: It is a conditional operator, that stores a value depending upon a
condition. This operator is also known as ternary operator. The syntax for this
operator is expression1?expression2:expression3 . and the example
is bonus=sales>15000?250:50;

1. What is the purpose of new operator? [2006]

Ans: We can use new operator to create a new objects or new array.

Ex. myClass obj = new myClass();

int arr[] = new int[5];

1. What do you mean by precedence? Illustrate with the help of example.

Ans: Precedence is the order in which a program evaluates the operations in


a formula or expression. All operators have precedence value. An operator
with higher precedence value is evaluated first then the operator having lower
precedence value. consider the following example

x = 5 + 4 *6;

The value of this expression is 29 not 54 or 34. Multiplication has been


performed first in this expression.

1. What is operands?

Ans: An operator acts on different data items/entities called operands.

1. What do you mean by constant? How you declare a variable as constant


variables.
Ans: The memory variables/locations whose values can not be changed within
the program is called constants. The keyword final makes a variable as
constants.

1. Which class is used for using different mathematical function in Java


program? [2007]

Ans: The class used for different mathematical functions in Java


is java.lang.Math

1. Write down the equivalent expression for the mathematical expression (a)
(cos x/tan-1 x)+x (b) |ex – x|

Ans: (Math.cos(x)/Math.atan(x)) + x and Math.abs(Math.exp(x)-x)

1. What is the difference between these two function Math.ceil() and Math.rint(),
explain with example.

Ans: Math.ceil() this function returns the smallest whole number greater then
or equal to the given number. e.g. Math.ceil(12.85) gives output 13
and Math.ceil(12.35) also gives output 13. Where as the Math.rint() returns
the roundup nearest integer value. e.g. Math.rint(12.85) gives output 13
but Math.rint(12.35) gives output 12.

1. What do you mean by type conversion? What is the difference between


implicit and explicit type conversion explain with example.

Ans: The process of converting one predefined type into another is called
Type Conversion.

A implicit type conversion is a conversion performed by the compiler. The


Java compiler converts all operands up to the type of the largest operand.
This is also known as type promotion. e.g. ‘c’-32 is converted to int type.
Where as an explicit type conversion is user defined that forces an expression
to be of specific type, this also known as type casting. e.g. (float)(x+y/2)

1. What is coercion? How it is implemented?

Ans: Implicit type conversion of an expression is termed as coercion. A implicit


type conversion is a conversion performed by the compiler. The Java compiler
converts all operands up to the type of the largest operand. This is default
type conversion.

1. What do you mean by type casting? What is the type cast operator? [2007]

Ans: The explicit conversion of an operand to a specific type is called type


casting. The operator that converts its operand to a specified type is called the
typecast operator. The typecast operator is ( ) in Java and is used as (type-to-
be-converted-in)

1. Explain the methods print() and println()?

Ans: A computer program is written to manipulate a given set of data and to


display or print the results. Java supports two output methods that can be
used to send the results to the screen. print() method println() method.

The print() method sends information into a buffer. This buffer is not flushed
until a new line (or end-of-line) character is sent. As a result print() method
prints output on one line.

The println() method by contrast takes the information provided and displays it
on a line followed by a line feed.

1. What is an Expression? Explain its different types.


Ans: An Expression is any statement which is composed of one or more
operands and return a vale. It may be combination of operators, variables and
constants. There are three different types of expressions.

(1) Constant Expressions: 8 * 12 /2

(2) Integral Expressions: formed by connecting integer constants x = (a + b)/2

(3) Logical Expressions: a > b or a!=b

1. Mention two different styles of expressing a comment in a program. [2005]

Ans: The two ways of inserting a comments in a program are:

(i) using // single line comments

(ii) using /* */ multiple line comments

1. Differentiate between operator and expression. [2005]

Ans: The operations are represented by operators and the object of the
operations are referred to as operands. The expression is any valid
combination of operators, constant and variables.

1. What is a compound Statement? Give an Example. [2005]

Ans: It is a block of code containing more then one executable statement. In


Java the { } is called block and the statements written under {} is called
compound statements or block statement. The { } opening and closing braces
indicates the start and end of a compound statement.

for(int i=1;i<=5;i++)
{

System.out.println(“Hello”);

System.out.println(“How”);

System.out.println(“are you?”);

Use of Constructor

[ICSE Syllabus on this Topic]

Default constructor, Constructor with arguments, default initializing.


Overloading constructor.
1. 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.

1. Why do we need a constructor as a class member? [2007]

Ans: Constructor is used create an instance of of a class, This can be also


called creating an object.

1. 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.

1. Explain default constructor? [2006]

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.

1. 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;

1. Give an 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;

1. 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.

1. 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.

1. 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.out.println(“the value of a and b after swaping : “+a+” “+b);

1. What are the types of Constructors used in a class?

Ans: The different types of constructors are as follows:

1. Default Constructors.
2. Parameterized Constructor.

iii. Copy Constructors.

1. 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;

User Define Functions

[ICSE Syllabus on this Topic]

Function as a way to define operations/methods/messages. Pure functions


return values and do not change state, impure functions may return values but
also change state, return type argument to function, function prototype and
function signature, overloading. Variable of a class type as reference to an
objects, invocation of function on objects through the reference, the concept of
this. Argument passing in functions, pass by value, what happened when a
reference is passed side effect.

1. 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.

1. 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.

1. 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)

1. 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.

1. 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.

1. 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.

1. 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.

1. Write advantages of using functions in programs


Ans: (i) functions lessen the complexity of programs (ii) functions hide the
implementation details (iii) functions enhance reusability of code

1. 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.

1. 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.

1. 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.

1. 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.

1. 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.
1. 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.

1. 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 void increment(Time obj, double secs)

time.seconds+=secs;

return(Time);

1. 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.
1. How are following passed in Java? [2005]

(i) primitive types (ii) reference types

Ans: (i) By value, (ii) By reference.

1. 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.

1. 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);

1. 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.

1. 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.

1. 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.

Class as a User Defined Types

[ICSE Syllabus on this Topic]

Class as a composite type, distinction between primitive type and composite


of class type.

1. What is data type?

Ans: Data types are means to identify the type of data and associated
operations of handling it.

1. 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;

1. 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.

1. Can you refer to a class as a user defined (composite) datatype? [2009]

Ans: Yes, we can refer to a class not having a main() method as user-defined
datatype.

1. What is the difference between primitive datatypes and composite datatypes?

Ans: (i) primitive datatypes are built-in datatypes. Java provides these
datatypes. User-defined datatypes are created by users. (ii) The size of
primitive datatypes are fixed. The size of user-defined datatypes are variable.
(iii) Primitive datatypes are available in all parts of Java programs. The
availability of user-defined datatypes depends upon their scope.

1. Compare a class as a user defined datatype and class as an application?

Ans: In Java, all functionality is enclosed in classes. But in order for a class to
be user-defined datatype, 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 datatype. Such classes (containing main() method) are more
analogues to application than a datatype.

1. Where can the following members of a class be accessed? private, protected,


public and default access. [2008]

Ans: Access specifier can be of following types:

(a) PUBLIC: Public members of a class are globally accessible.

(b) PRIVATE: Private members of a class be accessed by the member


functions of the class only.

(c) PROTECTED: Protected members of a class are accessible in the


package where the class is defined and in all the sub-classes of the class.

(d) Default (friendly) access: members with default (friendly) access can be
used within the package where the class is defined.

1. 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.

1. 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.

1. 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

Decision Making

[ICSE Syllabus on this Topic]

Application of if-then, if-then-else, switch (default, break).

1. What is a statement?

Ans: Statements are the instructions given t the computer to perform any kind
of action, as data movements, making decision or repeating action.
Statements form the smallest executable unit and terminated with semi-colon.

1. What are the three constructs that govern statement flow?


Ans: The three constructs that governs statement flow are: Sequence,
Selection and Iteration constructs.

1. What is a selection/conditional statement? Which selection statements does


Java provides?

Ans: A selection statement is the one that is used to decide which statement
should be execute next. This decision is based upon a test condition. The
selection statements provided by Java are: if-else and switch. The conditional
operator ?: can also be used to take simple decision.

1. What is an ‘if’ statement? Explain with an example.

Ans: the ‘if’ statement helps in selecting one alternative out of the two. The
execution of ‘if’ statement starts with the evaluation of condition. The ‘if’
statement therefore helps the programmer to test for the condition. General
form of ‘if’ statement.

if(expression) statement

if(marks>=80)

System.out.println(“Grade A”);

1. What is the significance of a test-condition in a if statement?

Ans: It is the test condition of an if statement that decides whether the code
associated with the if part or the one associated with the else part should be
executed. The former is executed if the test condition evaluates to true and
the latter works if the condition evaluates to false.

1. Write one advantage and one disadvantage of using ?: in place of an if.


Ans: Advantage: It leads to a more compact program. Disadvantage: Nested
?: becomes difficult to understand or manage.

1. What do you understand by nested ‘if’ statements?

OR

1. Explain with an example the if-else-if construct. [2007]

Ans: A nested ‘if’ is an statement that has another ‘if’ in its body or in it’s
appearance. It takes the following general form.

if(ch>=’A’)

if(ch<=’Z’)

++upcase;

else

++other;

1. What is the problem of dangling-else? When does it arise? What is the default
dangling-else matching and how it be overridden?

Ans: The nested if-else statement introduces a source of potential ambiguity


referred to as dangling-else problem. This problem arises when in a nested if
statement, number of if’s is more then the number of else clause. The
question then arises, with which if does the additional else clause property
match. For Example

if(ch>=’A’)

if(ch<=’Z’)

++upcase;

else

++other;

The indentation in the above code fragment indicates that programmer wants
the else to be with the outer if. However Java matches an else with the
preceding unmatched if. One method for over-riding the default dangling-else
matching is to place the last occurring unmatched if in a compound statement,
as it is shown below.

if(ch>=’A’)

if(ch<=’Z’)

++upcase;

else
++other;

1. Compare and contrast IF with ?:

Ans: (i) Compare to IF sequence, ?: offer more concise, clean and compact
code, but it is less obvious as compared to IF. (ii) Another difference is that
the conditional operator ?: produces an expression, and hence a single value
can be assigned, for larger expression If is more flexible. (iii) When ?: operator
is used in its nested form, it becomes complex and difficult to understand.

1. What is a switch statement? How is a switch statement executed?

Ans: Switch statement successively tests the value of an expression against a


set of integers or character constants. When a match is found, the statements
associated with the constants are executed. The syntax switch(expression)

case constants : statements; break;

case constants : statements; break;

The expression is evaluated and its values are matched against the value of
the constants specified in the case statements. When a match is found, the
statements sequence associated with that case is executed until the break
statement or the end of switch statement is reached.

1. What is the significance of break statement in a switch statement?


Ans: In switch statement when a match is found the statement sequence of
that case is executed until a ‘break’ statement is found or the end of switch is
reached, when a ‘break’ statement is found program execution jumps to the
line of code following the switch statement.

1. What is a control variable in a switch case?

Ans: A control variable in switch case is one which guides the control to jump
on a specified case. e.g. switch(x), here ‘x’ is the control variable.

1. What is a “fall through”?

Ans: The term “fall through” refers to the way the switch statement executes
its various case sections. Every statement that follows the selected case
section will be executed unless a break statement is encountered.

1. What is the effect of absence of break in a switch statement?

Ans: Absence of break statement in a switch statement leads to situation


called “fall through” where once a matching case is found the subsequence
case blocks are executed unconditionally

1. Write one limitation and one advantage of switch statement?

Ans: Advantage: More efficient in case a value is to be tested against a set of


constants. Disadvantage: switch can test only for quality, so for the rest of
comparisons one needs to use if-else.

1. Discuss when does an if statement prove more advantageous then switch


statement.

Ans: In the following case if statement proves to be more advantage over


switch statement: (i) When a range of values need to be tested for. (ii) When
relation between multiple variables needs to be tested. (iii) When multiple
conditions need to be tested. (iv) When expressions having a data type other
then integer or character need to be tested.

1. When does switch statement prove more advantageous over an if statement?

Ans: The switch statement is more advantageous then the if statement when
the test expression whose data type is either of byte, short, character, integer
or long is to be tested against a set of constants. The reason being that the
switch statement evaluates the expression once whereas the equivalent if
statement evaluates the expression repeatedly.

1. Explain, with the help of an example, the purpose of default in a switch


statement. [2005]

Ans: The default section is an optional part of the switch statement and the
statement written under default clause are executed when no matching case
is found.

switch(n)

case 1: System.out.println(“Sunday”); break;

case 2: System.out.println(“Monday”); break;

case 3: System.out.println(“Tuesday”); break;

case 4: System.out.println(“Wednesday”); break;

case 5: System.out.println(“Thursday”); break;


case 6: System.out.println(“Friday”); break;

case 7: System.out.println(“Saturday”); break;

default : System.out.println(“Invalid Input”);

1. Differentiate between if and switch statements. [2006]

Ans: Both are used as a selection statements, there are some difference in
their operations. (i) switch can only test for equality, where as if can evaluate a
relational or logical expression. (ii) it statement can handle ranges , where as
switch case level must be a single value. (iii) if statement can handle floating
point test also, where as the switch case labels must be an integer or
character.

Concepts of Conditions and Loops

[ICSE Syllabus on this Topic]

Utilization of loops. Fixed number of Iteration. The for Loop, unknown number
of Iteration – while, do-while loop, continue, break. Nested Loops.

1. 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.

1. 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.

1. Explain the difference between break and continue with an example. [2005]
[2008]

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 Statement

int i=0;

while(i<=10)

{
i++;

if(i==5)

break;

System.out.println(i);

e.g. of Continue Statement

int i=0;

while(i<=10)

i++;

if(i==5)

continue;

System.out.println(i);

1. 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.

1. Explain the term for loop with an example. [2005]

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);

1. State one similarity and one difference between while and do-while loop.
[2005]
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.

1. What do you meant by an infinite loop? Give an example. [2008]

OR

1. 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”);

1. 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 oft imes. variable iterative loop repeats the process till a
given condition is true.

1. 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++)

1. 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.

Using Library Classes

[ICSE Syllabus on this Topic]

Simple input, output. String, static variables and static methods, packages and
import statements.

1. What is the difference between byte oriented IO and character oriented IO?
How are these two performed in Java?

OR

1. What are the two ways of obtaining input in Java?

Ans: Bye oriented IO reads bytes of data or binary where there is no notation
of datatypes. Character oriented IO on the other hand performs IO which is
specially character oriented. In Java byte oriented IO is performed through
data streams where as character oriented IO is performed through Readers
and Writers.

1. What is an Exception?

Ans: Exception in general refers to some contradictory or unusual situation


which can be encountered while executing a program.
1. What is exception and what is exception handling? [2008]

Ans: During program development there may be some cases where the
programmer does not have the certainty that this code-fragment is going to
work right, either because it accesses resources that do not exist or it goes
out of range. These types of anomalous situations are generally called
exception and the way to handle then is called exception handling.

1. What are the advantages of Exception Handling?

Ans: (i) Exception handling separates error handling code from normal code.
(ii) It clarifies the code and enhanced readability. (iii) It stimulates
consequences as the error handling takes place at one place and in one
manner. (iv) It makes for clear, robust, fault tolerant programs.

1. When is Exception Handling required?

Ans: The exception handling is ideal for:

(i) Processing exceptional situations.

(ii) Processing exceptions for components that handle them directly.

(iii) Processing exceptions for widely used components that should not
process their own exception.

1. What do you mean by try block? How do you define it, give an example.

Ans: The try block is the one that contains the code that is to be monitored for
the occurrence of an exception. A try block is defined by enclosing the
statements that might possible raise an exception in. For example if the
formatting exception are to be handled while an integer is being read from the
keyboard, then the following try block can be used:

int inData;

BufferedReader br=new BufferedReader( new


InputStreamReader(System.in));

try

inData=Integer.parseInt(br.readLine());

1. What do you mean by catch block? How do you define it, give an example.

Ans: The catch block is the one that contains the code handle an exception. It
must follow the try block. i.e. there should be no statement between the try
and the catch blocks. If the catch block is written for the above try block then
we may do it as follows:

int inData;

BufferedReader br=new BufferedReader( new


InputStreamReader(System.in));

try

{
inData=Integer.parseInt(br.readLine());

catch(NumberFormatException nfEx)

System.out.println(“Input format is incorrect”);

1. What is finally block? When and how it is used.

Ans: The finally block is one of the exception handling blocks. The code
written in this block is always executed irrespective of whether an exception
was reported or not, or even if it was handled successfully or not. The purpose
of this block is to do cleaning up tasks, e.g. closing files etc.

1. Write down the function of the following IO Exception classes: EOFExcpetion,


FileNotFoundException, InterruptedIOException, IOException.

Ans: EOFException: Signals that an and of the file or end of the stream has
been reached unexpectedly during input.

FileNotFoundException: Informs that a file could not be found.

InterruptedIOException: Warns that an IO operation has been interrupted.

IOException: Signals the an IO exception of some sort has occurs.

1. What are wrapper classes? [2006]


Ans: Wrapper classes are the part or Java’s standard library java.lang and
these convert primitive datatypes into an object. to be more specific, a
wrapper class wraps a value of primitive types in an object. Java provides the
following wrapper classes: Boolean Integer, Float, Double, Character etc.

1. Why do we need a wrapper class?

Ans: A wrapper class is needed to store primitive values in objects as well as


in conversion from string to to primitive type.

1. Distinguish between data type and wrapper class.

Ans: A data type starts with lowercase letter and wrapper class starts with
uppercase letter.

1. Define String?

Ans: A string is a set of two or more then two characters, a set of characters
with the digit or a statement written with in double quotes. e.g. “Happy New
Year”, “Computer Application” etc.

1. What is String Buffer? How we create a String Buffer?

Ans: String Buffer is a type of memory location, which allows reasonable


space to contain a string such a way that any change brought affect the same
string.

String Buffer is created as follows: StringBuffer p=new


StringBuffer(“Computer”);

1. Differentiate between String and StringBuffer objects.


Ans: The String object of Java is immutable, i.e. once created they can not be
changed. if any change occurs in a String object, then original object string
remains unchanged and a new String is created with the changed String.
StringBuffer objects are mutable, on the other hand. That is these objects can
be manipulated and modified as desired.

1. Write down the purpose of the following string functions: toLowerCase(),


toUpperCase(), replace(), trim(), equals(), length(), charAt(), concat(),
substring(), indexOf(), compareTo().

Ans: The purpose and syntax of the following string functions are:

toLowerCase(): This function converts all the characters of the string in lower
case.

for example:

String n=”AMITABH”;

n=n.toLowerCase();

System.out.println(n);

toUpperCase(): This function converts all the characters of the string in upper
case.

for example:

String n=”amitabh”;

n=n.toUpperCase();
System.out.println(n);

replace(): This function replace all the occurrence of a characters with another
one.

String n=”DAD”;

n=n.replace(‘D’,’G’);

System.out.println(n);

trim(): This function is used to remove all the white spaces at the beginning
and end of string.

String n=”AMIT “;

n=n.trim();

System.out.println(n);

equals(): This function is used to compare two string and give true or false if
they are equal.

String s1=”AMIT”;

String s2=”amit”;

System.out.print(s1.equals(s2));

length(): This function return the length characters present in the string.

String s=”AMITABH”;
System.out.print(s.length());

charAt(): This function return the nth character of the string.

String s=”AMITABH”;

System.out.print(s.charAt(2));

concat(): This function concatenate/join two strings.

String s1=”AMITABH “;

String s2=”BANERJEE”

System.out.print(s1.concat(s2));

substring(): This function returns the substring starting from the nth character
of the string.

String s=”AMITABH”;

System.out.print(s.substringt(3));

This function also returns the substring starting from the mth character upto
the nth character without including the nth character of the string.

String s=”AMITABH”;

System.out.print(s.substringt(2,4));

indexOf(): This function returns the position of the first occurrence a character
in the string.
String s=”AMITABH”;

System.out.print(s.indexOf(‘A’));

This function also returns the position of the character from the nth position of
the string.

String s=”AMITABH”;

System.out.print(s.indexOf(‘A’,2));

compareTo(): This function returns negative if first string is less then second
string, positive if greater and zero if equals.

String s1=”AMIT”;

String s2=”SUMIT”

System.out.print(s1.compareTo(s2));

1. What is the difference between equals() and equalsIgnoreCase() string


functions?

Ans: Both the functions is used to compare strings, the difference being that
equals() distinguishes between upper case and lower case version of a
character, where as equalsIgnoreCase() carries out comparison ignoring the
case of characters.

1. Differentiate between equals() and compareTo() methods. [2006]

Ans: Both the functions is used to comparing two strings, the difference being
that (i) equals() method only comparing two string and gives they are equal or
not, where as compareTo() methods also gives whether first string is greater
or smaller then second one. (ii) equals() methods returns a boolean value,
where as compareTo() methods return integer value.

1. Differentiate between toLowerCase() and toUpperCase() methods. [2005]

Ans: The given two string method’s change the case of the current string. The
toLowerCase() method change the current string object to its equivalent
Lower Case, where as toUpperCase() method change the current string
object to its equivalent Upper Case.

1. What is the difference between the length() and capacity() string function.

Ans: The function length() returns the number of character contains in a string.
Where as capacity() returns the maximum number of character that can be
stored in a string objects.

1. Name some of the most used packages? [2007]

Ans: Language extensions java.lang, utilities java.utill, input-output java.io,


GUI java.awt and javax.applet, network services java.net etc.

1. Define static members?

Ans: The members that are declared static are called static members. These
members are associate with the class it self rather than individual objects.

1. What are static variables?

Ans: Static variables are used when we want to have a variable common to all
instances of a class.

1. What are the restrictions of static methods?


Ans: (i) They can only call other static methods.

(ii) They can only access static data.

(iii) They cannot refer to ‘this’ or ‘super’ keywords in anyway.

1. What are packages? [2006]

Ans: Java contains extensive library of pre-written classes we can use in our
programs. These classes are divided into groups called packages. Various
packages in Java are:
java.applet, java.awt, java.io, java.lang, java.new, java.util etc.

1. What are the benefits of organizing classes into packages.

Ans: In packages classes can be unique compared to other programs and be


easily be reused.

1. What are Java API packages:

Ans: Java API packages provide a large number of class grouped into
different packages according to functionality.

1. What are system packages?

Ans: The packages which are organised in hierarchical structure are referred
as system packages.

1. Explain the method on importing a package member?

Ans: To import a member of package into the current file, put an import
statement at the beginning of the file before any class definitions but after the
package statement, if there is one .
1. Describe the method to import entire package?

Ans: To import a member all the classes contained in a particular package,


using the import statement with the asterisk(*) wild card character.

1. Distinguish between Static variable (class variable) and member variable


(instance variable)

(i) Declare with the static keyword.

(ii) Exist at class level and can be used even if no instance of class exist in
memory.

(iii) Created when class is first referred to.

(iv) Destroyed when the program is over.

(v) Can be accessed using either the class name or name of any instance of
the class. (i) Declare without the static keyword.

(ii) Exist at instance level i.e. can not be used if there are no instance of class
exist in memory.

(iii) Created with each instance.

(iv) Destroyed when the instance containing them is destroyed.

(v) Can be accessed using the name of the instance only to which they
belong.

1. Explain instance variable. Give an Example. [2008]


Ans: A data member that is created for every objects of the class.

public class abc

int a,b; // instance variable or data member

1. State the difference between == operator and equals() method. [2008]

Ans: ==: 1. It is a relational operator. 2. it tests the value on the right side with
value on the left side.

equals(): 1. It is a string function. 2. It compares two strings and gives the


value as true or false.

Encapsulation

[ICSE Syllabus on this Topic]

private, public, scope and visibility rules. packages and package level access.

1. Explain the term ‘Encapsulation’ with an example? [2006]

Ans: The wrapping up to data and methods into a single units (called class) is
known as encapsulation. For example an engine of car or any vehicle
contains many small parts, which enables the entire machinery system to
work. Encapsulation property hides the inner working of objects from the real
world.

1. What does a class encapsulate?

Ans: A class encapsulate Data Members that contains the information


necessary to represent the class and Member Functions that perform
operations on the data member.

1. How does a class enforce information hiding?

Ans: Classes enforce information hiding by means of access specifier.

1. What is initial class?

Ans: A java program contains many classes. But one class in a Java program
contains the main() method. This class is called initial class.

1. What is Class variable (Static Variable)?

Ans: A data member that is declared once for a class. All objects of that class
type, share these data members, as there is single copy of them available in
memory. Keyword ‘Static’ in the variable declaration makes a class variable.

1. What is Instance variable? [2007] [2008]

Ans: A data member that is created for every objects of the class.

1. What does the class consists of ?

Ans: A class consists of:

(i) Data members: It contain information necessary to represent that class .


(ii) Methods: It perform operations on the data members of the class.

1. What is visibility modifiers?

Ans: It is also called access specifier. It defines which function or method is


able to use this method.

1. Define variable’s scope (scope rule)?

Ans: The program parts in which a particular data value (e.g., variable) can be
accessed is known as variable’s scope.

1. Define the term visibility?

Ans: Visibility is a related term which refers to whether one can use a variable
from a given place in the program.

1. Define the term Local variable and Global variable.

Ans: Local Variable: Variable declared inside a method or block.

Global Variable: Class variable which is available to the entire class.

1. Mention the levels of scope and visibility offered by java?

Ans: (i) Data declared at the class level can be used by all methods in the
class.

(ii) Data declared within a method can be used only in the method.

(iii) Data declared within a method is called local data.


(iv) Variable that are declared in block i.e., local variable are available to every
method inside of the block.

(v) Variable declared in interior blocks are not available outside of that block.

(vi) Variable declared in exterior blocks are visible to the interior blocks.

1. Explain the different types of access specifier?

Ans: Access specifier can be of following types:

(a) PUBLIC: It means that any one can call this method.

(b) PRIVATE: It means that only the methods in the same class are permitted
to use this method.

(c) PROTECTED: It means that methods in this class and methods in any
subclass may access this method.

1. What are member variables? State their types?

Ans: Member variables are also known as Instance variables. These member
variables are used to store value in the class. It may be public, private and
protected, where private and protected members remains hidden from outside
world and there by support data.

1. What is meant by private visibility of a method? [2006]

Ans: PRIVATE visibility of a Method means that only the methods in the same
class are permitted to use this method.

Arrays
[ICSE Syllabus on this Topic]

Array and their usage, sorting algorithm – selection sort and bubble sort,
search in sorted array. The class objects compatible with all the class.

1. What do you understand by Arrays? How you declare an Array?

Ans: An Array is a collection of variables of the same data type that are
referenced by a common name. Array can be declared by the following
statements: int n[]=new int[10];

1. What are the different types of arrays?

(i) Single Dimensional Arrays: A list of items can be given one variable name
using only one subscript and such a variable is called a single subscripted
variable or a one or single dimensional array.

(ii) Multi Dimensional Arrays: This type of arrays are actually arrays of arrays.

1. Why we use Arrays? or What are the Advantages of using Arrays.

Ans: The Advantages or Arrays are: (i) Easy to Specify. (ii) Free from run-time
overload. (iii) Random access of elements. (iv) Fast Sequential Access.

1. How can arrays be initialized?

Ans: Array can be initialized at the time of declaration by providing the value
list at the same time.
1. What do you understand by out-of-bound subscripts?

Ans: The subscripts other than 0 to n-1 for an array having n elements are
called out-of-bounds subscripts.

1. What do you mean by Binary Search?

Ans: This search technique searches the given ITEM in minimum possible
compression. The Binary search requires the array must be sorted in any
order. The search ITEM is compared with middle element of the array. If the
ITEM is more then the middle element later part of the arrays becomes the
new array segment. The same process is repeated until either the ITEM is
found or the array segment is reduce to single element.

1. Differentiate between linear search and binary search techniques? [2007]

Ans: In linear search each elements of the array is compared with the given
item to be searched for one by one while binary search searches for the given
item in a sorted array. The search segment reduces to half at every
successive stage.

1. State the conditions under which Binary Search is applicable?

Ans: For Binary Search The List must be sorted, lower bound upper bound
and the sort order of the list must be known.

1. Comment on the efficiency of linear search and Binary Search in relation to


the number of element in the list being searched?

Ans: The Linear search compares the search item with each element of the
array, one by one. If the search item happens to be in the beginning of the
array, the compressions are low, however if the element to be searched for is
one of the last elements of the array, this search technique proves the worst
as so many comparisons take place. The Binary search on the other hand,
tries to locate the search item in minimum possible comparisons, provided the
array is sorted. This technique proves efficient in nearly all the cases.

1. What do you mean by sorting?

Ans: Sorting of an array means arranging the array elements in a specified


order.

1. What is Selection sort?

Ans: In selection sort the smallest ( or largest depending upon the desired
order) key from the remaining unsorted array is searched for and put in the
sorted array. The process repeats until the entire array is sorted.

1. What is Bubble sort?

Ans: In bubble sort the adjoining values are compared and exchanged if they
are not in proper order. This process is repeated until the entire array is
sorted.

1. Which element is num[9] of the array num? [2005]

Ans: 10th element. Because the first index number/subscript value of an array
is 0. So 9th element is treated as the 10th element in an array.

Operations on File

[ICSE Syllabus on this Topic]


Stream – byte and character stream, files and operation on files. token and
String Tokenizer and stream Tokenizer classes.

[Note: no questions shall be asked in the theory paper from Operation on


Files]

1. What is File?

Ans: A file is a means of making data persistent. It is a set of bytes that is


stored on a storage device and can be referred to by a name.

1. What is Java Stream?

Ans: A stream in Java is a path along with data flows.

1. Why is streams need?

Ans: All programs need to handle data flow to or from a file, a pipe or an I/O
device. Stream are object representation of this flowing data and are used by
java to carry out data interchanged in a program.

1. What is the role of Input Stream class?

Ans: InputStream class provides the basis for classes used to read binary
data from a file, a pipe or an input device.

1. What is the role of a Reader class?

Ans: Reader class provides the basis for classes used to read character data
from a file or an input device.
1. What is the role of Output Stream class?

Ans: OutputStream class provides the basis for classes used to write binary
data to a file, a pipe or an output device.

1. What is the role of a Writer Class?

Ans: Writer class provides the basis for classes used to write character data to
a file, a pipe or an output device.

1. Name the most commonly used classes for handling Byte oriented IO.

Ans: Classes for byte I/O are DataInputStream and DataOutputStream.

1. Can we open an existing file for writing? If not, why?

Ans: When an existing file is to be opened for writing all the data of the file is
truncated unless it is opened in the append mode using the following syntax:

FileOutputStream file=new FileOutputStream(“student.dat”,true);

1. What are Input and Output stream.

Ans: An input stream is a sequence of bytes flowing from data source or an


input device to the program memory, where as output stream is a sequence of
bytes flowing from the program memory to a data store or an output device.

1. What is Buffer? What is buffered I/O?

Ans: A buffer represent a section of memory used as a staging area for input
or output data? Buffered I/O is an input or output operation that uses
temporary storage called a buffer to hold data before it is transferred from the
source to the destination.

1. What is Input Buffer? What is Output buffer?

Ans: An input buffer is used for sending a large chunk of data from a stream.
the buffer is then accessed as needed and when emptied another chunk of
data is read from the stream into the buffer. An output buffer is used to store
up data to be written to a stream. Once the buffer is full, the data is sent to the
stream all at once and the buffer is emptied to receive more data.

1. What is the String Tokenizer?

Ans: A String Tokenizer can identify and parse (segregate) token in a string.
String Tokenizer class is found in java.util package. String Tokenizer class
also provides two methods that are immediately used for processing strings.
(i) countToken() (ii) nextToken()

1. What is the StreamTokenizer class used for?

Ans: A Stream Tokenizer takes an input stream and parses it into tokens,
allowing the tokens to be read one at a time. When reading an input string
supplied by a user we like to be able to analyze it token by token. To isolate
such tokens, we use the String Tokenizer class. We can also use the string
Tokenizer to process input from a file line by line.

1. What is the difference between Text file and Binary file?

Ans: In text file data are stored as per a specific character encoding scheme.
In binary files, data are stored in the form of bytes that are machine readable
form.
1. What is the significance of java.io package file?

Ans: The package java.io provides classes that encapsulate input and output
stream in various forms. This package provides API that can be used to
perform character/byte based data input/output in Java program.

Q. The following program is supposed to check the given number is prime or not. Some part
of the program is replaced by ______, with the numbering 1 to 5, fill this part so that program
works correctly.
class checkPrime
{
public static void main(String args[])
{
int i, f=0;
int n = Integer.parseInt(args[0]);
for(i=__1__; __2__; i++)
{
if(__3__==0)
{
f=__4__;
break;
}
}
if(f==__5__)
System.out.print(“The given no. “+n+” is a prime number”);
else
System.out.print(“The given no. “+n+” is not a prime number”);
}
}

Ans: (1) 2 (2) i<n or i<=n/2 (3) n%i (4) 1 or f++ (5) 0

Q. The following program is supposed to print the following pattern. Some part of the
program is replaced by ___n____ where n is 1 to 5, fill this part so that program works
correctly.
5
45
345
2345
12345
class ques
{
public static void main(String args[])
{
for(__1__; __2__; i–)
{
for(__3__; __4__; __5__)
System.out.print(j);
System.out.println();
}
}
}

Ans: (1) int i=5 (2) i>=1 (3) int j=i (4) j<=5 (5) j++

Q. Given an array of 6 elements [2,6,12,20,30,42], the difference of successive elements


may be different of previous numbers are as follows. The following program supposed to
print out the following output.
2 6 12 20 30 42
4 6 8 10 12
2222
000
00
0
Some part is replaced by ____, with numbering 1 to 5, fill this part so that program works
correctly. [10]
public class elements
{
public static void main()
{
int a[]={2,6,12,20,30,42};
int n=___1___;
for(int i=0;i<6;i++)
{
System.out.println();
for(int j=0;j<___2___;j++)
System.out.print(” “+a[j]);
___3___;
for(int j=0;j<n;j++)
a[j]=___4___ – ___5___;
}
}
}

1. 6
2. n
3. n–
4. a[j+1]
5. a[j]
Q. The following function is a part of a class. It computes x raised to the power n. Here x is
the base and n is the power. Some part is replaced by ______, with numbering 1 to 5, fill this
part by expressions or statements so that program works correctly. [10]
double integralPower(double x, int n)
{
int inverse = 0;
double result = 1.0;
if (n == 0)
return ___1___;
else if (n < 0)
{
inverse = 1;
n = ___2___;
}
for(int i=1; ___3___; i++)
{
double temp =___4___;
result = ___5___;
}
return result;
}

1 -> 1
2 -> Math.abs(n)
3 -> i<=n
4 -> (inverse==0)?x:1/x
5 -> result*temp

Q. The following function is part of a class, which finds the lowest common devisor (except 1)
of two given numbers. Some part is replaced by _____, with numbering 1 to 5, fill this part by
expressions or statements so that program works correctly. [10]
public class lcd
{
public int main(int num1,int num2)
{
int small, res, found;
small = ___1___;
res = 2;
found = 0;
while(found==0 && ___2___)
{
if(num1%res==0 && num2%res==0)
___3___;
else
___4___;
}
if(found==0)
return(___5___);
else
return(res);
}
}

1 -> (num1>num2)?num2:num1
2 -> res<=small
3 -> found=1
4 -> res++
5 -> num1*num2

Q. The public function find() has been written to do a binary search for the integer m in the
sorted integer array data. The array is sorted in ascending order. If m is present in data then
it returns 1 else 0. Some part is replaced by ______, with numbering 1 to 5, fill this part by
expressions or statements so that program works correctly. [10]
int find(int m, int data[], int size)
{
/* data is a sorted array of integers arranged in ascending order. size gives the number of
elements in the array. m is the integer which we are trying to search in the array.*/
int found = 0;
int j = 0, k = ___1___;
int i=(j+k)/2;
if(___2___)
{
while(___3___)
{
i=(j+k)/2;
if(m==data[i])
{
___4___; break;
}
else
{
if(___5___) j=i+1;
else k=i-1;
}
}
}
return(found);
}

1 -> size-1
2 -> data[(j+k)/2]>m
3 -> j<=k && found==0
4 -> found=1
5 -> data[I]<m
Q. What will be the output of the following method for x(5,8)
public void x(int a, int b)
{
a=a+b;
b=a-b;
a=a-b;
System.out.print(a);
System.out.print(b);
}
What is the method computing/solving? What names you give to the method x() so that it’s
name become mnemonic.

Ans: The output of the method is 5 8 , the method interchange the value of two variables.
The name of the method must be swap() instead of x() so that it’s name is most
understandable.

Q. Given the following declarations:


String a=”abc”;
String s=a;
String t;
What is the value of the following expression (assume that there is no error)?
a) s.length();
b) 1+a;
c) “Tomorrow”.indexOf(‘r’);
d) “Tomorrow”.substring(2,4);
e) (a.length()+a).startsWith(“a”);
f) a.substring(1,3).equals(“bc”);

a) 3 b) 1abc c) 4 d) mor e) false f) true

Q. What is the output of the following program? [2]


public class check
{
public static void change(String nm)
{
nm = “Kush”;
}
public static void main()
{
String name = “Sandeep”;
System.out.println(name);
change(name);
System.out.println(name);
}
}
Sandeep
Sandeep

Q2. What will be the output of the following function? [4]


i) Math.pow(3,0.5) ii) Math.min(-21,-12)
iii) Math.ceil(5.2) iv) Math.floor(2.9)

i) 1.7320 ii) -21 iii) 6.0 iv) 2.0

Q4. Evaluate the following expression: when a=10, b=8 [4]


i) ++a-b– ii) a%b++
iii) a*=b+5 iv) x=69>>>2

(i) 3 (ii) 2 (iii) 130 (iv) 17

Q5. Write the java expressions for each of the following: [4]
(i) x = e|2x – 4x|
(ii) s=`/sin a + tan-1 a – e2x

(i) Math.exp(Math.abs(2*x-4*x)) (ii) Math.sqrt(Math.sin(a)+Math.atan(a)-


Math.exp(2*x))

Q. Find the output of the following questions. Give the dry run or working. In one line say
what is being computed by the function. [10]

public class output2


{ // if the value of n is 5
public static int unknown(int n)
{
int i,k;
if(n%2==0)
{
i=n/2;
k=1;
}
else
{
k=n;
n–;
i=n/2;
}
while(i>0)
{
k=k*i*n;
i–;
n–;
}
return(k);
}
}

120 it calculate the factorial of a number.

public class output3


{
public static void main()
{
int n=5732,result=0;
do
{
result *= 10;
int digit = n%10;
result += digit ;
n = n/10;
}while(n>0);
System.out.println(“Output = ” + result);
}
}

Output = 2375 it reverse the number.

Q. If the function trial() is member of some class.


public static void trial()
{
int item[]={9,0,4,1,16};
int j,k;
for(j=0,k=0;j<4;j++,k++)
{
if(item[k]<item[k+1])
{
int a = item [k] ;
item [k] = item [k+1];
item [k+1] = a;
}
}
}
(i) State the final value of j, k at the end of function. [2]
(ii) What are the values stored in the array item[] after this function is executed? [6]
(iii) In one line say what is being done by the function trial() state the technique used. [2]

(i) j = 4 k=4
(ii) 9 4 1 16 0
(iii) The function move the lowest number to the end of the array. The name of the technique
used is called bubble sort.

Q. What will be the output of the following program [3+2]


public class q3
{
public static void main()
{
int r;
for(int i=1;i<5;i++)
{
r=output(i);
System.out.print(r+” “);
}
}
private static int output(int num)
{
if(num==1)
return(1);
else
return (num + output(num-1));
}
}
What type of function “output()” is called and what care should be taken when we write the
definition of this type of function?

1 3 6 10
The function “output()” is called recursive function. While writing this type of function the
function definition part must contains a condition to stop the process.

Q. State the output of the following code segment:


public class q5 [3]
{
public static void main(String args[])
{
int result=0;
for(int i=0;i<=5;i++)
result=result+nextNum(i);
System.out.println(result);
}
public static int nextNum(int curr)
{
return (curr%2==0)?curr:0;
}
}
What is the above function do? [1]
6
The above function print sum of all even numbers from 0 to 5.

Q. The following public function is part of some class. Assume n is always positive. Answer
the given questions. Give the dry run/working.
public static int unknown(int n)
{
int i,k;
if(n%2==0)
{ i=n/2; k=1; }
else
{ k=n; n–; i=n/2; }
while(i>0)
{ k=k*i*n; i–; n–; }
return(k);
}
i. What value will be returned by the expression unknown(7) [4]
ii. What value will be returned by the expression unknown(6)[4]
iii. In one line say what is being computed by the function [2]

(I) 5040
(II) 720
(III) The above function calculates the Factorial of a given number.

Q. The following public function is part of some class. Assume n is always positive. Answer
the given questions. Give the dry run/working. [4+4+2]
int someFn(int a, int b)
{
int ans,sm,la;
if(a<b) { sm=a; la=b; }
else { sm=b; la=a; }
ans=la;
while(ans%sm!=0)
ans+=la;
return(ans);
}
What will be the output of the following function for?
(i) someFn(7,5) (ii) someFn(6,8)
(iii) In one line state what the function someFn() doing?

(i) 35
(ii) 24
(iii) The above functions find the LCM of two given value.

Q. Find out the output of each of the following programs. Dry run or working is necessary, (if
possible).
public class output1
{
static int m=0,n=0;
public static void main()
{
int m=10, x=20;
{
int n=30;
System.out.println(“m+n=”+(m+n));
}
x+=m+n;
System.out.println(“x=”+x);
}
}

m+n=40
x=30

public static void main()


{
String x = new String(“AMIT”);
char c; String p=””; int i;
for(i=0;i<x.length();i++)
{
c=x.charAt(i);
p=c+p;
System.out.println(p);
}
}

A
MA
IMA
TIMA

public static void abc()


{
int x=1, i=2;
do
{
x*=i;
}while(++i<=5);
System.out.println(x);
}

120
public class t100
{
public static void main()
{
int i=1,n=6,f=1;
while(i<=n)
{
f=f*i; i++;
System.out.print(f+” “);
}
}
}

1 2 6 24 120 720

public class t200


{
public static void main()
{
int i,n=5,s=0;
double f=0;
for(i=n;i>0;i–)
{
s=i*i;
f=(Math.pow(s,2))-i;
System.out.println(f);
}
}
}

620.0
252.0
78.0
14.0
0.0

public class q2 [5]


{
int a=10;
public void myfunc(int a,int b)
{
a=a+b;
a = a;
System.out.println(this.a+”\t”+a+”\t”+b);
}
public void main()
{
int a=20,b=30;
q2 x=new q2();
x.myfunc(a,b);
System.out.println(this.a+”\t”+a+”\t”+x.a);
}
}

10 50 30
10 20 10

public class q6 [3]


{
public static void sampleMethod()
{
int x=10,y=10;
System.out.println(x==y);
}
}

true

public class q6 [3]


{
public static void sampleMethod()
{
int x=50,y=20;
x=(x<y)?x+y:x-y;
System.out.println(x);
}
}

30

public class q2 [5]


{
int a=10;
public void myfunc(int a,int b)
{
a=a+b;
this.a = a;
System.out.println(this.a+”\t”+a+”\t”+b);
}
public void main()
{
int a=20,b=30;
q2 x=new q2();
x.myfunc(a,b);
System.out.println(this.a+”\t”+a+”\t”+x.a);
}
}

50 50 30
10 20 50

public class q6 [3+2]


{
public void sampleMethod(int val)
{
int n=500;
int res=n+val>1750?400:200;
System.out.println(res);
}
}
What will be the result if val=2000 and val=1000.

400
200

public class q6 [2]


{
public static void sampleMethod()
{
int k=20,l=1;
int j=–k+2*k+(l=k);
System.out.println(j);
}
}

76

public class q6 [3]


{
public static void sampleMethod()
{
System.out.println(1101 & 1100);
System.out.println(1101 | 1100);
System.out.println(1101 ^ 1100);
}
}
1100
1101
1

public class q6 [2]


{
public static void sampleMethod()
{
int i=17;
i>>=2;
System.out.println(i);
}
}

public class q6 [1]


{
public static void sampleMethod()
{
System.out.println(13 & 25);
}
}

public class q6 [2]


{
public static void sampleMethod()
{
int x=10,y=20;
if((x=5)>10)
System.out.println(x);
else
System.out.println(y);
}
}

20

public class q2 [5]


{
int a=10;
public void myfunc(int a,int b)
{
a=a+b;
a = this.a;
System.out.println(this.a+”\t”+a+”\t”+b);
}
public void main()
{
int a=20,b=30;
q2 x=new q2();
x.myfunc(a,b);
System.out.println(this.a+”\t”+a+”\t”+x.a);
}
}

10 10 30
10 20 10

Give the output of the following program segment [3]


String x = new String(“LOYOLA”);
char c; String p=””; int i;
for(i=0;i<x.length();i++)
{
c=x.charAt(i);
p=c+p;
System.out.println(p);
}

L
OL
YOL
OYOL
LOYOL
ALOYOL

Give the output of the following program segment [2]


int x=1, i=2;
do
{
x*=i;
}while(++i<=5);
System.out.println(x);

120

What will be the output of the following method [5]


public class qwe
{
static int a=100,b=200;
public static void main()
{
int count,c;
for(count=1;count<=5;++count)
{
c=4*count*count;
System.out.println(function(c));
}
}
static int function(int x)
{
int c ;
c = (x < 50) ? ( a + x ) : ( b – x ) ;
return(c);
}
}

104
116
136
136
100

public class qwe [4]


{
static int a=100,b=200;
public static void main()
{
int count,c;
for(count=1;count<=5;++count)
{
c=4*count*count;
System.out.println(function(c));
}
}
public static int function(int x)
{
int c = (x < 50)?( a + x ):( b – x );
return(c);
}
}

104
116
136
136
100
public class q2 [5]
{
int a=10;
public void myfunc(int a,int b)
{
a=a+b;
a = a;
System.out.println(this.a+”\t”+a+”\t”+b);
}
public void main()
{
int a=20,b=30;
q2 x=new q2();
x.myfunc(a,b);
System.out.println(this.a+”\t”+a+”\t”+b);
}
}

10 50 30
10 20 30

public class q4 [4]


{
public static void main()
{
String s=”Object”;
int l=s.length();
for(int c=0;c<l;c++)
{
if(Character.isLowerCase(s.charAt(c)))
System.out.print(Character.toUpperCase(s.charAt(c)));
else if(c%22==0)
System.out.print(‘E’);
else
System.out.print(Character.toLowerCase(s.charAt(c)));
}
}
}

EBJECT

public class q1 [4]


{
public static void main()
{
int x[]={60,50,30,40},y=3,size=4;
for(int i=size-1;i>=0;i–)
switch(i)
{
case 0:
case 2: System.out.println(y*x[i]);break;
case 1:
case 3: System.out.println(y+x[i]);
}
}
}

43
90
53
180

public class xyz [4]


{
public static void main()
{
int a,b,w,x,y,z;
a=10;b=8;
w = ++a – b– ;
System.out.println(w);
a=10;b=8;
x = a % b++;
System.out.println(x);
a=10;b=8;
a*=b+5;
System.out.println(a);
z=69>>>2;
System.out.println(z);
}
}

3
2
130
17

public class op3 [4]


{
public static void work( )
{
char ch=’ ‘;
String test= new String(“abcd”);
String test2=test;
if(test.equals(test2)) {
if(test==test2) {
System.out.println(“not equal”);
ch=test.charAt(0); }
else {
System.out.println(“not equal”);
ch=test.charAt(1); } }
else {
if(test==test2)
ch=test.charAt(3); }
System.out.println(ch);
}
}

not equal
a

Q3. Write the output after each pass (only five pass), if we apply insertion sort algorithm in
ascending order on following numbers: 2,8,1,9,4,3 [5]

Pass I 281943
Pass II 128943
Pass III 128943
Pass IV 124893
Pass V 123489

Q4. Write the output after each pass (only five pass), if we apply bubble sort algorithm in
descending order on following numbers: 2,8,1,9,4,3 [5]

Pass I 829431
Pass II 894321
Pass III 984321
Pass IV 984321
Pass V 984321

Q3. Write the output after each pass (only five pass), if we apply insertion sort algorithm in
ascending order on following numbers: 2,8,1,9,4,3 [5]

Pass I 281943
Pass II 128943
Pass III 128943
Pass IV 124893
Pass V 123489

Q6. Write the output after each pass (only five pass), if we apply selection sort algorithm in
descending order on following numbers 2,8,1,9,4,3 [5]
Pass I 981243
Pass II 981243
Pass III 984213
Pass IV 984312
Pass V 984321

Q6. Write the output after each pass (only five pass), if we apply insertion sort algorithm in
descending order on following numbers: 2,8,1,9,4,3 [5]

Pass I 821943
Pass II 821943
Pass III 982143
Pass IV 984213
Pass V 984321

Q. If m=5 and n=2 output the values of m and n after execution in (i) and (ii). [ICSE
2005]

(i) m -= n;

(ii) n = m + m/n;

Ans: (i) the value of m is 3 and n is 2 (ii) The value of m is 5 and n is 7

Q. What will be the output of the following. if x=5 initially? [ICSE 2005]

(i) 5 * ++x

(ii) 5 * x++

Ans: (i) 30 (ii) 25

Q. What is the output of the following? [ICSE 2005]

char c = ‘A’;

short m = 26;
int n = c + m;

System.out.println(n);

Ans: output is 91, because adding ‘char’ with integer data type ‘short’, the least data type
‘char’ converted to integer ‘short’. i.e. ‘A’ becomes 65, so 65+26 is 91.

Q. What do the following functions return for: [ICSE 2005]

String x = “hello”;

String y = “world”;

(i) System.out.println((x + y);

(ii) System.out.println((x.length());

(iii) System.out.println((x.charAt(3));

(iv) System.out.println((x.equals(y));

Ans: (i) helloworld (ii) 5 (iii) l (iv) false


Fill in the Blank

1. A Class is a set of objects that have a common structure and common behavior.

2. Full form of JVM Java Virtual Machine.

3. Java combine with Java API makes Java platform.

4. The behavior of an object is described through associated function called Method.

5. An Object is an identifiable entity with some characteristics and behavior.

6. The full form of WORA Write Once Run Anywhere.

7. The machine language for the JVM is called Java Byte Code.

8. The full form of API Application Programming Interface.

9. Java uses the Unicode character set.

10. Java/BlueJ developed by which company Monash University.

11. In java, methods reside in classes.

12. The number and type of arguments of a functions are known as function signature.

The first line of functions definition that tells about the type of return value along with
13.
number and type of arguments is called function prototype.

A class is a Blueprint or prototype that defines the variables and the methods
14.
common to the object of a certain kind.

15. Character set is set of valid characters that a language can recognize.

16. The smallest individual unit in a program is known as a Token.

17. Keyword is a word carrying special meaning and purpose.


18. Identifiers are user defined names for different parts of program.

19. Literal are data items that never change their value during a program run.

20. The region of program within which a variable is accessible is called its Scope

21. User defined type conversion is known as Type casting

22. Static variables are created once for entire class and are shared by all the object.

23. Keyword Final while declaring a variable, makes it a constant.

A member function having the same name as that of its class is


24.
called Constructor function.

25. A private constructor allows object creation only inside Member functions.

26. A Non-parameterized constructor takes no arguments.

27. The keyword This refers to current object.

28. A constructor function has No return type.

29. A Parameterized constructor creates objects through values passed to it.

30. Many constructor definitions in the same class is known as constructor Overloading

31. A private or protected constructor is not available to the Non-member functions.

32. The default constructor Initialize the data members by any dummy value.

33. Declaring a constructor with arguments Hides the default constructor.

34. A Member functions with the same name as its class is called constructor

35. Constructor function is defined with Public access specifier.

36. A class can have Multiple constructors for various situations.

37. Constructor that can take arguments are called Parameterized constructor
38. A constructor that access no parameter is called the Default constructors

39. The constructor can be used to perform Initialization

40. An array is simply a sequence of either Objects or primitives

Array elements of primitive types are automatically initialized to Empty or null


41.
values.

42. A private constructor allow object creation only inside Member functions.

43. A constructor functions has No return type.

44. A class encapsulates data, methods and functionality.

45. Java resolves duplicate variables name to most local scope variables.

46. Through Public access specifier a class makes its element visible.

If a local variables is having the same name as that of global class elements then
47.
it Hides the global variables.

48. Region within which a variables/piece-of-code is access scope

49. Variables declared inside a method or block local

50. Class variable which is available to the entire class global variable

51. In java for an array having N elements legal 0 to N-1 subscripts are

52. Total size of array A having 25 elements of char type is 50 bytes

53. Total size of array B[10][5] of int type is 200 bytes

54. The data type of array elements is known as the base type of the array.

55. In Java, array indices start is known as the 0 and are uptil size 1

56. Two dimensional array are stored in memory in a row-column matrix.


57. Sorting of an array means arranging the array elements in a specified order.

58. Binary IO is performed using Input and output streams

59. Streams Tokenizer is used to parse Streams into tokens.

60. The latest pure object oriented language is java.

61. Java was developed by sun Microsystems of USA in 1991.

62. Java is a platform neutral language.

63. Java compiler generates Byte code instructions.

64. The Size of primitive data types in Java are Machine independent.

65. Java language does not use pointers.

66. Java does not support Global variables.

The variables and methods in Java are declared with in a class and forms a part of
67.
that class.

68. OOP stands for objects oriental programming.

69. An object is an identifiable entity with some characteristic and behavior.

70. Real world object encapsulate state and behaviour.

71. objects interact with one another through Messages.

72. The entire set of Date and code of an object can made a user defined data.

73. Insulation of the data from direct access by the program is called data hiding.

74. A derived class in Java is known as subclass.

75. A object is a software bundle of variables and related methods.


Modularity refers to the source code for an object which can be written and
76.
maintained independently.

77. Creating an object is also referred to as Instantiating an object.

78. The functions defined inside a class are known as Methods.

79. Software object have Identity and state, behaviour.

80. The information in Java is passed along with message as parameters.

Data is encapsulated is a class by placing data fields data fields the body of class
81.
definition.

The real world objects are implemented in software form by representing their state
82.
through variables or data items called Member variables.

A class is a Blueprint or prototype that defines the variables and the methods
83.
common to the object of a certain kind.

84. Character set is set of valid characters that a language can recognize.

85. The smallest individual unit in a program is known as a Token

86. Keyword is a word carrying special meaning and purpose.

87. Identifiers are user defined names for different parts of program.

88. Literals are data items that never change their value during a program run.

89. The region of program within which a variables is accessible is called its Scope.

90. User defined type conversion is known as Type casting.

91. Static variables are created once for entire class and are shared by all the objects.

92. Keyword Final while declaring a variables, makes it a constant.

A member function having the same name as that of its class is


93.
called Constructor function.
94. A private constructor allows creating only inside Member function.

95. A Non-parameterized constructor takes no arguments.

96. The keyword This refers to current object.

97. A constructor function has No return type.

98. A Parameterized constructor creates objects through values passed to it.

Many constructor definitions in the same class is known as


99.
constructor Overloading.

100. A private or protected constructor is not available to the Non-Member functions.

101. The default constructor Initialize the data members by any dummy value.

102. Declaring a constructor with arguments Hides the default constructor.

103. A Member function with the same name as its class is called constructors.

104. Constructor function is defined with Public access specifier.

105. A class can have multiple constructors for various situations.

106. Constructor that can take arguments are called Parameterized constructor.

107. A constructor that accepts no parameter is called the Default constructors.

108. The constructor can be used to perform Initialization.

109. An array is simply a sequence of either Objects or primitives.

110. Array elements of primitive types are automatically initialized to Empty/Null.

111. A private constructor allow objects creation only inside Member functions.

112. A constructor functions has No return type.

113. A class Encapsulates data methods and functionality.


114. Java resolves duplicates variables name to most Local scope variable.

115. Through Public access specifier a class makes its elements visible.

If a local variable is having the same name as that of global class elements then
116.
it Hides the global variable.

117. Region within which a variable/pieces-of-code is accessible scope.

118. Variable declared inside a method or block local.

119. Class variable which is available to the entire class global variable.

120. In Java for an array having N elements legal subscripts are 0 to N-1.

121. Total size of array A having 25 elements of char type is 50 bytes.

122. Total size of array B [10] [5] of int type is 200 bytes.

123. The data type of array elements is known as the base type of the array.

124. In java array indices start from 0 and are uptill sixe 1.

125. Two dimensional arrays are stored in memory in a row-column matrix

126. Sorting of an array means arranging the array elements in a specified order.

127. (i) Binary IO is performed using Input and output streams.

128. (ii) Streams Tokenizer is used to parse Streams into tokens.

129. (iii) Data that need to be stored Permanently must

Multiple Choice Questions


Pick the correct option’s (can be more then one)
[1] Which of the following is not a keyword?

(i) class (ii) void (iii) true (iv) public

[2] Which of the following is invalid integer

(i) 1936 (ii) 0123 (iii) 0XFACE (iv) 01934

[3] 1 & 0 is

(i) 1 (ii) 0 (iii) false (iv) true

[4] a = 8 + 4/2 the result is

(i) 6 (ii) 10 (iii) 16 (iv) error

[5] The keyword turns a variable declaration into constant declaration

(i) const (ii) constant (iii) final (iv) fixed

[6] Function not returning any value has return type as:

(a) int (b) char (c) float (d) void

[7] A functions can return _________ values.

(a) 1 (b)2 (c) 3 (d) all of the above

[8] The parameter appearing in functions call statement are called

(a) actual (b) formal


(c) call parameters (d) all of the above
parameters paratemter

[9] The parameters appearing in function definition are called

(b) formal
(a) actual parameter (c) call parameter (d) all of the above
parameters

[10] The function call in which the data in actual parameters gets changed is known as
(b) Call by (d) Return by
(a) Call by value (c) Return by value
Reference Reference

[11] The function call in which the data in actual parameters gets changed is known as.

(b) Call by (d) Return by


(a) Call by value (c) Return by value
Reference Reference

[12] The function that changes the state of its parameters is called.

(b) impure
(a) pure function (c) change function (d) none of the above
function

[13] One function, many definitions, is called

(a) function (b) function


(c) function loading (d) all of the above
enlargement overloading

[14] Which of the following is not an advantage of functions?

(a) it help cope up (b) it makes (c) it hides the (d) it offers
complexity in subprogram implementation mathematical solution
programs reusable details of problems

You might also like