You are on page 1of 17

CS2305- PROGRAMMING PARADIGMS 2-MARK Questions and Answers UNI I

2) What is a lass? lass is a template for a set of objects that share a common str!ct!re and a common behavio!r.

do w

nl o

*) What is meant by abstraction? &bstraction defines the essential characteristics of an object that disting!ish it from all other +inds of objects. &bstraction provides crisply, defined concept!al bo!ndaries relative to the perspective of the viewer. #ts the process of foc!ssing on the essential characteristics of an object. &bstraction is one of the f!ndamental elements of the object model.

-) What is meant by Encaps!lation? Encaps!lation is the process of compartmentalising the elements of an abtraction that defines the str!ct!re and behavio!r. Encaps!lation helps to separate the contract!al interface of an abstraction and implementation. .) What are Encaps!lation$ #nheritance and Polymorphism? Encaps!lation is the mechanism that binds together code and data it manip!lates and +eeps both safe from o!tside interference and mis!se. #nheritance is the process by which one object ac/!ires the

ad ed

() What are the core OOP)s concepts? &bstraction$ Encaps!lation$#nheritance and Polymorphism are the core OOP)s concepts.

fro m

%) What is an #nstance? &n instance has state$ behavio!r and identity. 'he str!ct!re and behavio!r of similar classes are defined in their common class. &n instance is also called as an object.

re j

") What is an Object? Object is an instance of a class. #t has state$behavio!r and identity. #t is also called as an instance of a class.


pa ul .c

1) What is meant by Object Oriented Programming? OOP is a method of programming in which programs are organised as cooperative collections of objects. Each object is an instance of a class and each class belong to a hierarchy.



14) What gives java it)s 8write once and r!n anywhere9 nat!re? &ll 6ava programs are compiled into class files that contain bytecodes. & method)s signat!re is a combination of the first three parts mentioned of another object. Pac+ages access level also allows yo! to protect data from being !sed by the non. When an object is created !sing new operator$ memory is allocated to it.c om . 1ethod overriding 4 When a method in a class having the same method name with same arg!ments is said to be method overriding. 12) What are different types of access modifiers 3&ccess specifiers)? &ccess specifiers are +eywords that determine the type of access to the member of a class. 'his is a way to organi7e files when a project consists of m!ltiple mod!les. 'hey are name of the method$ type of object or primitive type the method ret!rns$ a list of parameters and the body of the method. #t also helps resolve naming conflicts when different pac+ages have classes with the same names. protected' &ny thing declared as protected can be accessed by classes in the same pac+age and s!bclasses in the other pac+ages. Polymorphism is the feat!re that allows one interface to be !sed for general class actions. 12) E5plain the !sage of 6ava pac+ages. 'hese +eywords are for allowing privileges to parts of a program s!ch as f!nctions and variables. do w nl o 1") What is method overloading and method overriding? 1ethod overloading4 When a method in a class having the same method name with different arg!ments is said to be method overloading. private' &ny thing declared as private can)t be seen o!tside of its class. 0) What are methods and how are they defined? 1ethods are f!nctions that operate on instances of classes in which they are defined. 'hese are4 public' &ny thing declared as p!blic can be accessed from anywhere.a!thori7ed classes. 1ethod definition has fo!r parts. ad ed fro m re j in pa ul . Objects can comm!nicate with each other !sing methods and can call methods in other classes. 'hese byte codes can be r!n in any platform and hence java is said to be platform independent. default modifier ' an be accessed only to classes in the same pac+age. 11) What is an Object and how do yo! allocate memory to it? Object is an instance of a class and it is a software !nit that combines a str!ct!red set of data with a set of operations for inspecting and manip!lating that data.

) What is >arbage 21) What is finali7e3) method? finali7e 3) method is !sed j!st before an object is destroyed and can be called j!st prior to garbage collection. 1. #n 6ava$ there is no concept of destr!ctors.level$ class.c om 1*) What is the difference between constr!ctor and method? onstr!ctor will be a!tomatically invo+ed when an object is created whereas method has to be called e5plicitly . 1-) What is Stati( )e)*er (+asses. gc3) method may be !sed to call it e5plicitly in pa ul . =i+e any other static method$ a static member class has access to all static methods of the parent$ or top. & static member class is a static member of a class. re j ollection and how to call it e5plicitly? When an object is no longer referred to by any variable$ java a!tomatically reclaims memory !sed by that object.estr!ctor is an operation that frees the state of an object and:or destroys the object itself.1() What is a constr!ctor? What is a destr!ctor? onstr!ctor is an operation that creates an object and:or initialises its state. do w nl o 22) What is the difference between ?tring and ?tring A!ffer? a) ?tring objects are constants and imm!table whereas ?tringA!ffer objects are not. 'his is +nown as garbage collection. ?ystem. . #ts ta+en care by the 6<1. b) ?tring class s!pports constant strings whereas ?tringA!ffer class s!pports growable and modifiable strings. 2") What is the difference between &rray and vector? &rray is a set of related data type and static whereas vector is a growable array of objects and dynamic ad ed 22) What is static variable and static method? static variable is a class variable which val!e remains constant for the entire class static method is the one which can be called with the class itself and can hold only the staic variables fro m 10) #n 6ava$ @ow to ma+e an object completely encaps!lated? &ll the instance variables sho!ld be declared as private and p!blic getter and setter methods sho!ld be provided for accessing the instance variables.

