Professional Documents
Culture Documents
3 PDF
3 PDF
8.
i<5'i++)'
,..
x == x++ * 2 + 3 *
x == 25
b) (i) Output :
m == 3
.....
. r n n n +n),
(il) char x='A'; int m;
m=(x='a')
? 'A' : 'a';
System.out.println("m="+m);
(a) x == 5
==
f.
(2008)
[2010J
-- x;
char
n == 14
(ii) m
int n=15;
for(int i-I'
(c)
==
boolean literal
'a' ;
character literal
int rollNumber;
String name;
(d) Inheritance:
@J
Use of Inheritance:
e.g.,
System.out.print(x);
If the type casting
(a) a-
class A
{
(b) a
Ans.
10.
Ans.
Write a statement
(I) Store a number
11.
b) % c
a + = a++ - ++b + a;
Resulting value of a = 6
14417~
* (++
class B extends A
{
}
Here, A is base class
and B is derived class.
If a = 5, b = 9, calculate the value of
a + = a++ - ++b + a
a = 5, b = 9;
(iz) Convert
the string
to a numeric
value
total=num+ 1000;
17.
Ans.
18.
(2
Z=X3+y3_
xy
[2
Ans.
(a)
(b)
double c = Math.pow(a,2)
double z = Math.pow(x,3)
+ Math.powib.c
+ Math.pow(y, 3
- (x * )
(I) 5* ++ x
(iz) 5*x ++
(b) What is the output
(i) Encapsulation:
Binding and wrapping up of
methods and data members together in the
form of a class is called encapsulation.
(ii) Abstraction:
Hiding unnecessary details and
representing
essential
features is called
abstraction.
(iii) Inheritance:
Inheriting the data members and
methods of objects of one class by another
class is called inheritance.
(iv) Polymorphism:
Same function may behave
differently
on different
classes. This is
represented by function overloading.
(b) Ifm = 5 and n = 2 then
(i) m-=n=:>m=m-n
i.e.,m=5-2=3
= 3, n = 2 after evaluation.
= m + mln
= 5 + 5/2 = 5 + 2 = 7
So, m
(ii) n
_1.
of the following,
if
of the followin
comment in a program.
(b) Differentiate
between operator and expression.
[20051
Ans. (a) A comment can be expressed in a program by
following two styles:
(i) II: For single line comments.
e.g., II This is a remark.
(ii) 1* *1: For multiple line comments. As it has
a beginning mark and an ending mark.
e.g., 1* This comment can proceed in
different lines *1
(b) An operator is a symbol that performs a specific
operation on the operands. An operator can be
unary operator and binary operator depending
on number of operands it operates upon.
e.g., +, -, *, I, % are binary operators.
++, --, are unary operators.
An expression is formed by the combination of
operators with operands.
e.g., a + b/2 * c is an arithmetic expression.
CE [lUESTI[)NS
1. What is a program ?
A program is a set of instructions written in a sequential
way to perform a specific application or to solve a
numeric or non numeric problem.
What are the known types of programming
languages?
Explain them.
Machine language, Assembly language and High level
language are some known types of programming
languages.
In machine language, the programs are written in
binary codes which are called machine codes or binary
codes.
In assembly language, the programs are written using
small symbolic words called mnemonics.
In high level languages, the programs are written in a
language which is closer to user i. e. english, just
following some rules specific for the language. Basic,
_
Pascal, Fortran, C, C++, java are some examples of
HLL. Object oriented programming languages (C++
and Java) are the high level languages.
3. What are procedural
languages ?
Ans. Developing a program with a process centric approach
is called procedural programming. It concentrates on
the processes for which the software is being built. In
this, the functions are highly interdependent on each
other. Procedural approach refers to breaking up of
complex problem into smaller problems and then
solving each by using modules which act on data.
4. What are the drawbacks
of using procedural
languages?
Ans. Drawbacks of using procedural languages:
(i) The modules (parts of programs) in a procedural
language strongly depend on each other. So, a
module cannot be reused by other programs.
1451
(b) Behaviour
(ii)
performs.
s, ~-,:~.~~<::::l'
~~~~~~~~\.\.,~~,,\.te.\\.~~ce.s
reusabilitv,
-p~~,.-.
...~.....
-. ---:~.\::~::~.:-:~--;-'":!"'""::"'-~~~~~~~<.;~:>
~
r.... cl.~:s:s ..
raps
up
the
au.ribules
#.r/L'"e rhe
u.///;r-C/TCCS
o~r~pec.n
.p~:':':1;:r-;J
7~
~"X,.,","a'\.., ~"bc
T< ...'o
0'1:
........
o\;. '-ne~e$
00
{c) !.~~\t~_~~~.t~
~~
Kd'I{//'C.J:
'-3.
~~
How \5 encap u a on mp
Encapsulation refers to binding and wrappiru
the methods and the data. In java, it is implei
by the use of a class. Its significance lie!
abstraction feature of hiding the non es
implementation details. Inspite of hiding infon
the user can easily access the code and data cc
A class binds together the methods (called r
functions) and data (or attributes called memb
common to the objects that belong to it.
12. List all characteristics of an object.
~~.~,,,\.~~~\\.\,\, C\..assi..f\.cati.on, Inheritance
an.
'--'-~/~~';=:~_~L~.,.G",~~."....~~'-c~~~~
1f'J/
U1c t/WU/ff
'n\Q'
~
(7/
--
Eo
- ---
$~JffV'C$/~
~~~~~,,-~~~,,-~~
1!!!II __
==iiiiiiiiiii
Ans.
evel?
ypes 0
(i) Stand alone applications
- programs that are
written and compiled on the same machine.
(ii) Applets - programs executed on web browser.
(iii) Servlets - server side programs.
24. Why is java called Internet language?
Ans. Java programs are translated to java bytecode. Since
bytecode is not effected by the machine environment,
it is easier to run these programs on a wide range of
machines. Only a java interpreter JVM is required to
be implemented on the machines. JVM along with the
java Application Interface libraries acts as a platform
for the java programs to run on the machine. All JVM's
interpret the same bytecode. This makes the program
easier to be transported to variety of machines thus
making it portable. The world wide web on the internet
demands portable programs as of java, to be distributed
on the internet.
The second reason for its popularity as an internet
language is that it concentrates
on the real world
objects.
25. Expand
the abbreviation
Ans.
reason if unvalid
(0) _123
commonly known.
Ans. IDE stands for Integrated Development Environment.
Eclipse and BlueJ are two commonly used IDE's.
26. Name the IDE used to run java programs.
Ans. For java BlueJ environment is used as an IDE.
(c) var.l
(e)
(g)
(I)
Ans. (a)
L~~
7~
aJlowed.
of java ?
* not
Ans.
refer to in context
(d) TS
C23
(f) C*23
C 23
(h) acc_no
accountno
(J) depositamount
_123 is valid as it begins with _ (undersco
(d) Valid
(e) Valid
(j) Invalid, special character
Ans. Unicode.
29. What is the character set of the language Java?
Ans. A set of characters which is valid for a specific
language. Java uses UNICODE character set.
java.
32. What does the token 'Keyword'
(b) break
otherwise it is valid.
39. Which of the following are valid integer lite
(0) - 5.0
(c) 4 x 10-3
Ans.
(b) 21
(b) 21
(d) -16E+03.
~O. Which
of the following
are
invalid
identifier
names?
are valid
hexadecimal
What is a literal?
A constant value is called a literal.
2. What are the different
;t
e
L
ly
re
Id
he
to
he
est
nd
de
tion,
lis?
types of literals?
literals
be
55.
Ans.
56.
Ans.
57.
Ans.
58.
Ans.
59.
Ans.
60.
Ans.
61.
Ans.
62.
Ans.
at ar varia
e ?
Memory location that stores a literal is called a
variable. It is identified by a variable name. Its value
can change in the program.
What do you mean by 'data type' of a variable?
Data type refers to the type of value to be stored in a
variable or the type of val ue to be used for calculations
and other manipulations in the expressions.
What are the different set of data types available
in java ?
Primitive data types and reference data types are two
types of data types available in java.
What are the different primitive data types?
int, byte, short, long, float, double, char, boolean are
primitive types.
List various reference data types of java.
Arrays and class are the reference data types and object
is a variable of data type class.
Write the size of the following integer data types
both in terms of bytes and bits:
(a) int
(b) short
(c) long
(d) byte
(a) int
4 Bytes
4 x 8 bits = 32 bits
(b) short
2 Bytes
16 bits
(c) long
8 Bytes
64 bits
(d) byte
i Byte
8 bits
Write the range of acceptable values of these data
types:
(a) int
(b) short
(c) long
(d) byte
(a) Range of values for int = _231 to 231 - I
(b) Range of values for short = _215 to 215 - I
= -32768 to 32767
(c) Range of values for long type = _263 to 263 - I
(d) Range of values for byte type = _27 to 27 - I
= -128 to 127
Write the size of (0) float (b) double in bytes and
bits.
(a) float = 4 Bytes = 32 bits
(b) double = 8 Bytes = 64 bits
Write the range of acceptable values of:
(a) float
(b) double
(a) -3.4 x 1038 to 3.4 x 1038
(b) -\. 7 x 10-308to I. 7 x I0308
63. How many bits are reserved for char data type '!
Ans. For character type values, it reserves 16 bits.
L491
,/
o to
set?
128 to 255
How many bits are reserved for boolean type?
8 bits are reserved but used only I bit.
How many bits does it use to store the boolean
value?
It uses only one bit.
What does a bit stand for?
Bit is an abbreviation for Binary Digit.
What are the two binary digits?
and I.
Ans.
What
boolean value does bits 1 and 0 represent
72.
respectively ?
Ans. I represents true and 0 represents false.
73. How many values can a variable store at a time?
Ans. A variable can store only one value at a time.
List the known
74. What are escape sequences?
sequences with their functions?
if preceeded by a backslash(\),
Ans. Some characters,
change their meaning and perform a specific function.
Ans.
70.
Ans.
71.
Escape sequences
\a audible bell
\b backspace
\n new line
\fform feed
are:
\v vertical tab
\t horizontal tab
\' quote
\" double quotes
\r carriage return
75. Write a java statement
to compute
discount
by
by MP.
Ans. double x=(double) totaIIlOO*MP;
76. Write a java statement to assign character X to a
variable val.
Ans. char val='X';
77. Write java statement to print the value of variable
val.
Ans. System.out.println(val);
78. What are comments/remarks
?
Ans. Comments or remarks refer to the statements which
are ignored by the java compiler and hence do not
effect the processing
and the output. These are
generally used to state the purpose of the instructions
used in the program.
79. How can you give comments in a java program.
Ans. In java the comments can be inserted by putting II
The entire line after /1 is treated as comment.
?~
Ans, +, -, *, I, %
82. Is a++; equivalent to ++aj ?
Ans, The two statements if written independently'
the value of a by I.
e.g., int a=IO;
a++;
System.out.println(a);
The above statements will result II as the a
a.
e.g., int a=IO;
++a;
System.out.println(a);
The above statements will also return II as
a.
following method :
Divide the variable total by 100. Multiply the result
Output: 2 /
Pre-decrement (--) and Post-decrement works same as
Pre-increment and Post-increment respectively with a
Y=++Xj
s. y= II,x= II
in x and Y after
y=x--j
x=9,y=
10
What values will be stored in x and y respectively
after executing the following:
int x = -10,Yj
Y=--Xj
-II, -II
of
-5
If a stores 45, b stores 2, e = a % b. What value" is
tored in e ?
I
i
of
lent
the
:he
by the following
SECTION-B
java
(a) S = 5x
+ 2y
(e) S = ut
+ - at2
(b) S =
(d)f=-+-
3x2 + 2y
x-y
1
US YEARS' (lUESTIDNS
id
iate
taiu
_
(a) class Employee
(e) class BankCustomer