Sunteți pe pagina 1din 19

IT2301 JAVA PROGRAMMING UNIT I 1) What is meant by Object Oriented Programming?

OOP is a method of programming in which programs are organized as cooperative collections of objects. Each object is an instance of a class and each class belong to a hierarchy. ) 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. #) What is an Object? Object is an instance of a class. $t has state% behavior and identity. $t is also called as an instance of a class. &) 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. )) What are the core OOP*s concepts? 'bstraction% Encaps"lation% $nheritance and Polymorphism are the core OOP*s concepts. +) 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 ac0"ires the properties of another object. Polymorphism is the feat"re that allows one interface to be "sed for general class actions.

1) What are methods and how are they defined? 2ethods are f"nctions that operate on instances of classes in which they are defined. Objects can comm"nicate with each other "sing methods and can call methods in other classes. 2ethod definition has fo"r parts. (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. ' method*s signat"re is a combination of the first three parts mentioned above. 13) What are different types of access modifiers 4'ccess specifiers)? 'ccess specifiers are ,eywords that determine the type of access to the member of a class. (hese ,eywords are for allowing privileges to parts of a program s"ch as f"nctions and variables. (hese are5 public: 'ny thing declared as p"blic can be accessed from anywhere. private: 'ny thing declared as private can*t be seen o"tside of its class. protected: 'ny thing declared as protected can be accessed by classes in the same pac,age and s"bclasses in the other pac,ages. 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. When an object is created "sing new operator% memory is allocated to it. 1 ) E6plain the "sage of 7ava pac,ages. (his is a way to organize files when a project consists of m"ltiple mod"les. $t also helps resolve naming conflicts when different pac,ages have classes with the same names. Pac,ages access level also allows yo" to protect data from being "sed by the non-a"thorized classes. 1#) What is method overloading and method overriding? 2ethod overloading5 When a method in a class having the same method name with different arg"ments is said to be method overloading. 2ethod overriding 5 When a method in a class having the same method name with same arg"ments is said to be method overriding. 1&) What gives java it*s 8write once and r"n anywhere9 nat"re? 'll 7ava programs are compiled into class files that contain bytecodes. (hese byte codes can be r"n in any platform and hence java is said to be platform independent. 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. ;estr"ctor is an operation that frees the state of an object and:or destroys the object itself. $n 7ava% there is no concept of destr"ctors. $ts ta,en care by the 7<2.

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 e6plicitly 1.) What is Static member classes? ' static member class is a static member of a class. =i,e any other static method% a static member class has access to all static methods of the parent% or top-level% class. 1/) What is >arbage !ollection and how to call it e6plicitly? When an object is no longer referred to by any variable% java a"tomatically reclaims memory "sed by that object. (his is ,nown as garbage collection. ?ystem. gc4) method may be "sed to call it e6plicitly 11) $n 7ava% @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. 3) 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 1) What is finalize4) method? finalize 4) method is "sed j"st before an object is destroyed and can be called j"st prior to garbage collection. ) What is the difference between ?tring and ?tring A"ffer? a) ?tring objects are constants and imm"table whereas ?tringA"ffer objects are not. b) ?tring class s"pports constant strings whereas ?tringA"ffer class s"pports growable and modifiable strings. #) 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 &) What is a pac,age? ' pac,age is a collection of classes and interfaces that provides a highlevel layer of access protection and name space management. )) What is the difference between this4) and s"per4)? this4) can be "sed to invo,e a constr"ctor of the same class whereas s"per4) can be "sed to invo,e a s"per class constr"ctor.

+) E6plain wor,ing of 7ava <irt"al 2achine 47<2)? 7<2 is an abstract comp"ting machine li,e any other real comp"ting machine which first converts .java file into .class file by "sing !ompiler 4.class is nothing b"t byte code file.) and $nterpreter reads byte codes.