ifferentiate between a 'he Object class is the highest. fro m 1) What is meant by #nheritance? #nheritance is a relationship among classes$ wherein one class shares the str!ct!re or behavio!r defined in another file into . 'he lass class is !sed to represent the classes and interfaces that are loaded by a 6ava program.c 2*) E5plain wor+ing of 6ava <irt!al 1achine 36<1)? 6<1 is an abstract comp!ting machine li+e any other real comp!ting machine which first converts . 2() What is the difference between this3) and s!per3)? this3) can be !sed to invo+e a constr!ctor of the same class whereas s!per3) can be !sed to invo+e a s!per class constr!ctor. lass and an Object? re j in pa ul . #f a class shares the str!ct!re or behavio!r from m!ltiple classes$ then it is called 1!ltiple #nheritance. #nheritance defines 8is.a9 hierarchy among classes in which one s!bclass inherits from one or more generalised s!perclasses.) and #nterpreter reads byte codes. 'he lass class is !sed to obtain information abo!t an objectBs design. om .2%) What is a pac+age? & pac+age is a collection of classes and interfaces that provides a high. 'his is called ?ingle #nheritance. Every object belongs to a class and every class contains one or more related objects. Whereas an object is an instance or living representation of real life object. () What is meant by Ainding? Ainding denotes association of a name with a class do w ad ed 2) What is meant by #nheritance and what are its advantages? #nheritance is the process of inheriting all the feat!res from a class. UNI II O!"#C -ORI#N #D PROGRAMMING $ IN-#RI ANC# ") What is the difference between s!perclass and s!bclass? & s!per class is a class that is inherited whereas s!b class is a class that does the inheriting.class is nothing b!t byte code file.class file by !sing ompiler 3. 'he advantages of inheritance are re!sability of code and accessibility of variables and methods of the s!per class by s!bclasses.level class in the 6ava class hierarchy. nl o %) .level layer of access protection and name space management. & lass is only a definition or prototype of real life object.

&nonymo!s class4 &nonymo!s class is a class defined inside a method witho!t a name and is instantiated and declared in the same place and cannot have e5plicit constr!ctors fro m 0) What is an &bstract lass? &bstract class is a class that has no instances. &n inner class can have any accessibility incl!ding private. final 1ethods. 'he act!al meaning depends on whether it is applied to a class$ a variable$ or a method. ad ed 12) What are inner class and anonymo!s class? #nner class4 classes defined in other classes$ incl!ding those defined in methods are called inner classes.time. re j final lasses. & final class cannot have s!bclasses. #t is associated with polymorphism and inheritance. & final variable cannot be changed once it is initiali7ed. . &n abstract class is written with the e5pectation that its concrete s!bclasses will add to its str!ct!re and behavio!r$ typically by implementing its abstract operations. -) What is . Polymorphism is a characteristic of being able to assign a different behavior or val!e in a s!bclass$ to something that was declared in a parent class. in pa ul .ynamic binding 3also +nown as late binding) means that the code associated with a given proced!re call is not +nown !ntil the time of the call at r!n. 1") What is reflection in java? Ceflection allows 6ava code to discover information abo!t the fields$ methods and constr!ctors of loaded classes and to dynamically invo+e them. • • • do w nl o 11) What is an #nterface? #nterface is an o!tside view of a class or object which emphai7es its abstraction while hiding its str!ct!re and secrets of its behavio!r. final <ariables. #n 6ava$ Object is the base class for all classes. 12) What is a base class? Aase class is the most generalised class in a class str!ct!re. 1ost applications have s!ch root classes.c om .ynamic Ainding? Ainding refers to the lin+ing of a proced!re call to the code to be e5ec!ted in response to the call. .) What is final modifier? 'he final modifier +eyword ma+es that the programmer cannot change the val!e anymore. & final method cannot be overridden by s!bclasses.*) What is meant by Polymorphism? Polymorphism literally means ta+ing more than one form.

