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

Java Pyq Edited

The document is an examination paper for the Fourth Semester BCA course on Java Programming, covering various topics such as object-oriented programming concepts, Java interfaces, mutability of strings, threading, and JDBC architecture. It includes questions on Java programming principles, constructors, and client-server communication using sockets. The exam consists of compulsory and optional questions, with a total of 75 marks allocated.

Uploaded by

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

Java Pyq Edited

The document is an examination paper for the Fourth Semester BCA course on Java Programming, covering various topics such as object-oriented programming concepts, Java interfaces, mutability of strings, threading, and JDBC architecture. It includes questions on Java programming principles, constructors, and client-server communication using sockets. The exam consists of compulsory and optional questions, with a total of 75 marks allocated.

Uploaded by

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

.

END TERM EXAMINATION


FOUR}'H SEMESTER (BCA)-MAY-JUNE 2014
AVA PROGRAMMING-[BCA-206]
- Time:8 hrs. M.M.:75
Note: Q.No. 1 is compulsory and is 0f 26 marks. Attempt one question from each unit.
.5 marks.

chine level Codes?


ns that is not specific to
ced by the java compiler
ocessor. The bytecode is
terprets the Java byte
difference between
ccannot be directly run
e designated machine.
sense that they can
Windows, Solaris
can be run on
is smaller as
- LR University(BOA)-Akash Books
3 nce variable?
i8 used to access the object. A reference variable is declared
hat type can never be changed. Reference variables can be
variables, method parameters, or local variables.
can’t ever be reassigned to refer to a different
can be modified, but the reference variable cannot be

variable, but it is not referring


hieve polymorphism, a reference
ny subtype of its declared type.
Tk

nce in JAVA every class has a


structor like other classes. The
constructors, the constructor
nstructor in class is used to

he object of applet class, so


init() method of applet
() and paint() method are

eter?
Java program stored in
ytecode is independent
s the bytecode to native
2014-5

oes they differ from concrete


ted? Can there be an abstract
ample. ®)
abstract—it may or may not
antiated, but they can be
ithout an implementation
abstract void move(double
class itself must be declared

5 uéually provides
However, if it does
your answer with suitah),
o ®s5)
are used to initialize object;
they are called or invokeg
plicitly. Constructors have p,
er, the default construct,
one constructor, which i
then default constructo

‘values of one object t;


to copy the values of one
S “@
It has static constants and
ieve fully abstraction.
‘method body. It is used to
ava. Java Interface also
ike abstract class.

that can appear in an


i -
S

10-2014 Fourth Semester, Java Programming

(1) Mutability: String is immutable (Once created, ca;


StringBuffer is mutable (can be modified). itk Modifieg,
Example
"y
String is immutable:
String str = “Hello World”;
str = “Hi World!”;
In first statement an object iss created using strin,
shhmsgt
g literal
when we ulilmd tl;_g_:u;vd, string literal “Hj wo; d ;{tills"tr’:;ld » 0s g0,
difl;‘t mngnnmmflinjflabjmm in memory using string li,'te € object itgg

:;i :l‘:fl':h
s ex!it,s',‘?
A ? N itmeis assigned to str.
having So basically
different both Kloeations)
references the objects “Hell-;fl0 Worlgr,,

ingBufl

< Immg string litera] “Helly


ged to “Hello Worlg fron
Ofmafing the new obju

tenate strings usin


String is immutable.

xample,
a thread is born,
ete. life cycle of a thread.

s back to the runnable


ntinue executing.
BCA)-Akash Books 2014-11
d waiting for a monitor lock is in this state.

tiple threads try to write


use one of the threads can
le at the same time another

s and make sure that


is implemented
with a monitor,
hold a lock on a
ting threads and
| resources within

iates with the


‘way is to use
ique monitor.
2014-13
2014-15
Write a program to illustrate the
5 ®
consistent mechanisms to
2014-21
h Books 2014-23
Web server, It is not necessary to

written in Java.
f restrictions to protect the

lable to a servet. It can

) *Ei'xxg includes an HTML


or a custom HTTP client

equire talking to a
e, or computing the