UNIT II 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 class. (his is called ?ingle $nheritance. $f a class shares the str"ct"re or behavio"r from m"ltiple classes% then it is called 2"ltiple $nheritance. $nheritance defines 8is-a9 hierarchy among classes in which one s"bclass inherits from one or more generalised s"perclasses. ) What is meant by $nheritance and what are its advantages? $nheritance is the process of inheriting all the feat"res from a class. (he advantages of inheritance are re"sability of code and accessibility of variables and methods of the s"per class by s"bclasses. #) 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. &) ;ifferentiate between a !lass and an Object? (he Object class is the highest-level class in the 7ava class hierarchy. (he !lass class is "sed to represent the classes and interfaces that are loaded by a 7ava program. (he !lass class is "sed to obtain information abo"t an objectBs design. ' !lass is only a definition or prototype of real life object. Whereas an object is an instance or living representation of real life object. Every object belongs to a class and every class contains one or more related objects. )) What is meant by Ainding? Ainding denotes association of a name with a class. +) What is meant by Polymorphism? Polymorphism literally means ta,ing more than one form. 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. .) What is ;ynamic Ainding? Ainding refers to the lin,ing of a proced"re call to the code to be e6ec"ted in response to the call. ;ynamic binding 4also ,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-time. $t is associated with polymorphism and inheritance. /) What is final modifier? (he final modifier ,eyword ma,es that the programmer cannot change the val"e anymore. (he act"al meaning depends on whether it is applied to a class% a variable% or a method.

final !lasses- ' final class cannot have s"bclasses. final <ariables- ' final variable cannot be changed once it is initialized. final 2ethods- ' final method cannot be overridden by s"bclasses.

1) What is an 'bstract !lass? 'bstract class is a class that has no instances. 'n abstract class is written with the e6pectation that its concrete s"bclasses will add to its str"ct"re and behavio"r% typically by implementing its abstract operations. 13) What are inner class and anonymo"s class? $nner class5 classes defined in other classes% incl"ding those defined in methods are called inner classes. 'n inner class can have any accessibility incl"ding private. 'nonymo"s class5 '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 e6plicit constr"ctors 11) What is an $nterface? $nterface is an o"tside view of a class or object which emphaizes its abstraction while hiding its str"ct"re and secrets of its behavio"r. 1 ) What is a base class? Aase class is the most generalised class in a class str"ct"re. 2ost applications have s"ch root classes. $n 7ava% Object is the base class for all classes. 1#) What is reflection in java? Ceflection allows 7ava code to discover information abo"t the fields% methods and constr"ctors of loaded classes and to dynamically invo,e them. 1&) ;efine s"perclass and s"bclass? ?"perclass is a class from which another class inherits. ?"bclass is a class that inherits from one or more classes. 1)) What is meant by Ainding% ?tatic binding% ;ynamic binding? Binding: Ainding denotes association of a name with a class. Static binding: ?tatic binding is a binding in which the class association is made d"ring compile time. (his is also called as Early binding. Dynamic binding5 ;ynamic binding is a binding in which the class association is not made "ntil the object is created at e6ec"tion time. $t is also called as Late binding.

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. (his is s"pported "sing Ceflection 'P$ with b"ilt-in classes li,e !lass% 2ethod% Dields% !onstr"ctors etc. E6ample5 Esing 7ava Ceflection 'P$ we can get the class name% by "sing the getFame method. 1.) What is the difference between a static and a non-static inner class? ' nonstatic inner class may have object instances that are associated with instances of the classBs o"ter class. ' static inner class does not have any object instances. 1/) 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. 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. c) 'bstract class m"st have s"bclasses whereas interface can*t have s"bclasses. 11) !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. 3) 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. $nterfaces are "sef"l for5 a) ;eclaring methods that one or more classes are e6pected to implement b) !apt"ring similarities between "nrelated classes witho"t forcing a class relationship. c) ;etermining an object*s programming interface witho"t revealing the act"al body of the class. 1) @ow is polymorphism acheived in java? $nheritance% Overloading and Overriding are "sed to acheive Polymorphism in java. ) What modifiers may be "sed with top-level class? p"blic% abstract and final can be "sed for top-level class. #) What is a cloneable interface and how many methods does it contain? $t is not having any method beca"se it is a ('>>E; or 2'CHEC interface. &) What are the methods provided by the object class? (he Object class provides five methods that are critical when writing m"ltithreaded 7ava programs5

notify notify'll wait 4three versions)

)) ;efine5 ;ynamic pro6y. ' dynamic pro6y is a class that implements a list of interfaces% which yo" specify at r"ntime when yo" create the pro6y. (o create a pro6y% "se the static method java.lang.reflect.Proxy::newProxy n!tance"). (his method ta,es three arg"ments5