10) an yo! have an inner class inside a method and what variables can yo! access? Ges$ we can have an inner class inside a method and final variables can be accessed. & static inner class does not have any object instances. 'his is also called as Early binding.eclaring methods that one or more classes are e5pected to implement b) apt!ring similarities between !nrelated classes witho!t forcing a class relationship. 1() What is meant by Ainding$ ?tatic binding$ . 22) What is interface and its !se? #nterface is similar to a class which may contain method)s signat!re only b!t not bodies and it is a formal set of method and constant declarations that m!st be defined by the class that implements it. ?!bclass is a class that inherits from one or more classes. #nterfaces are !sef!l for4 a) . b) #n abstract class$ +ey word abstract m!st be !sed for the methods whereas interface we need not !se that +eyword for the methods. 1*) What is reflection &P#? @ow are they implemented? Ceflection is the process of introspecting the feat!res and state of a class at r!ntime and dynamically manip!late at r!n time. Dynamic binding4 .static inner class? & non. #t is also called as Late binding. E5ample4 Esing 6ava Ceflection &P# we can get the class name$ by !sing the getFame method.static inner class may have object instances that are associated with instances of the classBs o!ter class. Static binding: ?tatic binding is a binding in which the class association is made d!ring compile time. 'his is s!pported !sing Ceflection &P# with b!ilt. 1-) What is the difference between a static and a non. c) &bstract class m!st have s!bclasses whereas interface can)t have s!bclasses.) What is the difference between abstract class and interface? a) &ll the methods declared inside an interface are abstract whereas abstract class m!st have at least one abstract method and others may be concrete or abstract.1%) .etermining an do w nl o ad ed fro m re j in pa ul .ynamic binding? Binding: Ainding denotes association of a name with a class.c om . classes li+e lass$ 1ethod$ Dields$ onstr!ctors etc.ynamic binding is a binding in which the class association is not made !ntil the object is created at e5ec!tion time. c) .efine s!perclass and s!bclass? ?!perclass is a class from which another class inherits.

'he first thing is to +now that a 6A!tton)s edges are ad ed • • • 'he class loader to define the pro5y class &n invocation handler to intercept and handle method calls & list of interfaces that the pro5y instance implements fro m 2() .ynamic pro5y.object)s programming interface witho!t revealing the act!al body of the class. 'o create a pro5y$ !se the static method java. UNI III #. 2%) What are the methods provided by the object class? 'he Object class provides five methods that are critical when writing m!ltithreaded 6ava programs4 nl o 2*) What is object cloning? #t is the process of d!plicating an object so that two identical objects will e5ist in the memory at the same time.level class? p!blic$ abstract and final can be !sed for top.lang. or 1&CHEC interface.#N PROGRAMMING do w 1) What is the relationship between the anvas class and the >raphics class? & anvas object provides access to a >raphics object via its paint3) method.c om .efine4 .reflect. 2) @ow wo!ld yo! create a b!tton with ro!nded edges? 'here)s 2 ways.level class.Proxy::newProxy n!tance"). 2") What is a cloneable interface and how many methods does it contain? #t is not having any method beca!se it is a '&>>E.#N -DRI. & dynamic pro5y is a class that implements a list of interfaces$ which yo! specify at r!ntime when yo! create the pro5y. 21) @ow is polymorphism acheived in java? #nheritance$ Overloading and Overriding are !sed to acheive Polymorphism in java. 22) What modifiers may be !sed with top. 'his method ta+es three arg!ments4 re j • • • notify notify&ll wait 3three versions) in pa ul .

