1. Describe Java Exceptions with an example?
Java Exceptions: in Java, Exception is an unwanted or unexpected event, whic
the execution of a program, i.e. at run time, that disrupts the normal flow o
instructions. Exceptions can be caught and handled by the program. When an ¢
within a method, it creates an object. This object is called the exception ob
information about the exception, such as the name and description of the ex
state of the program when the exception occurred.
Major reasons why an exception Occurs:
e Invalid user input
» Device failure
- Loss of network connection
«Physical limitations (out-of-disk memory)
> Code errors
« Opening an unavailable file
Errors represent irrecoverable conditions such as Java virtual machine (JVM
memory, memory leaks, stack overflow errors, library incompatibility, infinite
Errors are usually beyond the control of the programmer, and we should not try teMethods to print the
ORS Tete) fel Ke mE erode \ ce) at
PPPS Cri OR noe eMC RUC RCI om ua uta Urs
Cxcatee er eum ut ces emer atc
np!
Pu Mee MMM pec ete Mucus)
I BSTech:1 Sem: (2023-24) OOPs Using Java Notes Unit — Ill i
class GFG
public static void main (String[] args)
iE
int b=0;
‘System.out. printin(a/b);
i
catch(ArithmeticException e)
e.printStackTrace();
}
}
Fev e ue stress ecco
at GFG.main(File java:10)DeSean eet e eee eka ee
fA) Streams in Java: Steams in Java represent an ordered sequence of data. Java performs input]
jand output operations in the terms of streams. It uses the concept of streams to make 1/0]
operations fast. For example, when we read a sequence of bytes from a binary file, actually, we're]
reading from an input stream. Similarly, when we write a sequence of bytes to a binary file, we're|
writing to an output stream. In Java, 3 streams are created for us automatically. All these streams}
are attached with the console.
1) system out: standard output stream
2) System.in: standard input stream
3) System.err: standard error stream
‘Types of Streams: Modern versions of Java platform define two types of I/O streams:
+ Byte streams
+ Character strear
Byte Streams in Java: Byte streams in Java are designed to provide a convenient way for handling}
ihe input and output of bytes (i, units of 8-bits data). We use them for reading or writing to|
binary data /O. Byte streams are especially used when we ate working with binary files such as
executable files, image files, and files in low-level file formats such as .zip,.class, .obj, and .exe,
Binary files are those files that are machine readable. For example, a Java class file is an]
lextension of *.class” and humans cannot read it. It can be processed by low-level tools such as a|
JIVM (executable java.exe in Windows) and java dis-assembler (executable javap.exe in Windows)
[Another real time example is storing a photo in a .bmp or peg file. These files are certainly not}
human readable. Photo editing or image manipulation software can only process them,
Byte streams that are used for reading are called input streams and for writing are
called output streams. They are represented by the abstract classes of InputStream and|
loutputStream in Java.
[Character Streams in Java: Character streams in Java are designed for handling the input and|
ut of characters. They use 16-bit Unicode characte ter streams are more efficient
than byte streams. They are mainly used for reading or writing to character or text-based I/O such]
jas text files, text documents, XML, and HTML files. Text files are those files that are human|
readable. For example, a xt file that contains human-readable text. This file is created with a text
editor such as Notepad in Windows.
Character streams that are used for reading are called readers and for writing are|
called writers. They are represented by the abstract classes of Reader and Writer in Java.
112. Explain about Steam Classes and their methods in Java?
A) Stream Classes in Java: All streams in Java are represented by classes in java.io package. This|
package contains a lot of stream classes that provide abilities for processing all types of data. We|
can clessiy these stream classes into two basie groups based on the date type. They ae es
Follows:
+ Byte Stream Classes (support for handling /O operations based on bytes)
+ Character Stream Classes (support for managing 1/0 operations on characters)
Byte Stream Classes in Java: There are two kinds of byte stream classes in Java. They are as|
follows:
+ InputStream classes
+ OutputStream classes
OutputStream: Java application uses an output stream to write data to a destination; it may be a|
file, an array, peripheral device or socket.
InputStream: Java application uses an input stream to read data from a source; it may be a file, an
array, peripheral device or socket. Let's understand the working of Java OutputStream and]
InputStream by the figure given below
File Consola Socket Fila Console Socket
\ | 7 \ 722. tNustrate Random files In Java?
ere
ees
one Te
Cea!
ican read from a fie as well as wtte to the fle, Reading
squential process. Using 2 ra
we can read of write at any position within the file, An object of thel
domAccessFile class can do the random file access. We can read/write bytes and all
primitive types values toa file.
th strings using its readUTFO and writeUTEQ methods,
The RandomAccessfile class is not in the class hierarchy of the InputStream and
loutputStream classes.
Mode
random access file can be created in four diferent access modes. The a
fa sting. They are listed ae follow
ly mod
eee eee
ina read-write mode. Any modifications to the file
Sree eer eg
y modifications to the file's content
Read and Write: We create an instance of the RandomAccessFile class by specifying the fle
name and the access mode.
RandomaccessFile raf = new RandomAccessFile(randomtest.tx, rw)
A random access file has a fle pointer that moves forward when we read data from itor vite
ata tot
The file pointer is a cursor where our next read or write will start. ts value indicates thel
cistance of the cursor from the beginning of the file in bytes, We can get the value of fle
pointer by using its getFilePointer() method When we create an object of the
RandomAccessFile clas, the fle pointer Is set to zero. We can set the fle pointer ata specic
location in the file using the seek() method. The length0) method of a Rand
returns the current length of the file We can extend or truncate a file by using it
method.
Example
The following code shows how to read and write Files Using @ RandomAccessFile Object
import java.io File
Javaio ]OException,
io RandomAccessFile;
public static void main(Strinaf] args) throws IOException
String fileName = "randomaccessfile.xt;
File leObject = new FilefileName);
If (flebject.exists0)
{
intiatWrite( fileName)
)
readiile(fleName}
readile(fileName),
public static void readFile( String fileName) throws IOException
-eesFile raf = new RandomAccessFileileName,*rw");
at ceadint:MoM Mena 1
fo
DST ues ee uu MRE eed
Multitasking in Java: The process of executing one or more tasks concurrently or at the same
time is called multitasking: It\is the ability of an operating system to exectite multiple tasks at
Cre MUU esd ue MOEN UN ilu aCe aUh INueR tye) eins
implemented in two ways:
1. Process-based multitasking (Multiprocessing)
2. Thread-based multitasking (Multithreading)
Process-based Multitasking (Multiprocessing): The process of executing multiple programs or
processes at the same time (concurrently) is called process-based multitasking or program-based
multitasking. In process-based multitasking, several programs are executed at the same time by
MMe ee SIE SOM ier LCM Sec ena
process-based multitasking feattre alloWs to execute two or more programs concurrently on the
Cairn
A good example Is, running spreadsheet program while also working with word-processor.
Each program (process) has its own/address space\in the memory. In other words, each program
is allocated in a separate memory area. The operating system requires some CPU time to switch
CMU eich Ue Ie ie PLU nea TAA AUE Ia ps IMEI echo
‘switching, The switching from/one program to|another| program isso fast that itlappears to the
eu Re TM line fellate Tm kT elo
‘Thread-based Multitasking (Multithreading): A thread is a/separate path of execution of code for:
each task within’a program. In thread-based multitasking, a program uses multiple threads to
perform |one or more tasks at the same time by/a processor. That is, thread-based multitasking
feature allows you to execute several parts of the same’ program at once! Each|thread/has a
Ceca escorts
Advantage of Thread-based Multitasking over Process-Thread Multitasking: The main
advantages of thread-based multitasking as compared to process-based tasking are’
1. Threads share the same memory address space.
2. Context switching from one thread to another thread Is less expensive than between processes.
eeu er eee nn CNA aves
4, Threads are lightweight as compared to processes (heavyweight). They utilize the minimum
resources of the system. They take less memory and less processor time.
Java supports thread-based multitasking and provides a high quality of facilities for
multithreading) programming, A\ great way to | remember the (difference between process-based
multitasking and thread-based multitasking is process-based multitasking works with multiple
(ere kee SN Me Ue Et ULC aCe oH AML UNCLE N sas LE LLD
process-based multitasking, a program is the smallest Unit of executable code whereas, in thread-
DEES uM eth aite mM Uler-CeMR Teta ec aU tate L acy cratic, Kere](reer une VYnN
DYeco ona Osama cu eterna)
Aare rerio pe Run IU
enero nieey eect Reon ieecinl ste en eke Mare or)
Cetera oar nie banter oer Menno UXecOaG
thread in Java. They are as folows:
Moen aterm tens
Pe Geta sean ey evoke aa
Soe tie eie rere eee Once eounr ice!
tema e cease eect Ucn
4, Create a cless that extends the Thread class. n order to extend a thread) we will use a keyword
Crecoaeee sete anon Ia un a cececc nko 8
Gerace oii ere)
Z| Now inthis newly created class, deine a method run0) Here, run0| method acts as entry point of
Coie ace siee keen li gore ti
Craps inc tock
Tonsil cunt
Gis itat
4
erence
)
1 Greate an object of newly crested claes co that run) method is avalible for execution. The
reece tat ues meter Ley
14, Now create an object of Thread class end pass the object reference variable crested fo the
Conetuctor of Thread cise.
Geren)
be ei unclCs eee
5, Run the threed) For this, we need to call to star) method of Thread class because we cannot
iota e restr ea catre Ue ra Marcio Accor ee
Reece hice os eee earn cane)
Goo Mi esoesnce ae eer ny cist epee terse
ie
eens
Ceoier oer uit
(pubic voldrun)
q
taxa HH)
‘System out pimin( Thread currentThread0,getName0 +":*+1),
public close ThreadClassDemo
(
Puble static void main(String e103)
ies:
Sie tres
Sie eeae rc)
Genny
arn
eng)
Toes esos cn
(Cee it ear teas Satie em ee ar Is sacle)
eS STOR ee a a EET LE ye=
USE ese RSSTPI Eevee) Uta
IL
u
Creating Threads in Java Using Runnable Interface: Threads can also be created by implementing
Renee ea ee Meet nu smu eneu ti sstane leurs
Tape Mace ean pesca eS ae Us Se Cetera) e)
Meee Min aun a van SNL uL eRe NSS aU Meee SC SEH
Meee hu Crk inee Nous A ued ufsleu senMintcrice Kod
Ao ees umes erica use our iis Pueneltnnes cies Sc3
PER eC ius ne a un)
PH ECON Same eClulsncusiceanett
i
public vold run()
{
‘System/out printin(New thread running);
tied) 5; i+),
if
‘System.out printin(|);
)
System.out printin(Thread.currentThread());
»
public static vold main(Stringl] args)
{
‘System.out printin(‘Main thread running’);
7/.Creste an object of MyThread class,
MyThread th = new MyThread();
// Create an object of Thread class and pass reference variable th to Thread class constructor.
Thread t = new Thread(th);
Deen OP Ute ecu eae Cured Se Lt tinct lerd annie Kos).
}
}EOI ci ey
10) Explain about Inter Thread Communication and its methods in Java using an example of
Producer ‘and Consumer Problem?.
YC Meena ie trun ie comets MMi lca Ps Rue
Com eR CeCe ns SWC C nee AUN ral aru WNT a eC
‘communicates with each other by reducing CPU idle time! CPU idle time is a process in which CPU
cles are not wasted! When more than one thread Is executing simultaneously, sometimes they
Pee O comme OM TAN eure acu Us (ur) ncaa RCC eA D ee
Gee icra ems Oc acne ei SSIS ae cee ae S(O rt
‘Communication between threads is important,
Ge USO SME UEC ACU ERML eerKel elected
De eV cnn ee MCE eS ALICE Mos ces ee NSC ILS Nc SUNIL
Caer eomneih ule Oe CUE ules ois iu kec ncn uuu Pie cel cc Lue
tasks) they do not have to wait and check each other's status every time. Thus, CPU cycles willnot
Waste. This type of Information exchanging between threads Is called Inter-thread communication
Wee
rete aneet Neamt aM Me Bl nto edu CVU
ECO Ce MS CACM Maulana sedy gels LaKe ead Mele el SUS lcs
1. walt(, 2. notify), 3. notifyAll()
Muenster eles Ns ls.ecd
Coors ee en CMMMr Ine Me ones ose atelier uy start
PCC oe Musee te Concern scan sts Ae cece)
ous Nereus
‘wait() Method: wait() method in Java notifies the current thread to give up the monitor (lock) and
OR OIE CISCO ME MERC ME COI Ns cellar yey iacurssMuaisna ac
Prout =te ot UIC CANE Nua ult ier al SiN Cs AUN wun ILsCuP
Tenures Ker NALS Le ia
‘Syntax: public final vold Walt((ong millisecond) throws Interruptedexception
notify() Method: The notify) method wakes up a single thread that called|wait()/ method on the:
Same object: If more than one thread is waiting, this method will awake one of them):The general
Sareea Se ACCS
Syntax: public final void notify0)
ReMi ect AMES Nauti hn OU OMe kee Quarta)
on the same object. The thread having the highest priority willirun first. The general syntax to call
TotifyAll() method Is as follows: Syntax: public final void notifyAll()
Producer-Consumer Problem In Java using walt and notify methods: In the producer and
Cora fae CRAM OL MSM see ete TA erent Oa Leh
S Cheech Sonic ok
TSS ee Lee 13)
Caceres areas Mei Reus Me XLT CuK
Ce aM et uct MMM acle nna lene orc pa ted scot Wrote le ha (usu
a thread completes the production of data, the Consumer thread will take that data
ETTSue
rogram code:
Txermets ene ied eastern tit
pineers}
«
ie
boolean valueSet = fale,
synchronized vor produce(it |)
i(valieset)
b)
x
car
catch InteruptedException fe)
x
Sueno}
cng
pete
Barntentomn easton
cain
D
Penne Ntsc uu
c
H((alueset)
}
Ge ucmamscr colt
Secrecy
)
Someta
Portes
Cae
=
ray
)
}
paseo
Core)
OG
Green)
x
Cisse:
}
Pach)
Dees ete ea uy
ee
Ghee
)
,
public class Consumer extends Thread
Take
Co
Furch)
Cree
}
Preietoria)
x
cate oats)
ienaih
i}
}
Dine unc emma
Piiceriensthr neuer)
{
Qg=new 20;
roer pre roca)
Seaton Oy
parr "i
a
»
aePeron sone nete te Soe MAI
A) Life Cycle of Thread in Java is basically state transitions of a thread that starts from its bith
‘and ends on its death. When an instance of a thread is created and is executed by calling star()
‘method of Thread class, the thread goes into runnable state. When slaep() or wait() method is
called by Thread class, the thread enters into non-runnable state. From non-runnable state, thread
‘comes back to runnable state and continues execution of statements
SRC Sem CN aR
Coe ORR Re ee ue iy
thread state.
SS Con a ee een ec nea eS
following five states during its life cycle, The five states are as follows:
1.New 2.Runnable 3. Running 4. Blocked (Non-runnable state) 5. Dead
1. New (Newborn State): When we create a thread object using Thread class, thread is bom and is
known to be in Newborn state. Thatis, when a thread is bor, it enters into new state but the star()
ei ee Se
|$——© resem
In other words, Thread object exists but it cannot execute any statement because it is not an
execution of thread. Only start() method can be called on a new thread; otherwise,
Penne estes un co
2. Runnable state: Runnable state means a thread Is ready for execution. When the start() method
is called on anew thread, thread enters into a runnable state. In runnable state, thread is ready for
Penne Reo ea eeok aU)
3, Running state: Running means Processor (CPU) has allocated time slot to thread for its
execution, When thread scheduler selects a thread from the runnable state for execution, it goes
en ee ce ce eet een NR mero eas
‘executes its run method. This i ret nee ae Cea)
‘come into running state only from runnable state. A running thread may give up its control in any
fone of the following situations and can enter into the blocked state.UE NL Matatce SNe ce RR Ue he NS eM act i
Me ip for specified time period, the thread is out
Cie TRUS nd sa MU kune Cet MmCe Can NOR TnE
age CULE Sees ie tin}
b) When a thread Is suspended using suspend() method for some time In ord tf
lel RP Ie Ur oh ts or Nae nO Apes Te an easel baa CTA
OUT IM INO U LT SCE Ke Mth Mesa Nema eine ues el
Tun again using notify() or notifyAll) method, aie
cu Ee Co) state: A thread is considered to be inthe blocked state when it Is suspended, sleeping,
or waiting for some time in order to satisfy some condition:
5. Dead state:A thread dies or moves into dead) state automatically when Its run() method
completes the execution of statements. That Is,/a thread is terminated or dead| when a thread
comes out of run() method! A'thread can also be’dead when the stop() method is called!
Ce Ree Cnc eerie re
PNT Pues te Hee Ma eae PLU LCh CURL) LOL SaLeVS ord noun c(elCer Ce)
Main thread. When’ a program starts, main thread starts running immediately: Apart from this main:
Teeth Wes NE eC ieCo sim unc ed WE) nels Iu SCM leet uct A aa gle nie)
threads create from Its main thread known'as parent ithread. There’ are two ways to create/a/new!
thread|inWava: They are as follows:
1. One Is /by extending java.lang.Thread (class
2, Another is by Implementing java.lang.Runnable interface
BCs PU Re Se al Ses ar PLCs CSU Ke et sac kere CUS E ater)
TREN Manichieles uate pres Saeed ene het Tn aCe ULM
PCAC KeRCSR Ur RCs cut SHUT MMe eee ike sm Xs Cul NUCL PME Nyaa
extends. The Thread class Is found in java.lang package. The syntax for creating anew class that
extends Thread class is as follows: Class Myclass extends Thread
2. Now in this newly created class, define a method run(). Here, CL one tel Ie Posies
the!new/ thread! The|run()|method ‘contains the actual task that thread will/perform. Thus, we
‘override run() method of Thread class.
r
CTU eauccren See ual Orel oneeESNLU LLYPast ing Repainting?
Requesting Repainting: Whenever your applet needs to update the information displayed in its
window, it simply calls repaint). The repaint( ) method is defined by the AWT. It causes the AWT|
runtime system to execute a call to your applets update( ) method, wiicl
implementation, calls paint(),
as a general rule, an applet vattes to its window only when its update() or paint() method is called}
by the AWT. This raises an interesting question: How can the applet itself cause its window to be|
lupdated when its information changes? For example, if an applet is displaying a moving banner,
what mechanism does the applet use to update the window each time this banner scrolls?
Remember, one of the fundamental architectural constraints imposed on an applet is that it must
Jquickly return control to the AWT run-time system. It cannot create 2 loop inside paint( ) tha]
repeatedly scrolls the banner, for example. This would prevent control from passing back to the|
wr.
Given this constraint, it may seem that output to your applet’s window will be difficult at best
Fortunately this is not the case, Whenever your applet needs to update the information display
in its window, it simply calls repaint( ). The repaint() method is defined by the AWT. It causes the|
JAWT run-time system to execute a call to your applet’s update( ) method, which, in its default
implementation, calls paint). Thus, for another part of your applet to output to its window, simply
store the output and then call repaint( ). The AWT will then execute a call to paint(), which can|
display the stored information. For example, if part of your applet needs to output a string, it can}
store this string in @ String variable and then call repaint( ). Inside paint(), you will output the string
using drawString )
The repaint( ) method has four forms. Let's look at each one, in turn, The simplest version of
repaint() is shown here
void repaint()
This version causes the entire window to be repainted. The following version specifies a region
that will be repaintec
Here, the coordinates of the upperleft corner ofthe region are specified by lft and top, and the
vith and height ofthe region are passed in udth and height. These dimensions are specified i
pixels You save time by specifying region to repaint. Window updetes are costly in terms oftime|
IF you need to update only a small portion of the widow, it is more efficient to repaint only tha
region. Calling repaint( ) is essentially a request that your applet be repainted sometime soon.
fowever, it your system ts slow or busy. update ) might not be called immediately. Multpe
requests for repainting that occur within @ short time can be collapsed by the AWYT in a manner
such that update) is only called sporadically. This ca be a problem in many situations, inctuding|
animation, in ihich consistent update time is necessary. One soltion to this problem is to use
the following forms of repent)
void repaintiong maxDelay)
void repaint(long maxDelay, int x, int y, int width, int height)
Here, maxDelay specifies the maximum number of miliseconds that ean elapse before update
scaled. Beware, though. I the time elapses before update() can be called, it isnt called. There's
jo etum value or exception thrown, so you must be careful
tis possible for a method other than pait() or update() to output to an apple's windows. To do
so, t must obtain a graphics context by calling getGraphics() (defined by Component) and then
tise this context fo output to the windovr. However for most applications, tis better and easier to
route window output through paint( ) and to call repaint( ) when the contents of the windo
change
import java.a
import java.applet.Applet;
event
‘RepaintJavatieample.class"width="250"height="150"> */
public class RepaintJavaExample extends Applet implements MouseListener
{
private int mousex, mouseY;
private boolean mouseclicked = false;
public void init()
{
setBackground(Color.CYAN);
addMouseListener(this);
}
public void mouseClicked(MouseEvent e)
{
mouseX = e.getX();
mouseY=e.getY();
mouseclicked = true;
repaint();
}
public void mouseEntered(MouseEvent e){};
public void mousePressed(MouseEvent e){};
public void mouseReleased(MouseEvent e){};
public void mouseExited(MouseEvent e){};
public void paint( Graphics g)
{
String str;
g.setColor(Color.RED);
if (mouseclicked)
{
str = "X="+ mouseX +"," + "Y="+ mousey ;
g.drawString(str,mouseX,mouseY);
mouseclicked = false;=
perpen eo ea
OTSA poe
P Jay
ey Q i rae
| een PS a template ton geet
Classes. jt typically
)
ckly create new clag;
Tell me more
Meat
itor Conn}
EVE e te
CE ene
PALI c aie
Semone
Class. This class
ds to go through a se
: ] de ane
Ere eee Re ie ie
ee RLS Nae es Peo
BITC rcr ery enna
CON een
ena ett
CUCM lately
UME LCMUP Itc Te}
CTU tate
AERO a cnt ee
Caen
SP lt ]2) Coan eyfe) TORUS Re ESR MMe] COL RUC COTS eget
applet. In this method, the varial
CRUE Ta ents Rta ay RUE ema cree Mors
thing you must note here is that this method can be invoked ea Reirecd caer a res
CA RCS RRC TTS See M uu RUC entra) PS CmU a Ruiter
See AS Urals emir Meg eee ana Coane Sea)
DTU texe ReMi el ete Rete Rts eye m ees tla tte)
Pa NRO R RN ee) RUS e ica cn Coen)
applet. In other words, the stop() method is used to suspend the threads which are net
PP aS eee gee Se ke ee ee
CCE Ue Mer mace nee
Public void destroy(): Finally, we have the destroy() method which is invoked in order to
Completely remove an applet from the memory. This method is invoked only once per
applet life cycle and all the engaged resources must be freed up before this method is
ealed
CoC Rees gte Pune caaee eT)
i I i Taco es
° lic void paint(Graphics g): This method is invoked whenever an appl
eee rye ae ‘i the browser, irrespective of ee Ea
i ia)
Teo re CeCe eeu ceases
eet PASTOR UUM eee ako RR aeAPM Takeo WT eM ASS e104)
‘A) JDBC Steps: Java|Database Connectivity with 5 Steps. There are 5 steps to\connect any Java
E sIe tenance Ten RP Eemn es ee es Cores
Ouse ui ate ss
Oecaeamesicw
O cacae cuca
0 Execute queries
©) Close connection
1) Register the driver class: The forName() method of Class class is used to register the driver:
class) This method is used to dynamically load the driver class.
‘Syntax: public ’static void forName(String className)throws ClassNotFoundException’
Example: Class forName(-oracle jdbc driver OracleDriver’);
2) Create the connection object: The getConnection0 method of DriverManager, class is Used to
Cseeeenuea tuk nunuek eee
Syntax:
1) BTECH 1 SEM OOPS — JAVA NOTES UNIT V. 17
Aaa eset ln kee rst OUU UM Sel see cto
2) publie'static Connection getConnection(Stringlurl String name,String password),
Example:
Cee UEP MEME as ene Isler a ul N le inset yA. fas
Ssrccny
Eee RU RE Chur ele ges ML Meter cellu tO uuteltatene Lien ses oD chet ce NIST LO)
Crea aM tees ees sts Wes exon ese ety
‘Syntax: public Statement createStatement()throws SQLException’
(aT CoS ECCI RCCL CLL IN
‘4) Execute the query: The executeQuery() method of Statement Interface Is Used |to execute
Cnet ae les MMn Saree ua ii)s (eee Tess Muri iile sessile tse
TUCO
Syntax: public ResultSet executeduery(String sqi)throws SQLException
Bou
ResultSet rs=stmt executeQuery(‘select * from emp’);
while(rsinextQ)(
Sc esse mereeer Siu)
i
DCm Cee asp nr rams M eter Chis uI SMD Ls
Closed automatically. The close() method of Connection interface Is Used to close the connection,
Sarcsa Molererks tess unss usta
em caren‘7. What is a Swing, Design an applet with swing components?
Create a Swing Applet: The second type of program that commonly uses S\ Peas
Swing based applets ‘are similar to AWT-based applets, but with anlimportant difference: A Swing
applet extends JApplet rather than Applet. JApplet is derived from Applet. Thus, JApplet includes
ecient sce etree eee kee
Seen eee Aet ear hence Ronee Una kes
Roca tke nE none ieee rete
Se Senna gc eee cS
‘Swing applets use the same four life-cycle methods ie ini), start( ), stop( ), and
destroy('), OF course, you need override only those methods that /are needed by your, applet.
Painting is accomplished differently in Swing than it isin the AWT, and|a Swing applet will not
normally overide the paint() method. Al interaction with components in a Swing applet must
anne cerere secant ene el Stee rasta
Verges
Coeur at
Tce
Paar
Gass eee re ee