(he class loader to define the pro6y class 'n invocation handler to intercept and handle method calls ' list of interfaces that the pro6y instance implements

+) What is object cloning? $t is the process of d"plicating an object so that two identical objects will e6ist in the memory at the same time. UNIT III 1) What is the relationship between the !anvas class and the >raphics class? ' !anvas object provides access to a >raphics object via its paint4) method. ) @ow wo"ld yo" create a b"tton with ro"nded edges? (here*s ways. (he first thing is to ,now that a 7A"tton*s edges are drawn by a Aorder. so yo" can override the A"tton*s paint!omponent4>raphics) method and draw a circle or ro"nded rectangle 4whatever)% and t"rn off the border. 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. #) What is the difference between the IDont* and IDont2etrics* class? (he Dont !lass is "sed to render Iglyphs* - the characters yo" see on the screen. Dont2etrics encaps"lates information abo"t a specific font on a specific >raphics object. 4width of the characters% ascent% descent) &) What is the difference between the paint4) and repaint4) methods? (he paint4) method s"pports painting via a >raphics object. (he repaint4) method is "sed to ca"se paint4) to be invo,ed by the 'W( painting thread. )) Which containers "se a border =ayo"t as their defa"lt layo"t? (he window% Drame and ;ialog classes "se a border layo"t as their defa"lt layo"t. +) What is the difference between applications and applets? a)'pplication m"st be r"n on local machine whereas applet needs no e6plicit installation on local machine.

b)'pplication m"st be r"n e6plicitly within a java-compatible virt"al machine whereas applet loads and r"ns itself a"tomatically in a java-enabled browser. c)'pplication starts e6ec"tion with its main method whereas applet starts e6ec"tion with its init method. d)'pplication can r"n with or witho"t graphical "ser interface whereas applet m"st r"n within a graphical "ser interface. .) ;ifference between ?wing and 'wt? 'W( are heavy-weight componenets. ?wings are light-weight components. @ence swing wor,s faster than 'W(. /) 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 organize components in a container. (he different layo"ts are available are Dlow=ayo"t% Aorder=ayo"t% !ard=ayo"t% >rid=ayo"t and >ridAag=ayo"t. 1) @ow are the elements of different layo"ts organized? #lowLayout5 (he elements of a Dlow=ayo"t are organized in a top to bottom% left to right fashion. BorderLayout: (he elements of a Aorder=ayo"t are organized at the borders 4Forth% ?o"th% East and West) and the center of a container. $ardLayout: (he elements of a !ard=ayo"t are stac,ed% on top of the other% li,e a dec, of cards. %ridLayout: (he elements of a >rid=ayo"t are of e0"al size and are laid o"t "sing the s0"are of a grid. %ridBagLayout: (he elements of a >ridAag=ayo"t are organized according to a grid. @owever% the elements are of different size and may occ"py more than one row or col"mn of the grid. $n addition% the rows and col"mns may have different sizes. (he default =ayo"t 2anager of Panel and Panel s"b classes is Dlow=ayo"t. 13) Why wo"ld yo" "se ?wingEtilities.invo,e'ndWait or ?wingEtilities.invo,e=ater? $f we want the "pdate to happen immediately 4perhaps for a progress bar component) then we "se invo,e'ndWait. 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. (here are two types of models for handling events and they are5 a) event-inheritance model and b) event-delegation model 1 ) 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#) Why won*t the 7<2 terminate when $ close all the application windows? 'W( event dispatcher thread is not a daemon thread. Go" m"st e6plicitly call ?ystem.e6it to terminate the 7<2.

(he

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 controls5 =abels% P"sh A"ttons% !hec, Ao6es% !hoice =ists% =ists% ?crollbars% and (e6t !omponents. (hese controls are s"bclasses of !omponent. 1)) What is the difference between a !hoice and a =ist? ' !hoice is displayed in a compact form that re0"ires yo" to p"ll it down to see the list of available choices. Only one item may be selected from a !hoice. ' =ist may be displayed in s"ch a way that several =ist items are visible. ' =ist s"pports the selection of one or more =ist items. 1+) What is the p"rpose of the enableEvents4) method? (he enableEvents4) method is "sed to enable an event for a partic"lar object. Formally%an event is enabled when a listener is added to an object for a partic"lar event. (he enableEvents4) method is "sed by objects that handle events by overriding their eventdispatch methods. 1.) What is the difference between the Dile and Candom'ccessDile classes? (he Dile class encaps"lates the files and directories of the local file system. (he Candom'ccessDile class provides the methods needed to directly access data contained in any part of a file. 1/) What is the lifecycle of an applet? init4) method - !an be called when an applet is first loaded start4) method - !an be called each time an applet is started. paint4) method - !an be called when the applet is minimized or ma6imized. stop4) method - !an be "sed when the browser moves off the applet*s page. destroy4) method - !an be called when the browser is finished with the applet. 11) What is the difference between a 2en"$tem and a !hec,bo62en"$tem? (he !hec,bo62en"$tem class e6tends the 2en"$tem class to s"pport a men" item that may be chec,ed or "nchec,ed. 3) What class is the top of the 'W( event hierarchy? (he java.awt.'W(Event class is the highest-level class in the 'W( event-class hierarchy. 1) What is so"rce and listener? !ource : ' so"rce is an object that generates an event. (his occ"rs when the internal state of that object changes in some way. li!tener : ' listener is an object that is notified when an event occ"rs. $t has two major re0"irements. Dirst% it m"st have been registered with one or more so"rces to receive notifications

abo"t specific types of events. ?econd% it m"st implement methods to receive and process these notifications. ) E6plain how to render an @(2= page "sing only ?wing. Ese a 7EditorPane or 7(e6tPane and set it with an @(2=EditorHit% then load the te6t into the pane. #) @ow wo"ld yo" detect a ,eypress in a 7!omboAo6? (his is a tric,. most people wo"ld say Iadd a Hey=istener to the 7!omboAo6* - b"t the right answer is Iadd a Hey=istener to the 7!omboAo6*s editor component.* &) 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. )) @ow can $ create my own >E$ components? !"stom graphical components can be created by prod"cing a class that inherits from java.awt.!anvas. 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. UNIT IV GENERI PROGRAMMING 1) What is an e6ception? 'n exception is an event% which occ"rs d"ring the e6ec"tion of a program% that disr"pts the normal flow of the programBs instr"ctions. ) What is error? 'n Error indicates that a non-recoverable condition has occ"rred that sho"ld not be ca"ght. Error% a s"bclass of (hrowable% is intended for drastic problems% s"ch as O"tOf2emoryError% which wo"ld be reported by the 7<2 itself. #) Which is s"perclass of E6ception? the parent class of all e6ception related classes. J(hrowableJ%