drawn by a Aorder. the characters yo! see on the screen. 'he repaint3) method is !sed to ca!se paint3) to be invo+ed by the &W' painting thread. @ence swing wor+s faster than &W'. () Which containers !se a border =ayo!t as their defa!lt layo!t? 'he window$ Drame and . do w nl o .ialog classes !se a border layo!t as their defa!lt layo!t.weight components. c)&pplication starts e5ec!tion with its main method whereas applet starts e5ec!tion with its init method.weight componenets. d)&pplication can r!n with or witho!t graphical !ser interface whereas applet m!st r!n within a graphical !ser interface. Or yo! can create a c!stom border that draws a circle or ro!nded rectangle aro!nd any component and set the b!tton)s border to it. @owever$ the elements ad ed -) . fro m *) What is the difference between applications and applets? a)&pplication m!st be r!n on local machine whereas applet needs no e5plicit installation on local machine.enabled browser. so yo! can override the A!tton)s paint omponent3>raphics) method and draw a circle or ro!nded rectangle 3whatever)$ and t!rn off the border. %ridBagLayout: 'he elements of a >ridAag=ayo!t are organi7ed according to a grid. $ardLayout: 'he elements of a ard=ayo!t are stac+ed$ on top of the other$ li+e a dec+ of cards. Dont1etrics encaps!lates information abo!t a specific font on a specific >raphics object. 'he different layo!ts are available are Dlow=ayo!t$ Aorder=ayo!t$ ard=ayo!t$ >rid=ayo!t and >ridAag=ayo!t. 3width of the characters$ ascent$ descent) .c %) What is the difference between the paint3) and repaint3) methods? 'he paint3) method s!pports painting via a >raphics object.compatible virt!al machine whereas applet loads and r!ns itself a!tomatically in a java. BorderLayout: 'he elements of a Aorder=ayo!t are organi7ed at the borders 3Forth$ ?o!th$ East and West) and the center of a container. re j in pa ul . b)&pplication m!st be r!n e5plicitly within a java. 0) @ow are the elements of different layo!ts organi7ed? #lowLayout4 'he elements of a Dlow=ayo!t are organi7ed in a top to bottom$ left to right fashion. %ridLayout: 'he elements of a >rid=ayo!t are of e/!al si7e and are laid o!t !sing the s/!are of a grid. om ") What is the difference between the IDont) and IDont1etrics) class? 'he Dont lass is !sed to render Iglyphs) .ifference between ?wing and &wt? &W' are heavy.) What is a layo!t manager and what are different types of layo!t managers available in java &W'? & layo!t manager is an object that is !sed to organi7e components in a container. ?wings are light.

c # want to !pdate a ?wing component b!t #)m not in a callbac+. re j in 11) What is an event and what are the models available for event handling? &n event is an event object that describes a state of change in a so!rce. #n other words$ event occ!rs when an action is generated$ li+e pressing b!tton$ clic+ing mo!se$ selecting a list$ etc. delegation model pa ul . Go! m!st e5plicitly call ?ystem. #n addition$ the rows and col!mns may have different si7es. 1*) What is the purpose of the enableEvents() method? The enableEvents() method is used to enable an event for a particular object. #f # don)t care when the !pdate occ!rs$ #)d !se invo+e=ater.are of different si7e and may occ!py more than one row or col!mn of the grid. 'here are two types of models for handling events and they are4 a) event.inheritance model and b) event. 'he default =ayo!t 1anager of Panel and Panel s!b classes is Dlow=ayo!t. Only one item may be selected from a hoice. fro m 1") Why won)t the 6<1 terminate when # close all the application windows? 'he &W' event dispatcher thread is not a daemon thread. 1-) What is the difference between the #ile and $andom%ccess#ile classes? do w nl o ad ed 1%) What is meant by controls and what are different types of controls in &W'? ontrols are components that allow a !ser to interact with yo!r application and the &W' s!pports the following types of controls4 =abels$ P!sh A!ttons$ hec+ Ao5es$ hoice =ists$ =ists$ ?crollbars$ and 'e5t omponents. & =ist s!pports the selection of one or more =ist items. & =ist may be displayed in s!ch a way that several =ist items are visible.e5it to terminate the 6<1.invo+e=ater? . #f # want the !pdate to happen immediately 3perhaps for a progress bar component) then #)d !se invo+e&ndWait. The enableEvents() method is used b objects that handle events b overridin" their eventdispatch methods.invo+e&ndWait or ?wingEtilities. om 12) Why wo!ld yo! !se ?wingEtilities. Normall !an event is enabled when a listener is added to an object for a particular event. 12) What is the difference between scrollbar and scrollpane? & ?crollbar is a omponent$ b!t not a ontainer whereas ?crollpane is a onatiner and handles its own events and perform its own scrolling. 1() What is the difference between a Choice and a List? & hoice is displayed in a compact form that re/!ires yo! to p!ll it down to see the list of available choices. 'hese controls are s!bclasses of omponent.