foer
et.InetAddress
END TERM EXAMINA TON [JUNE-2015]
FOURTH SEMESTER [BCA|
OGR
i MM :75
is compulsory.
n example to each
(5%5=25)
when you want to process only
stener interface. You can define
S and_unple;nent only those events

, MousePressed etc.
y Anested class has access
it is nested. however
ted class.

nembers of

osing class directly.


g
nester, Java Programmin
al by
‘All the variables are static fin
to be
default, and a value needs
tion
assigned at the time of defini
by
All the methods are abstract
default and they will not have a
definition.

Provide
e complete life cycle of thread.
hread. (6.5
gram
e path followed when executing a pro
teq
, known as the main thread, which is crea
main() method is invoked with the main

a Thread:
cycle. For exgmple, a thread is born,

remains in this state until


thread.
id becomes runnable. A

ting nsstate while the


>wainsi
tra tio bac k to the
6)
e simple, clean and easy
either left outin Java or
ter, Java Programming
Mddmnbfibinglhuttheemptlon&
ufihth-fimmyflon
h Books 2015-9
rit the properties of a class. The idea behind
classes that are built upon existing classes.
ar uunmothodn and fieoflds
parent class,
5) Hybrid
e, multiple u‘ahentanee i

The C class inheritsAz


it from child class object, &

e use of
am to illustratthe
I @
streamis an abstractiont
to a physical deviceby
LP. University-(BCA|-Akash Books 2018611

used to perform input and output of B-bit bytes. Though


ted to byte streams but the most frequently used classes are,
putStream ‘
ns are used to perform input and output for 16-bit

,FileReader and FileWriter.


ted for us automatically. All these streams are
TR

_ Input stream classes


(reads)

Output stream classes


(writes)
2015-13
InputStream and a Reader is that an InputS
tream is at
a stream of chara.

tion; reads and returns the next byte from the stre
am
[OException; returns the number of bytes that
can be

ould be called when you are done with the

Re ;lder using an InputStreamReader

ader is that an InputStream is at


chars.

a String to the stream


t any writes have actually

q convert into binary


: L (4.5)
SSemester, Java P Program ming
14-2015 Fourth
.
numbe ple”);
System out.printIn(*Conve T t decimal number toB binary
inar i N tmber . ”):
eT example
i “yittis
System.out.printin(“Binary value of “ +
)

i ) .
tes on any two o! f the following:
ing: i(6.25 x 2 - 1 |
)
Q‘i8. :v?;)east:(g):::)s
a and TCP/IP : based
. client
A andkst:rver socke
2ns Client and Sever communication using Socke
i dpoint of a two-way communi ication link betw£ een two progr
the TOP Lres a
rumfi\nsg CoI:f:.\:: :2:\5315 A socket is bound to a port nutn:ber 50 thal yer
identify the application that data is destined to be sent to.

Connection
g request
S P -
t °l ciient
It
R
p Connection
Server| © |
: g
r| Client
(t |
Working of Client
and Server using
Server runs on a specific Sockets
number. The server computer and has a
Just waits, listening socket that is bound to a specific
request. to the socket for a client p
to make a connectj
On the client-side:
serveris The client knows the
ing and the Port number hostname of the machine
request, the client on which the server on which t
tries to co is listening. To make a connectj
i
i

can continue to li e address and port


sten to the origin; of th,
needs of the connected client
,

Client and Server


Itis of two types
1. TCP based
P University—[BCA]-Akash Boo
ks 2015-15
s a simple transport-layer pro
tocol The application write
socket, which is then encapsulated in a UDP
din an IP datagram, which is sent to the d:&mm, :}:chsi:
destination,
rantee that a UDP will reach the des
tination, that the order of the
0 cross the net work or that datagrams arrive only
DP once.
is its lack of reliability: if a datagram rea
ches its final destination
an error, or if the datagram is droppe
d in the network, it is not
comparison with AWT controls,
ts are light-weight as compared to AWT comp
onen
't make use of the native UI components of the ts for the
underlying
been written completely in Java language. Not
the same
libs gries, x
atively less number of classes as compared to AWT
the it doesn’t depend on native code, but also because it has
olution from AWT. Most of the design flaws got fixed which
= es.
wing components is defined only by the Swing extension
the look and feel of the underlying platform as well
components is mostly goverened by the underlying
1ents open up in their own look and feel.
‘and JDBC Drivers
vity, a Java API that enables Java programs to execute
a programs to interact with any SQL-compliant
1 database management systems (DBMSs) support
most platforms, JDBC makes it possible to write
can run on different platforms and interact with
but is designed specifically for Java programs,

3 = source

commonly associated with


E
Fourth Semester, Java Programming
16-2015

* Executining g that SQL or MySQL quer