&) What are the advantages of "sing e6ception handling? E6ception handling provides the following advantages over JtraditionalJ error management techni0"es5 ?eparating Error @andling !ode from JCeg"larJ !ode. Propagating Errors Ep the !all ?tac,. >ro"ping Error (ypes and Error ;ifferentiation. )) What are the types of E6ceptions in 7ava (here are two types of e6ceptions in 7ava% "nchec,ed e6ceptions and chec,ed e6ceptions.

$&ec'ed exception!: ' chec,ed e6ception is some s"bclass of E6ception 4or E6ception itself)% e6cl"ding class C"ntimeE6ception and its s"bclasses. Each method m"st either handle all chec,ed e6ceptions by s"pplying a catch cla"se or list each "nhandled chec,ed e6ception as a thrown e6ception. (nc&ec'ed exception!: 'll E6ceptions that e6tend the C"ntimeE6ception class are "nchec,ed e6ceptions. !lass Error and its s"bclasses also are "nchec,ed. +) Why Errors are Fot !hec,ed? ' "nchec,ed e6ception classes which are the error classes 4Error and its s"bclasses) are e6empted from compile-time chec,ing beca"se they can occ"r at many points in the program and recovery from them is diffic"lt or impossible. ' program declaring s"ch e6ceptions wo"ld be pointlessly. .) @ow does a try statement determine which catch cla"se sho"ld be "sed to handle an e6ception? When an e6ception is thrown within the body of a try statement% the catch cla"ses of the try statement are e6amined in the order in which they appear. (he first catch cla"se that is capable of handling the e6ception is e6ec"ted. (he remaining catch cla"ses are ignored. /) What is the p"rpose of the finally cla"se of a try-catch-finally statement? (he finally cla"se is "sed to provide the capability to e6ec"te code no matter whether or not an e6ception is thrown or ca"ght. 1) What is the difference between chec,ed and Enchec,ed E6ceptions in 7ava? 'll predefined e6ceptions in 7ava are either a chec,ed e6ception or an "nchec,ed e6ception. !hec,ed e6ceptions m"st be ca"ght "sing try.. catch 4) bloc, or we sho"ld throw the e6ception "sing throws cla"se. $f yo" dont% compilation of program will fail. 13) What is the difference between e6ception and error? (he e6ception class defines mild error conditions that yo"r program enco"nters. E6ceptions can occ"r when trying to open the file% which does not e6ist% 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. (he error class defines serio"s error conditions that yo" sho"ld not attempt to recover from. $n most cases it is advisable to let the program terminate when s"ch an error is enco"ntered. 11) What is the catch or declare r"le for method declarations? $f a chec,ed e6ception may be thrown within the body of a method% the method m"st either catch the e6ception or declare it in its throws cla"se. 1 ) When is the finally cla"se of a try-catch-finally statement e6ec"ted? (he finally cla"se of the try-catch-finally statement is always e6ec"ted "nless the thread of e6ec"tion terminates or an e6ception occ"rs within the e6ec"tion of the finally cla"se.

1#) What if there is a break or return statement in try block followed by finally block? $f there is a ret"rn statement in the try bloc,% the finally bloc, e6ec"tes right after the ret"rn statement enco"ntered% and before the ret"rn e6ec"tes.

1&) What are the different ways to handle e6ceptions? (here are two ways to handle e6ceptions5 Wrapping the desired code in a try bloc, followed by a catch bloc, to catch the e6ceptions. =ist the desired e6ceptions in the throws cla"se of the method and let the caller of the method handle those e6ceptions. 1)) @ow to create c"stom e6ceptions? Ay e6tending the E6ception class or one of its s"bclasses. E!am"le: class 2yE6ception e6tends E6ception K p"blic 2yE6ception4) K s"per4)L M p"blic 2yE6ception4?tring s) K s"per4s)L M M 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,. N#te: $t is not valid to "se a try cla"se witho"t either a catch cla"se or a finally cla"se. 1.) What is the difference between swing and applet? ?wing is a light weight component whereas 'pplet is a heavy weight !omponent. 'pplet does not re0"ire main method% instead it needs init method. 1/) What is the "se of assert ,eyword? 'ssert ,eyword validates certain e6pressions. $t replaces the if bloc, effectively and throws an 'ssertionError on fail"re. (he assert ,eyword sho"ld be "sed only for critical arg"ments 4means witho"t that the method does nothing). 11) @ow does finally bloc, differ from finalize4) method? Dinally bloc, will be e6ec"ted whether or not an e6ception is thrown. ?o it is "sed to free reso"rces. finalize4) is a protected method in the Object class which is called by the 7<2 j"st before an object is garbage collected. 3) What is the difference between throw and throws cla"se? throw is "sed to throw an e6ception man"ally% where as throws is "sed in the case

of chec,ed e6ceptions% to tell the compiler that we havenBt handled the e6ception% so that the e6ception will be handled by the calling f"nction. 1) What are the different ways to generate and E6ception? (here are two different ways to generate an E6ception. 1. E6ceptions can be generated by the 7ava r"n-time system. E6ceptions thrown by 7ava relate to f"ndamental errors that violate the r"les of the 7ava lang"age or the constraints of the 7ava e6ec"tion environment. . E6ceptions can be man"ally generated by yo"r code. 2an"ally generated e6ceptions are typically "sed to report some error condition to the caller of a method. ) Where does E6ception stand in the 7ava tree hierarchy? java.lang.Ob$ect java.lang.T%r#&able java.lang.E!ce"ti#' java.lang.Err#r #) (%at is Stac)O*er+l#&Err#r? (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 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. (his error is generated by 7<2. e.g. void swap4)K swap4)L M &) E6plain the e6ception hierarchy in java. (he hierarchy is as follows5 (hrowable is a parent class off all E6ception classes. (hey are two types of E6ceptions5 !hec,ed e6ceptions and Enchec,edE6ceptions. Aoth type of e6ceptions e6tends E6ception class )) @ow do yo" get the descriptive information abo"t the E6ception occ"rred d"ring the program e6ec"tion? 'll the e6ceptions inherit a method print?tac,(race4) from the (hrowable class. (his method prints the stac, trace from where the e6ception occ"rred. $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. UNIT V