'his occ!rs when the internal state of that object changes in some way.level class in the &W' event. in pa ul . fro m 21) What is so!rce and listener? !ource : & so!rce is an object that generates an event. 22) What class is the top of the &W' event hierarchy? do w nl o 2") @ow wo!ld yo! detect a +eypress in a 6 omboAo5? 'his is a tric+.) 2%) What an #:O filter? &n #:O filter is an object that reads from one stream and writes to another$ !s!ally altering the data in some way as it is passed from one stream to another. ad ed 22) E5plain how to render an @'1= page !sing only ?wing. ?econd$ it m!st implement methods to receive and process these notifications.The #ile class encapsulates the files and directories of the local file s stem. stop3) method . most people wo!ld say Iadd a Hey=istener to the 6 omboAo5) . UNI I. Go!r component sho!ld override the paint method$ j!st li+e an applet does$ to provide the graphical feat!res of the component.awt. paint3) method . b!t the right answer is Iadd a Hey=istener to the 6 omboAo5)s editor component. Ese a 6EditorPane or 6'e5tPane and set it with an @'1=EditorHit$ then load the te5t into the pane. li!tener : & listener is an object that is notified when an event occ!rs. re j 'he java.class hierarchy. #t has two major re/!irements. destroy3) method . Dirst$ it m!st have been registered with one or more so!rces to receive notifications abo!t specific types of events.c om . an be called when the applet is minimi7ed or ma5imi7ed. an be !sed when the browser moves off the applet)s page. an be called when an applet is first loaded start3) method . The $andom%ccess#ile class provides the methods needed to directl access data contained in an part of a file. 1. 10) What is the difference between a 1en!#tem and a hec+bo51en!#tem? 'he hec+bo51en!#tem class e5tends the 1en!#tem class to s!pport a men! item that may be chec+ed or !nchec+ed.) What is the lifecycle of an applet? init3) method .&W'Event class is the highest. an be called when the browser is finished with the applet. anvas. 2() @ow can # create my own >E# components? !stom graphical components can be created by prod!cing a class that inherits from java.awt. an be called each time an applet is started.

time chec+ing beca!se they can occ!r at many points in the program and recovery from them is diffic!lt or impossible. -) &ow does a tr statement determine which catch clause should be used to handle an e'ception? ad ed $&ec'ed exception!: & chec+ed e5ception is some s!bclass of E5ception 3or E5ception itself)$ e5cl!ding class C!ntimeE5ception and its s!bclasses.c om . • • • ?eparating Error @andling ode from JCeg!larJ Propagating Errors Ep the all ?tac+.ifferentiation. fro m re j in ode. lass Error and its s!bclasses also are !nchec+ed. 2) What is error? &n Error indicates that a non. Error$ a s!bclass of 'hrowable$ is intended for drastic problems$ s!ch as O!tOf1emoryError$ which wo!ld be reported by the 6<1 itself. %) What are the advantages of !sing e5ception handling? E5ception handling provides the following advantages over JtraditionalJ error management techni/!es4 pa ul . ") Which is s!perclass of E5ception? J'hrowableJ$ the parent class of all e5ception related classes. () What are the types of E5ceptions in 6ava 'here are two types of e5ceptions in 6ava$ !nchec+ed e5ceptions and chec+ed e5ceptions. do w nl o (nc&ec'ed exception!: &ll E5ceptions that e5tend the C!ntimeE5ception class are !nchec+ed e5ceptions. & program declaring s!ch e5ceptions wo!ld be pointlessly. >ro!ping Error 'ypes and Error .G#N#RIC PROGRAMMING 1) What is an e5ception? &n exception is an event$ which occ!rs d!ring the e5ec!tion of a program$ that disr!pts the normal flow of the programBs instr!ctions.recoverable condition has occ!rred that sho!ld not be ca!ght. *) Why Errors are Fot hec+ed? & !nchec+ed e5ception classes which are the error classes 3Error and its s!bclasses) are e5empted from compile. Each method m!st either handle all chec+ed e5ceptions by s!pplying a catch cla!se or list each !nhandled chec+ed e5ception as a thrown e5ception.

