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

Theory Questions(Java)

The document contains a series of theoretical questions and answers related to Java programming, covering topics such as control structures (if vs switch case), loops (for, while, do-while), platform independence, arrays, user-defined methods, object-oriented programming concepts, access modifiers, Java libraries, string functions, exception handling, wrapper classes, and threads. Each question is followed by a detailed explanation or definition, providing foundational knowledge for Java programming. The content appears to be structured for educational purposes, likely for a programming course or exam preparation.

Uploaded by

Palak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Theory Questions(Java)

The document contains a series of theoretical questions and answers related to Java programming, covering topics such as control structures (if vs switch case), loops (for, while, do-while), platform independence, arrays, user-defined methods, object-oriented programming concepts, access modifiers, Java libraries, string functions, exception handling, wrapper classes, and threads. Each question is followed by a detailed explanation or definition, providing foundational knowledge for Java programming. The content appears to be structured for educational purposes, likely for a programming course or exam preparation.

Uploaded by

Palak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Ch-3 theory qs

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

Lkant to continue?: Sele

6. STATIC DATA MEMBERS


#include<iostream . h>
#include<conio . h>

class Item

int code;
float price;
static int count;
public:

void input( int i, float j)


Code=i;
price=j;
cOunt++;
void display()
"<<code<<endl; cout<<"Code Number :
CHAPTER-3
THEORY QUESTIONS
1.What is the difference between if and switch caser
Ans.
If statement Switch case
usedto
The if statement in Java lets us The switch statement is
execute a block of code execute a block of code
many
depending upon whether an matchingone value out of
expression evaluates to true or possible values.
false.
The switch statement is a
The if-else statements belong to multiple-choice selection
selection statements in OOP.
statement.

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.

Syntax: Syntax: Syntax:


for (initialization while (condition) do {
statements
condition; testing
condition; statements while (condition);
increment/decremen
t)
statement(s)
3.Why is java platform independent?
Ans. AJava compiler instead of translating Java code to
Bytecode.
machine language code, translates it into Java
When the bytecode is to be run on a computer, aJava
interpreter, called the Java Virtual Machine (JVM), translates
then executes it. The
the bytecode into machine code and programmer has
advantage of such an approach is that once a
be runon any
compileda Java program into bytecode, it can as it has a JVM
as long
platform (say WVindows, Linux, or Mac)
it. This makes the Java programs platform
running on
independent andhighly portable.
arrays?
4. What is the purpose of using
variables that can hold more than one value,
Ans. Arrays are
values of the same type. Arrays are used
theycan hold a list of instead of
single variable,
to store multiple values in a
each value.
declaring separate variables for

should we have user defined methods?


5. Why statements grouped
Java is a block of
Ans. A method in the result to the
and return
together to perform a specific task specific task without
perform some
caller. AJavamethod can allow us to reuse the
Methods in Java
returning anything.
retyping the code.. A method has a name, a
code without
optional list of parameters, and a body.
return type, an
sYn ISTO N

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

off the java libraries.


Namesome
10. Java libraries:
Ans.
A.Datainput
B. Array manipulation
C. String manipulation

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

Concatenate myString.concat Hello


String concat ("Today") World
the specified
(String str)
NON string at the end Today
of this string
Teraod
boolean
Returns true if myString.
contains TRUE
contains this string
(String s) contains the ("Hell")
specified
substring
boolean Test whether myString.ends FALSE
endsWith this string end With
(String suffix) with the given (old")
suffix

String Returnsa new myString. He**o


replace(char string after replace Wor'd
oldChar, replacing all
char newChar) (T")
0CCurrences of
BMSue

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

a The and In firstthe In Consider


the valu50.e Integer intexample,Forthcle ass.
a ’ To
memoryvariable These you may Java ofAns. Wha14. t is
initialised
second = can point An Ans. 13
b50; classes need to By
-eaAssertionDemo java the An
the use
default, are -ea statementassertion
declaration,inan
t F implement to
codmemanntdilyelinniaenblgeddureintgeacassertion?
s teritng How
location a
newfollowing passed
valueby assertions the
wi
is th wrapper pass a by
declaration, Wrapthe wrapper
the
option, execution
athe Integer(50); Integer the using:- is
memory
that states and a
two classes primitiveprimitive at useful
value primitive runtime,correcting
holds wrapper class? the
of a
declarations: condition
mechanism
and
location 50. anvariable provided data data program.
obiect you \ogical
an not
class data types types that
object by can
errors for
and of is holds type reference. enable should
the declared by by(such effectively
ofthe into Java.
reference. in
class an as them be a
the int an int,
prograrm.
true
from
variableb Integer
class and variable. object Sometimes, float,
That
at
the a
withe particular
Integer. is initialised is of is and
a that when you so
referenceinstantiated on)

to

You might also like