1) E6plain different way of "sing thread? (he thread co"ld be implemented by "sing r"nnable interface or by inheriting from the (hread class. (he former is more advantageo"s% Bca"se when yo" are going for m"ltiple inheritance..the only interface can help. ) What are the different states of a thread ? (he different thread states are ready% r"nning% waiting and dead. 3, Why are there separate &ait and slee" methods? (he static T%rea-.slee"/l#'0, method maintains control of thread e6ec"tion b"t delays the ne6t action "ntil the sleep time e6pires. (he &ait method gives "p control over thread e6ec"tion indefinitely so that other threads can r"n. &) What is m"ltithreading and what are the methods for inter-thread comm"nication and what is the class in which these methods are defined? 2"ltithreading is the mechanism in which more than one thread r"n independent of each other within the process. wait 4)% notify 4) and notify'll4) methods can be "sed for inter-thread comm"nication and these methods are in Object class. wait4) 5 When a thread e6ec"tes a call to wait4) method% it s"rrenders the object loc, and enters into a waiting state. notify4) or notify'll4) 5 (o remove a thread from the waiting state% some other thread m"st ma,e a call to notify4) or notify'll4) method on the same object. )) What is synchronization and why is it important? With respect to m"ltithreading% synchronization is the capability to control the access of m"ltiple threads to shared reso"rces. Witho"t synchronization% 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. (his often leads to significant errors. +) @ow does m"ltithreading ta,e place on a comp"ter with a single !PE? (he operating systemBs tas, sched"ler allocates e6ec"tion time to m"ltiple tas,s. Ay 0"ic,ly switching between e6ec"ting tas,s% it creates the impression that tas,s e6ec"te se0"entially. .) What is the difference between process and thread? Process is a program in e6ec"tion whereas thread is a separate path of e6ec"tion in a program. /) What happens when yo" invo,e a threadBs interr"pt method while it is sleeping or waiting? When a tas,Bs interr"pt4) method is e6ec"ted% the tas, enters the ready state. (he ne6t time the tas, enters the r"nning state% an $nterr"ptedE6ception is thrown. 1) @ow can we create a thread? ' thread can be created by e6tending (hread class or by implementing C"nnable interface. (hen we need to override the method p"blic void r"n4).

13) What are three ways in which a thread can enter the waiting state? ' thread can enter the waiting state by invo,ing its sleep4) method% by bloc,ing on $:O% by "ns"ccessf"lly attempting to ac0"ire an objectBs loc,% or by invo,ing an objectBs wait4) method. $t can also enter the waiting state by invo,ing its 4deprecated) s"spend4) method. 11) what state a thread is in ? is'live4) was commonly "sed to test a threads state. $f is'live4) ret"rned false the thread was either new or terminated b"t there was simply no way to differentiate between the two. 1 ) What is synchronized ,eyword? $n what sit"ations yo" will Ese it? ?ynchronization is the act of serializing access to critical sections of code. We will "se this ,eyword when we e6pect m"ltiple threads to access:modify the same data. (o "nderstand synchronization we need to loo, into thread e6ec"tion manner. 1#) What is serialization? ?erialization 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&) What does the ?erializable interface do? ?erializable is a tagging interfaceL it prescribes no methods. $t serves to assign the ?erializable data type to the tagged class and to identify the class as one which the developer has designed for persistence. ObjectO"tp"t?tream serializes only those objects which implement this interface. 1)) When yo" will synchronize a piece of yo"r code? When yo" e6pect yo"r code will be accessed by different threads and these threads may change a partic"lar data ca"sing data corr"ption. 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. set;aemon method is "sed to create a daemon thread. 1.) What is the difference between yielding and sleeping? When a tas, invo,es its yield4) method% it ret"rns to the ready state. When a tas, invo,es its sleep4) method% it ret"rns to the waiting state. 1/) What is casting? (here are two types of casting% casting between primitive n"meric types and casting between object references. !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.