hec+ed e5ceptions m!st be ca!ght !sing try. The first catch clause that is capable of handlin" the e'ception is e'ecuted. =ist the desired e5ceptions in the throws cla!se of the method and let the caller of the method handle those e5ceptions. 1") What if there is a brea+ or ret!rn statement in try bloc+ followed by finally bloc+? #f there is a ret!rn statement in the try bloc+$ the finally bloc+ e5ec!tes right after the ret!rn statement enco!ntered$ and before the ret!rn e5ec!tes. ad ed 11) What is the catch or declare r!le for method declarations? #f a chec+ed e5ception may be thrown within the body of a method$ the method m!st either catch the e5ception or declare it in its throws cla!se. 1%) What are the different ways to handle e5ceptions? 'here are two ways to handle e5ceptions4 • • do w nl o Wrapping the desired code in a try bloc+ followed by a catch bloc+ to catch the e5ceptions.When an e'ception is thrown within the bod of a tr statement! the catch clauses of the tr statement are e'amined in the order in which the appear.finally statement is always e5ec!ted !nless the thread of e5ec!tion terminates or an e5ception occ!rs within the e5ec!tion of the finally cla!se.catch. . #n most cases it is advisable to let the program terminate when s!ch an error is enco!ntered. 'he error class defines serio!s error conditions that yo! sho!ld not attempt to recover from.finally statement e5ec!ted? 'he finally cla!se of the try.c om . 0) What is the difference between chec+ed and Enchec+ed E5ceptions in 6ava? &ll predefined e5ceptions in 6ava are either a chec+ed e5ception or an !nchec+ed e5ception.) What is the purpose of the finall clause of a tr (catch(finall statement? 'he finally cla!se is !sed to provide the capability to e5ec!te code no matter whether or not an e5ception is thrown or ca!ght. re j in pa ul . The remainin" catch clauses are i"nored. 12) When is the finally cla!se of a try. catch 3) bloc+ or we sho!ld throw the e5ception !sing throws cla!se. fro m )*) What is the difference between e5ception and error? 'he e5ception class defines mild error conditions that yo!r program enco!nters.catch. #f yo! dont$ compilation of program will fail.. E5ceptions can occ!r when trying to open the file$ which does not e5ist$ the networ+ connection is disr!pted$ operands being manip!lated are o!t of prescribed ranges$ the class file yo! are interested in loading is missing.