ies in the database
ing rec
records : .
ing & Modifying the resulting
i IVIIou ?ort.s both two-tier and three-tier processing models fo d"'-flh,,
X .}JDBC Architecture consists of two layers:
e ¢ =
A {Dr}f Ce?xzralThis
access(l;:)BlCiPI' i
provides the application-to-JDBC Manager
1. : connection,
2. JDBC Driver Manager : This supports the :IDBC Manager-to-Driver C()""‘?flti.,, Not! L

In ths; two-tier model, a Java application ta}lks dxf'ec’,tly to t}“le data


source and t
three-tier model,
commands are sent to a “middle tier” of services, which then
senqg th
commands to the data source.
The JDBC driver manager can support
multiple drivers connecting to diffe,ep
databases. When an application tries to connect pet
to a particular database, the driy,
manager loads the appropriate JDBC
driver and routes subsequent al
driver. callg through th J?av
A JDBC driver is a database-s
pecific software that receives
driver manager, translat
es them into a form th calls from the Jpp
data to the application, at the da ta base can process, and
retury,
Types of JDBC Driver X

Specific databage Protocol, BC calls direct


i e i om the type 4 g
ii Yy i that the protoco] ¢, . .
sient, butin thehe midle.gioptier. Like
middle e,type 4 drivers,
he p the typeonversi on logie pes
3 driver i wfi:s;fizsnr:iot ?t
rely

i
re type 4 dfive’:lsplemented
for 3
’ [MAY-JUNE 2016]
‘n:n'fi R [B CA]
AING [BCA-206)

! W let, you read the values


!f._l'() method of the
——
B Publisher
rent class constructor
t class instance variable,

class features, there is a possibility


features and JVM gets an ambiguity.
d derived class features must he

sses. Anested class hasaccess


in which it isnested. however

‘g‘ at heap memory,


g the unused objects.

the unreferenced

we don’t need
Y%
2016-7

(2.5)
t places (pushes) the details of each method it
with details such as the name of the class/

mcuti«m, it is removed from (popped off)


U fully completed execution, it is popped

which contains the

(4.5)
v ke)vvord is used