11) What classes of e6ceptions may be thrown by a throw statement? ' throw statement may throw any e6pression that may be assigned to the (hrowable type. 3) ' T%rea- is r"nnable% how does that wor,? (he T%rea- classB r1' method normally invo,es the r1' method of the R1''able type it is passed in its constr"ctor. @owever% it is possible to override the threadBs r1' method with yo"r own. 1) !an $ implement my own start/, method? (he T%rea- start/, method is not mar,ed +i'al% b"t sho"ld not be overridden. (his method contains the code that creates a new e6ec"table thread and is very specialised. Go"r threaded application sho"ld either pass a R1''able type to a new T%rea-% or e6tend T%rea- and override the r1'/, method. ) ;o $ need to "se s2'c%r#'i3e- on setVal1e/i't,? $t depends whether the method affects method local variables% class static or instance variables. $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. #) What is thread priority? (hread Priority is an integer val"e that identifies the relative order in which it sho"ld be e6ec"ted with respect to others. (he thread priority val"es ranging from 1- 13 and the defa"lt val"e is ). A"t if a thread have higher priority doesnBt means that it will e6ec"te first. (he thread sched"ling depends on the O?. &) 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. Ay invo,ing its sleep4) method% by bloc,ing on $:O% by "ns"ccessf"lly attempting to ac0"ire an objectBs loc,% or by invo,ing an objectBs wait4) method. )) @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 ?ize of the pool to be constr"cted and name of the class which implements C"nnable 4which has a visible defa"lt constr"ctor) and constr"cts a thread pool with active threads that are waiting for activation. once the threads have finished processing they come bac, and wait once again in the pool. +) 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.

Part A Enit 1 1. . #. &. ). +. .. /. 1. 1. . #. &. ). +. .. /. 1. 13. E6plain OOP Principles. E6plain the feat"res of 7ava =ang"age. !ompare and !ontrast 7ava with !. !ompare and !ontrast 7ava with !NN. E6plain !onstr"ctors with e6amples. E6plain the methods available "nder ?tring and ?tring A"ffer !lass. E6plain the ;ate !lass methods with e6amples. ;isc"ss in detail the access specifiers available in 7ava. E6plain the different visibility controls and also compare with each of them. Enit E6plain the concept of inheritance and its types. E6plain the concept of overriding with e6amples. What is dynamic binding? E6plain with e6ample. E6plain the "ses of reflection with e6amples. ;efine an interface. E6plain with e6ample. E6plain the methods "nder 8object9 class and 8class9 class. What is object cloning? E6plain deep copy and shallow copy with e6amples. E6plain static nested class and inner class with e6amples. With an e6ample e6plain pro6ies. E6plain the 2ethods s"pported in reflect pac,age. 'lso write a program to

implement the reflection of a partic"lar class details li,e constr"ctors% methods and fields with its modifiers.

11.

What is pro6y class? ;evelop a code for constr"cting a pro6y objects to trace a Enit #

binary search method with e6planations 1. . #. &. ). +. .. /. 1. E6plain the classes "nder ; shapes. E6plain event handling with e6amples. E6plain action event with an e6ample. What are the swing components. E6plain. ;escribe the 'W( event hierarchy. E6plain swing and 7Drame with a helloworld program. @ow 2odel <iew !ontroller design pattern is achieved? E6plain any five swing components with an e6ample program. ;isc"ss 2o"se =istener and 2o"se 2otion =istener. >ive an e6ample program. Enit & 1. E6plain generic classes and methods. . E6plain e6ception hierarchy. #. What are the advantages of >eneric Programming? &. E6plain the different ways to handle e6ceptions. ). @ow 7ava handle overflows and "nderflows? +. E6plain in details% the inheritance r"les for generic types. .. @ow generic methods and generic e6pressions are translated? Enit ) 1. E6plain the different states of a thread. . E6plain thread synchronization with e6amples. #. E6plain the algorithm "sed for thread sched"ling. &. ;escribe m"lti threading. ). E6plain ;eadloc,s. +. a) E6plain the following

.. 4i) ?tates of a thread with a neat diagram. 4ii) (hread priorities. /. Write a java application that ill"strate the "se of m"ltithreading. E6plain the same with sample inp"t

S-ar putea să vă placă și