1-) What is the difference between swing and applet? ?wing is a light weight component whereas &pplet is a heavy weight omponent.time system. E5ceptions thrown by 6ava relate to f!ndamental errors that violate the r!les of the 6ava lang!age or the constraints of the 6ava e5ec!tion environment.) What is the !se of assert +eyword? &ssert +eyword validates certain e5pressions. pa ul . Example: class MyException extends Exception { public MyException() { super(). ad ed fro m 1. re j in 1*) an we have the try bloc+ witho!t catch bloc+? Ges$ we can have the try bloc+ witho!t catch bloc+$ b!t finally bloc+ sho!ld follow the try bloc+. 2. #t replaces the if bloc+ effectively and throws an &ssertionError on fail!re. finali7e3) is a protected method in the Object class which is called by the 6<1 j!st before an object is garbage collected. 22) What is the difference between throw and throws cla!se? throw is !sed to throw an e5ception man!ally$ where as throws is !sed in the case of chec+ed e5ceptions$ to tell the compiler that we havenBt handled the e5ception$ so that the e5ception will be handled by the calling f!nction.c om public MyException(String s) { super(s). Note' #t is not valid to !se a try cla!se witho!t either a catch cla!se or a finally cla!se. } } 10) @ow does finally bloc+ differ from finali7e3) method? Dinally bloc+ will be e5ec!ted whether or not an e5ception is thrown.1() @ow to create c!stom e5ceptions? Ay e5tending the E5ception class or one of its s!bclasses. do w nl o 21) What are the different ways to generate and E5ception? 'here are two different ways to generate an E5ception. E5ceptions can be generated by the 6ava r!n. &pplet does not re/!ire main method$ instead it needs init method. 'he assert +eyword sho!ld be !sed only for critical arg!ments 3means witho!t that the method does nothing). } . E5ceptions can be man!ally generated by yo!r code. ?o it is !sed to free resoo!rces. 1.

lang. void swap3)K swap3)L M ad ed 2() @ow do yo! get the descriptive information abo!t the E5ception occ!rred d!ring the program e5ec!tion? &ll the e5ceptions inherit a method print?tac+'race3) from the 'hrowable class. 'he hierarchy is as follows4 'hrowable is a parent class off all E5ception classes. #t may occ!r in case of rec!rsive methods or a large amo!nt of data is fetched from the server and stored in some object.lang. 2) What are the different states of a thread ? 'he different thread states are ready$ r!nning$ waiting and dead. om java. 'hey are two types of E5ceptions4 hec+ed e5ceptions and Enchec+edE5ceptions. 'his error is generated by 6<1.#1(e2tion java. 22) Where does E5ception stand in the 6ava tree hierarchy? • • • • e.O*/e(t java.the only interface can help.lang. 'his method prints the stac+ trace from where the e5ception occ!rred. 'he former is more advantageo!s$ Bca!se when yo! are going for m!ltiple inheritance. UNI .g. 0rowa*+e java.. nl o do w 1) E5plain different way of !sing thread? 'he thread co!ld be implemented by !sing r!nnable interface or by inheriting from the 'hread class.lang. Aoth type of e5ceptions e5tends E5ception class CONCURR#N PROGRAMMING re j in pa ul .#rror . fro m 2%) E5plain the e5ception hierarchy in java.1an!ally generated e5ceptions are typically !sed to report some error condition to the caller of a method.c 2") What is StackOverflowError? 'he ?tac+OverDlowError is an Error Object thorwn by the C!ntime ?ystem when it Enco!nters that yo!r application:code has ran o!t of the memory. #t prints the most recently entered method first and contin!es down$ printing the name of each method as it wor+s its way down the call stac+ from the top.

) What happens when yo! invo+e a threadBs interr!pt method while it is sleeping or waiting? When a tas+Bs interr!pt3) method is e5ec!ted$ the tas+ enters the ready state.c om . 'he wait method gives !p control over thread e5ec!tion indefinitely so that other threads can r!n. wait3) 4 When a thread e5ec!tes a call to wait3) method$ it s!rrenders the object loc+ and enters into a waiting state. 'hen we need to override the method p!blic void r!n3). Ay /!ic+ly switching between e5ec!ting tas+s$ it creates the impression that tas+s e5ec!te se/!entially. 'his often leads to significant errors. 12) What are three ways in which a thread can enter the waiting state? % thread can enter the waitin" state b invo+in" its sleep() method! b bloc+in" on . do w nl o . notify3) or notify&ll3) 4 'o remove a thread from the waiting state$ some other thread m!st ma+e a call to notify3) or notify&ll3) method on the same object.! b unsuccessfull attemptin" to ac/uire an ad ed -) What is the difference between process and thread? Process is a program in e5ec!tion whereas thread is a separate path of e5ec!tion in a program.thread comm!nication and what is the class in which these methods are defined? 1!ltithreading is the mechanism in which more than one thread r!n independent of each other within the process. 'he ne5t time the tas+ enters the r!nning state$ an #nterr!ptedE5ception is thrown.thread comm!nication and these methods are in Object class. With respect to m!ltithreading$ synchroni7ation is the capability to control the access of m!ltiple threads to shared reso!rces.") Why are there separate wait and s+ee2 methods? 'he static 0read3s+ee24+on56 method maintains control of thread e5ec!tion b!t delays the ne5t action !ntil the sleep time e5pires.-. fro m re j in () What is synchroni7ation and why is it important? pa ul . %) What is m!ltithreading and what are the methods for inter. 0) @ow can we create a thread? & thread can be created by e5tending 'hread class or by implementing C!nnable interface. wait 3)$ notify 3) and notify&ll3) methods can be !sed for inter. *) @ow does m!ltithreading ta+e place on a comp!ter with a single PE? 'he operating systemBs tas+ sched!ler allocates e5ec!tion time to m!ltiple tas+s. Witho!t synchroni7ation$ it is possible for one thread to modify a shared object while another thread is in the process of !sing or !pdating that objectBs val!e.