xception and
MWBOM-AB Publisher 2016-9
Programming
Fourth Semesterter,, Java
102016 :
th e t op, botto m, left and right inge
bject that contains bty
method to get the Inset 0 ov er rride
ri c the getInset() method, v, "
aine r is di sp la ye d. We ha ve thy ,
used when the cont desire.
that cont ains the inset spacing you
Insets object ttom, g
left, int bottom, int right) top, l.efl., bo oy, ny
Constructor: Inset(int top, int and its en cl os in g Wi nd
etween the container
right specify the amount of space b
CardLayout layg,
ardLayout we can prepare different
It stores the different layouts. Using Ci
d when needed.
and have them hidden, ready to be activate
Constructors
CardLayout()
CardLayout(inthorz, intvert)
horizontal and vertj,
First one is default. Second one allows you to specify the
space left between components.
l. This pay
The object of CardLayout class is created and stored in the type Pane
must have CardLayout selected as its Layout manager.
CardLayoutcard_layout = new CardLayout();
Panel panel_main =new Panel();
ut);
panel_main.setLayout(card_layo
‘We can create different panels, each having a different set of components, th
these panels are added to the panel for which CardLayout is the layout manager. Final
the panel is added to the main applet panel.
Q.5. (c) List the methods under Window Listencr Interface. (
Ans.

S.N. Method & Description

1. Void windowActivated(WindowEvent e) Invoked when the Window


is set to be the active Window.
2. Void windowClosed(WindowEvent e) Invoked when a window has
. been closed as the result of calling dispose on the window.
3. Void windowClosing(WindowEvent e)Invoked when the user attempts
to close the window from the window’s system menu.
4. Yold windowDeactivated(WindowEvent e)Invoked when a Window
is no longer the active Window.
5. Void windowDeiconified(WindowEvent e)Invoked
< when a window
i
mdnn@dfiumaminimize_dtn a normal state.
6. ¢ Void windowIconified(WindowE:
- Vs ventmr;
e)In ivoked when a window
i isi
s 'Void
o windowOpened(WindowEven
% i : t e)Invoked
the first time a window
SAI Publinher 201611
b nnd Applots, Bwing components nre
Andependont, Thoterm Hghtwelght is
clinawen are contnined in javaxswing,
Applotn that uwe Bwing must he
such i the content pane, the

v ndd method of the content


18

;lx'lttqn entirely in
are more efficicnt

v (? irom String
W)
Fourth Semester, Java Programming

Ali streams behave in the same manner, even if the actua) phy,
ey are linked differ. Thus, the same 1/0 classes and methodg ci‘t
“device. This means that an input stream can abstracy,
a disk file, a keyboard or a network socket, Likewi‘:

used to perform input and output o 8


d to byte streams but the most f'equeu
e Output Stream.
s are used to perform input and outpy,
s are used to perform input and outpyy
se related to character streams but
er and File Writer. Though inte
uses File Output Stream byt
ytes at a time and FileWriter wriy

languages provide support for standy


a keyboard and then Pproduce,
C or C++ programming languag,
s STDIN, STDOUT and STDER

user’s program and usually


ted as System.in.
n
|2
3
©
&
. LP. UniversityBCAJ-Akagh
Boo
- l
2019-15
olgnoreCase(): Compare two gy
ings, g
public class MyClass (
i
tic void main(String( ] a
myStrl = “HELLO”; 2!
myStr2 = “hello”;
.out.printin(my8trl.com, pareTolgnoreCase(; (myStr2));
ecked exceptions: Write a
sl exceptions. ¢
the program will kive
these exceptions are
means
if your
that
T = S o S
' Max. Marks: 75
ok
~ Cello JO
el
rmnmi ng
m e s t e r, J ava I’rng
Fourth Se e in AWT.
@
er szlz)\;;l labl
10-2023
s v a r i o u s L ayout Mafnug. (Pg. No. 14-2017)
"
s R’
Q.6. (a) Discu E n d T e r m E
tlo: e
-
to Q6. (b ) s
Ans. Refer e n S w i n g an A
betwe
Q.6. (b) Diif
ferentiai te tion hod overriding,
E n d T e r m Examdiinnag different from met
fe to rQ6. _((2a) -
Ans. Re a
thod overlo
E
H o w is m e :
Q.7. (a) example. 2 0 1 9 (P g. no 4-2019)
uitable Examinatio n s
Give s rm
Re fe r to Q 2 . (a) End Te ng:
Ans.
no te s on the followi
shor t
Q.7. ®) Write
7)
Q7. (i) Adapter
class.
a t i o n 20 17 (Pg. No. 21-201
rm Exam i n
Q.8. () End Te am.
Ans. Refer to ation pro; gr
et and applic 2017 (Pg- No. 22
-2017)
Q.7. (b)Gi) Appl Ex am in al ti on
(¢) from End Term
Ans. Refer Q.8. ce list.
k box and choi No. 22-2017)
Q.7 (b) (ii) Chec rm Ex am in at ion 2017 (Pg. @)
8 (d) End Te in detail.
Ans. Refer to Q. , JDBC drivers
? Ex pl ai n all
Q.8. (a) Wh at is JDBC -2019)
(Pg. No. 20
. (a) En d Te rm Examination 2019
Ans. Refer to Q8 (5)
no te s on Ja va Servlet.
t
Q.8. (b) Write shor n on a Web or Application server and
act
pr og ra ms tha t ru
Ans. Java Servlets are t co ming from a Web
browser or other HTTP client
tw ee n 2 re qu es
as a middle layer be the HTTP server.
ns on
and databases or applicatio forms,
you can col lec t inp ut from users through web page
Using Servle ts, , y o u dynamically. i
s fro m a dat aba se or ano the r source, and create web pages
rec ord ssi
a Ser vle ts oft en ser ve the sam e purpose as rograms i
Jav Jaans B e
Common Gateway Interface (CGD.
ison with the CGI as given below:
But Servlets offer several advantagesin compar :
e
« Performance is significantly better.
* Servl ddr
. execute te wi within the address
Servlets ;pace of a W. eb server.
spac TV It is not not n necessaryto

¢ Servlets are teplpl: atform-i5 nde pe- ndem;A


it n in Java.
because they are wr g
¢ Java security
man: HTTP
tiogns ;n fi?;;;er:;r
enforces a set of ’estfic he -
Protocol
fge
resources son a servi» er machine.
i y
So, servlets | Web Browser Servlets
Program
The following diagram &
position of Servlets in a Web App;.'h;:iin.the
Java Servlets are Java classes run by
hasthatx 5
a web server 1as S an interp; reter that
supports th Java b
8 o le_t speedimfiol:
-
e to hardware failure, resource
occurs in Java, an exception is
omething
about the exception
léx::eptum.
iGN

You might also like