Theory Questions(Java)
Theory Questions(Java)
VIva
What is the difference between if and switch case
Difference between for,while and do while loop
Why java is platform independent
What is the purpose of using array
Whyshould we have user defined methods
What is oops . give its features
Difference b/w class and object
What is a constructure. Features
What are access modifiers - name them
Name some java lib
Some string functions '
assertion
What is exception handling. How to do ithow to implement
What is wrapper class
What is a thread. how to implement it.
T H E OQ
RYU E
b e t w e e
d i f f e r e n c e
Enter radius:
units.
153.860001
Areais
continue?: u t h e
ant to
i s
Enter choice: 2
Is
f t a t e m e n t
l e
W h a t
breadth: J a v a
length &
Enter c o
kcfo o
12
i n
19 228 units.
s i a t e m e n t
d e p e n d
u ipn g
o
w nh
Area is
continue?: y
Want to e x p r e s s
e ivoanl u
Enter choice:3 e
i
x
f
e c u t e
f h e
triangle:
Enter sides of
3
4 false
units.
Area is 6 T h
i fe- e
class Item
int code;
float price;
static int count;
public:
evaluates only
switch statement
if statement evaluates integer, character or integer
character, pointer or
Value.
floating-point type orboolean
type. execute one
switch statements
Either if statement will be case after another till a break
executed orelse statement is statement is appeared or the
executed. statement is
end of switch
reached.
switch
If the condition inside
If the condition inside if statements does not match with
statements is false, then by that
statement is any of the cases, for statements
default the else instance the default
executed if created.
are executed if created.
2.
Difference between for loop, while loop
loop arand do while
Ans. loop.
os For LOOP
while LOOP do-while LOOP
A loop in which the A
while loop is an Ado-while loop is
control statement isentry controlled an exit control loop
executed for a loop- it tests for a - it tests for a
pre-known no. of condition prior to conditionafter
times to obtain the running a runninga
result is known as block of code. block of code.
the for loop.
It can be said that A while loop runs Ado-while loop
for loop is a zero or more timesruns once or more
repetitive times but at least
Body of the loop
command. may never be once.
executed.
BT
In the for loop, the The variables ir It is not necessary
Command is the test condition to initialise the
must variables in the test
controlled by a
variable. Each time be initialised prior condition prior to
the loop iterates, toentering the loop entering the loop
the predefined structure. structure.
variable gets a new
value.
n Ans.
FEATURES: object
objects
language. Ans. statement statementscommas)
return return_type
’ ’
7. 6. "
generic
What his applications. classesand utilise methods Java What The
is
isbject memorising
Polymorphism: Inheritance: Encapsulation: that structure
an In
n already instance is is
the
is name interact an an
oops? method_name(list
together
OOPObject
Difference of
of
to established ofwith Give a
f various It language, Java
multiple enables in a Oriented
a It a It other
class. its
allows single helps method
b/w methods features.
names. characteristics the in
objects a
Programming of
A
class the unit program parameters is
programmer wrapping to as
Class and programmer
or
s solve below:
operators is
object? up a
of a(0OP)
collection separated
o of problem.
a to data
to class
effectively
to
give and
minimise Each of by
in
a new
N
or, issues.
Access makes class
arbitrarily, Ans. Features: done Ans.
initialise
’ ’ ’ requirement.
keyword
mainly
Student):
Student
s1=new Object
e.g. per
Object Object as
Object data that
9. 8. a
debugging DataWhat
by We
class type, The
Whenever at What A pen, in is
odifiers time special
the is is is capable
ismemory
default.
we do constructor a
laptop, a
members are is and is
created createdphysical real
le, lose not
invoked ofdata
may object method a
access a constructor?
world locations. of
etc.
in control By call new members through many holding
Java code the entity.
entity
allowing ofautomatically. orhas
od, object may creation). member times
helps harder over modifiers? class aconstructor the new actual
not of such
objects of sanme the as
the can have
a calledWrite
or to and class class
restrict
data values be explicitly. name
a Student(
keyworde.g.
class Class Class Objectobjects.Class which,single data
our accessed to Name (or the it's
change parameteris is and
as features.
any
constructor is is is object unit.
ber. code being created, declared declared a group a methods
the the logical It
other is is
scope
vulnerable held their them. class,
list. created. a
from the of
blueprint
initialization using once. entity. similar together
data
in has
method
of them. outside constructor
class
a members no from in
class, to is a
return used
is
security This the to
of
the be to
IST BIO
tructor, issues.
Access
variable, arbitrarily,
makes class Ans. Features: initialise
done Ans. requirement.
Object per Object
Object Object
as data that
9. ’ ’ ’ 8.
Student
keyword
mainly
e.g.
byData We
class type, The
Whenever at A
What pen, a in is
debugging
modifiers What time special is is is capable
is memory
default.
we the
do constructor
is and s1
created created laptop, real a
members are not ofdata is =new physical a
lose invoked a
call amay object method world locations. of
in control By access constructor?
members Student():through many etc. holding
Java code the new or entity.
allowing of automatically. has creation). entity
method, aconstructor object may member times
helps harder over class
modifiers? the new actual
not of such
objects of same the as
the can have
a Write
or to and class classcalled
restrict
data values be name Student{}
keyword
class e.Class
g. Class Objectobjects.Class which,single data
a
to Nameexplicitly.
our accessed parameter
is (or the it's and
change as anyfeatures. is is
is is
object unit.
member. code being created, constructor declared declared
the the a group a methods
other logical It
scope is is
vulnerable held their them. class,
list. a
from the of
created.
blueprint
initialization method using once. entity.
similar together
data
in constructor has
of them. outside
a class
members nO from in
class, to is a
return is
used
security This the to
of
the be to
types of access modifiers:-
Therearetwo
1. PRIVATE
2. PUBLIC
string functions.
11. Write some
Ans.
APPLICATION
DESCRIPTIONMy String="HELLO OUTPUT
METHOD WORLD"
myString.
sSuea
nok paS
charcharAt
(intindex)
Return the
character at the charAt(6) W
given index
NOIS
/Codefinally { I/
catch
Handle catch Handle I/ II try bel{structure
ow. The programmer,
anticipate a and Such is handling? Ans. 12.
Part statement Handle " " Denote "The results
error.
cOuldead t
ma
hd
memory becauseeere
to
(exceptiontype2 of errors
occur.
Can basic causes an to
unexpectedly
be exception(exceptiontype1
exception the Catch unpredictable
exceptions.
idea to er or and iv ide an So meWhat?is
exception i
executed the it dso of
program of the exceptionan in terminate As to
situation an
a thshould
at you on . runtime
arraerrors.
y withyour
reference
integer index with
newCharstring
of of try-catchexception
exception exception
programs
when the the where that
by
argument2)argument1)
exceptiontype2
exceptiontype1
the handlingunexpectedly
information.- -block zero, when
an Receive
Take unexpected
try exception
might The
was
or
executed
Corrective ldentify -
block the exceptions
is and errors
out How
{ { blockfor to:-
handle isin was of to
error areas range,Could may
exits called the
insufficient do
action in
exception the program have it
OCCur in an have
or
your
to the EXCEPTION. an
terminated
program ocCurred
recOver code attempt
executioncomputer
handling
where
from was
is the
as
-|nsYi ISGT ATIa
NNN
to