1-) What is the difference between yielding and sleeping? When a tas+ invo+es its yield3) method$ it ret!rns to the ready state. #f is&live3) ret!rned false the thread was either new or terminated b!t there was simply no way to differentiate between the two. set. ObjectO!tp!t?tream seriali7es only those objects which implement this interface. do w nl o 1. 'o !nderstand synchroni7ation we need to loo+ into thread e5ec!tion manner. #t serves to assign the ?eriali7able data type to the tagged class and to identify the class as one which the developer has designed for persistence. When a tas+ invo+es its sleep3) method$ it ret!rns to the waiting state. om . 10) What classes of e5ceptions may be thrown by a throw statement? & throw statement may throw any e5pression that may be assigned to the 'hrowable type. 1") What is seriali7ation? 1%) What does the ?eriali7able interface do? ?eriali7able is a tagging interfaceL it prescribes no methods.c 12) What is synchroni7ed +eyword? #n what sit!ations yo! will Ese it? ?ynchroni7ation is the act of seriali7ing access to critical sections of code.t can also enter the waitin" state b invo+in" its (deprecated) suspend() method.aemon method is !sed to create a daemon thread.object0s loc+! or b invo+in" an object0s wait() method. 11) @ow can i tell what state a thread is in ? Prior to 6ava ($ is&live3) was commonly !sed to test a threads state.) What is casting? 'here are two types of casting$ casting between primitive n!meric types and casting between object references. . We will !se this +eyword when we e5pect m!ltiple threads to access:modify the same data. asting between n!meric types is !sed to convert larger val!es$ s!ch as do!ble val!es$ to smaller val!es$ s!ch as byte val!es. asting between object references is !sed to refer to an object by a compatible class$ interface$ or array type reference. pa ul . 1*) What is daemon thread and which method is !sed to create the daemon thread? .aemon thread is a low priority thread which r!ns intermittently in the bac+ gro!nd doing the garbage collection operation for the java r!ntime system. ad ed fro m re j in ?eriali7ation is the process of writing complete state of java object into o!tp!t stream$ that stream can be file or byte array or stream associated with ' P:#P soc+et. 1() When yo! will synchroni7e a piece of yo!r code? When yo! e5pect yo!r code will be accessed by different threads and these threads may change a partic!lar data ca!sing data corr!ption.

2*) What is a thread gro!p? & thread gro!p is a data str!ct!re that controls the state of collection of thread as a whole managed by the partic!lar r!ntime environment.22) & 0read is r!nnable$ how does that wor+? 'he 0read classB run method normally invo+es the run method of the Runna*+e type it is passed in its constr!ctor. 21) an # implement my own start46 method? 'he 0read start46 method is not mar+ed 7ina+$ b!t sho!ld not be overridden. do w nl o 2() @ow wo!ld yo! implement a thread pool? 'he 'hreadPool class is a generic implementation of a thread pool$ which ta+es the following inp!t ?i7e of the pool to be constr!cted and name of the class which implements C!nnable 3which has a visible defa!lt constr!ctor) and constr!cts a thread pool with active threads that are waiting for activation. re j in 22) . pa ul . 12 and the defa!lt val!e is (. Ay invo+ing its sleep3) method$ by bloc+ing on #:O$ by !ns!ccessf!lly attempting to ac/!ire an objectBs loc+$ or by invo+ing an objectBs wait3) method. @owever$ it is possible to override the threadBs run method with yo!r own. 'his method contains the code that creates a new e5ec!table thread and is very specialised. ad ed 2%) What are the different ways in which a thread can enter into waiting state? 'here are three ways for a thread to enter into waiting state.a+ue4int6? #t depends whether the method affects method local variables$ class static or instance variables. 'he thread sched!ling depends on the O?. once the threads have finished processing they come bac+ and wait once again in the pool.o # need to !se s8n(0roni9ed on set. #f only method local variables are changed$ the val!e is said to be confined by the method and is not prone to threading iss!es. A!t if a thread have higher priority doesnBt means that it will e5ec!te first. fro m 2") What is thread priority? 'hread Priority is an integer val!e that identifies the relative order in which it sho!ld be e5ec!ted with respect to others. Go!r threaded application sho!ld either pass a Runna*+e type to a new 0read$ or e5tend 0read and override the run46 method.c om . 'he thread priority val!es ranging from 1.