You are on page 1of 12

Command

Description

driver.get("http://www.google.com"); To open an application driver.findElement(By.id("passwd id")); Finding Element using Id driver.findElement(By.name("passwd")); Finding Element using Name driver.findElement(By.!path("//inp"t#$id%&passwd id&'")); Finding Element using Xpath element.send(eys("some te!t"); To type some data element.clear(); clear thecontents of a text eld or textarea driver.findElement(By.!path("//select")); Selecting the value select.findElements(By.tag)ame("option")); Selecting the value select.deselect*ll(); This will deselect all O TIONs from the rst SE!E"T on the page select.selectBy+isi,le-e!t("Edam"); select the O TION withthe displayed text of #Edam$ findElement(By.id("s",mit")).clic.(); To clic% on &ny 'utton(!in% driver.switch-o().window("window)ame"); )oving from one window to another window driver.switch-o().frame("frame)ame"); swing from frame to frame *or into iframes+ driver.switch-o().frame("frame)ame./.child"); to access su'frames 'y separating the path with a dot, and you can specify the frame 'y itsindex toodriver.switch-o().alert(); .andling &lerts driver.navigate().to("http://www.e!ample.com"); To Navigate aeticular /0! driver.navigate().forward(); To Navigate Forward driver.navigate().,ac.(); To Navigate 1ac%word driver.close() "loses the current window driver.0"it() 2uits the driver and closes every associated windowdriver.switch1to1alert() Switches focus to an alert on the pagedriver.refresh() 0efreshes the current pagedriver.implicitly1wait(2/) &mount of time to wait driver.set1script1timeo"t(2/) The amount of time to wait driver.get1screenshot1as1file(3/4creenshots/foo.png3) The full path you wish to save your screenshot to driver.get1screenshot1as1,ase56() 3ets the screenshot of the current window as a 'ase45 encoded string which is useful in em'edded images in .T)!

Core 7ava 8*94


6-What are the principle concepts of OOPS?
There are four principle concepts upon which object oriented design and programming rest. They are: Abstraction Polymorphism nheritance !ncapsulation "i.e. easily remembered as A#P !$.

2.What is Abstraction? Abstraction refers to the act of representing essential features without including the bac%ground details or e&planations.

3.What is Encapsulation? !ncapsulation is a techni'ue used for hiding the properties and beha(iors of an object and allowing outside access only as appropriate. t pre(ents other objects from directly altering or accessing the properties or methods of the encapsulated object.

4.What is the difference between abstraction and encapsulation? Abstraction Abstraction Encapsulation is the deliverables of Abstraction. Encapsulation barely talks about grouping up your abstraction to suit the developer needs. solves the problem in the design side while Encapsulation is the mplementation.

!.What is

nheritance? nheritance is the process by which ob"ects of one class ac#uire the properties of ob"ects of another class. A class that is inherited is called a superclass. $he class that does the inheriting is called a subclass. nheritance is done by using the keyword e%tends. $he two most common reasons to use inheritance are& $o promote code reuse $o use polymorphism

'.What is (olymorphism? (olymorphism is briefly described as )one interface* many implementations.) (olymorphism is a characteristic of being able to assign a different meaning or usage to something in different conte%ts + specifically* to allow an entity such as a variable* a function* or an ob"ect to have more than one form.

,.-ow does .ava implement polymorphism? / nheritance* 0verloading and 0verriding are used to achieve (olymorphism in "ava1. (olymorphism manifests itself in .ava in the form of multiple methods having the same name. n some cases* multiple methods have the same name* but different formal argument lists /overloaded methods1. n other cases* multiple methods have the same name* same return type* and same formal argument list /overridden methods1.

2.E%plain the different forms of (olymorphism. $here are two types of polymorphism one is 3ompile time polymorphism and the other is run time polymorphism. 3ompile time polymorphism is method overloading. 4untime time polymorphism is done using inheritance and interface. 5ote& From a practical programming viewpoint, polymorphism manifests itself in three distinct forms in Java: 6ethod overloading 6ethod overriding through inheritance 6ethod overriding through the .ava interface

7.What is runtime polymorphism or dynamic method dispatch? n .ava* runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile+time. n this process* an overridden method is called through the reference variable of a superclass. $he determination of the method to be called is based on the ob"ect being referred to by the reference variable.

89.What is :ynamic ;inding? ;inding refers to the linking of a procedure call to the code to be e%ecuted in response to the call. :ynamic binding /also known as late binding1 means that the code associated with a given procedure call is not known until the time of the call at run+time. t is associated with polymorphism and inheritance.

88.What is method overloading? 6ethod 0verloading means to have two or more methods with same name in the same class with different arguments. $he benefit of method overloading is that it allows you to implement methods that support the same semantic operation but differ by argument number or type. 5ote& Overloaded methods MUST change the argument list Overloaded methods C ! change the return type Overloaded methods C ! change the access modifier Overloaded methods C ! declare new or "roader chec#ed e$ceptions method can "e overloaded in the same class or in a su"class

82.What is method overriding? 6ethod overriding occurs when sub class declares a method that has the same type arguments as a method declared by one of its superclass. $he key benefit of overriding is the ability to define behavior that<s specific to a particular subclass type. 5ote& The overriding method cannot have a more restrictive access modifier than the method "eing overridden %&$: 'ou can(t override a method mar#ed pu"lic and ma#e it protected)* 'ou cannot override a method mar#ed final 'ou cannot override a method mar#ed static

83.What are the differences between method overloading and method overriding?

Arguments 4eturn type E%ceptions Access )ust change *an change *an change *an change

0verloaded 6ethod

0verridden 6ethod )ust not change *an+t change e&cept for co(ariant returns *an reduce or eliminate. )ust not throw new or broader chec%ed e&ceptions )ust not ma%e more restricti(e "can be less restricti(e$

nvocation

,eference type determines which o(erloaded (ersion is selected. -appens at compile time.

Object type determines which method is selected. -appens at runtime.

84.3an overloaded methods be override too? =es* derived classes still can override the overloaded methods. (olymorphism can still happen. 3ompiler will not binding the method calls since it is overloaded* because it might be overridden now or in the future.

8!. s it possible to override the main method? 50* because main is a static method. A static method can>t be overridden in .ava. 8'.-ow to invoke a superclass version of an 0verridden method? $o invoke a superclass method that has been overridden in a subclass* you must either call the method directly through a superclass instance* or use the super prefi% in the subclass itself. ?rom the point of the view of the subclass* the super prefi% provides an e%plicit reference to the superclass> implementation of the method.

// From subclass super.overriddenMethod();


8,.What is super? super You can only go back one level. In the constructor, if you use super(), it must be the very first code, and you cannot access any is a keyword which is used to access the method or member variables from the superclass. f a method hides one of the member variables in its superclass* the method can refer to the hidden variable through the use of the super keyword. n the same way* if a method overrides one of the methods in its superclass* the method can invoke the overridden method through the use of the super keyword. 5ote& this.xxx variables or methods to compute its parameters.

82.-ow do you prevent a method from being overridden? $o prevent a specific method from being overridden in a subclass* use the final modifier on the method declaration* which means )this is the final implementation of this method)* the end of its inheritance hierarchy.

public final void exampleMethod() { // Method statements }


87.What is an nterface? An interface is a description of a set of methods that conforming implementing classes must have. 5ote& 'ou can(t mar# an interface as final* +nterface varia"les must "e static* n +nterface cannot e$tend anything "ut another interfaces* 29. =ou can<t instantiate an interface directly* but you can instantiate a class that implements an interface. 28.3an we create an ob"ect for an interface? =es* it is always necessary to create an ob"ect implementation for an interface. nterfaces cannot be instantiated in their own right* so you must write a class that implements the interface and fulfill all the methods defined in it. 22.:o interfaces have member variables? nterfaces may have member variables* but these are implicitly public, static, and final+ in other words* interfaces can declare only constants* not instance variables that are available to all implementations and may be used as key references for method arguments for e%ample. 23.What modifiers are allowed for methods in an nterface? 0nly public and abstract modifiers are allowed for methods in interfaces. 24.What is a marker interface? 6arker interfaces are those which do not declare any re#uired methods* but signify their compatibility with certain operations. $he java.io. eriali!able interface and "loneable are typical marker interfaces. $hese do not contain any methods* but classes must implement this interface in order to be seriali@ed and de+seriali@ed. 2!.What is an abstract class? Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared* but contains no implementation. 5ote& +f even a single method is a"stract, the whole class must "e declared a"stract* "stract classes may not "e instantiated, and re,uire su"classes to provide implementations for the a"stract methods*

'ou can(t mar# a class as "oth a"stract and final*

2'.3an we instantiate an abstract class? An abstract class can never be instantiated. ts sole purpose is to be e%tended /subclassed1. 2,.What are the differences between nterface and Abstract class?

Abstract 3lass An abstract class can pro(ide complete. default code and/or just the details that ha(e to be o(erridden. n case of abstract class. a class may e&tend only one abstract class. An abstract class can ha(e non#abstract methods. An abstract class can ha(e instance (ariables. An abstract class can ha(e any (isibility: public. pri(ate. protected. f we add a new method to an abstract class then we ha(e the option of pro(iding default implementation and therefore all the e&isting code might wor% properly. An abstract class can contain constructors . Abstract classes are fast.

nterfaces An interface cannot pro(ide any code at all.just the signature. A *lass may implement se(eral interfaces. All methods of an nterface are abstract. An nterface cannot ha(e instance (ariables. An nterface (isibility must be public "or$ none. f we add a new method to an nterface then we ha(e to trac% down all the implementations of the interface and define implementation for the new method. An nterface cannot contain constructors . nterfaces are slow as it re'uires e&tra indirection to find corresponding method in the actual class.

22.When should use abstract classes and when should use interfaces? Ase nterfaces whenB Ase Abstract 3lass whenB f various implementations are of the same kind and use common behavior or status then abstract class is better to use. When you want to provide a generali@ed form of abstraction and leave the implementation task with the inheriting subclass. Abstract classes are an e%cellent way to create planned inheritance hierarchies. $hey>re also a good choice for nonleaf classes in class hierarchies. 27.When you declare a method as abstract* can other nonabstract methods access it? =es* other nonabstract methods can access a method that you declare as abstract. 39.3an there be an abstract class with no abstract methods in it? =es* there can be an abstract class without abstract methods. 38. A constructor is a special method whose task is to initiali@e the ob"ect of its class. t is special because its name is the same as the class name. $hey do not have return types* not even void and therefore they cannot return values. $hey cannot be inherited* though a derived class can call the base class constructor. 3onstructor is invoked whenever an ob"ect of its associated class is created. 32.-ow does the .ava default constructor be provided? f a class defined by the code does not have any constructor* compiler will automatically provide one no+ parameter+constructor /default+constructor1 for the class in the byte code. $he access modifier /publicCprivateCetc.1 of the default constructor is the same as the class itself. 33.3an constructor be inherited? 5o* constructor cannot be inherited* though a derived class can call the base class constructor. 34.What are the differences between 3ontructors and 6ethods?

(urpose 6odifiers 4eturn $ype 5ame

3onstructors *reate an instance of a class *annot be abstract, final, native, static. or synchronized 2o return type. not e(en (oid Same name as the class "first letter is capitali3ed by con(ention$ ## usually a noun

6ethods 0roup 1a(a statements *an be abstract, final, native, static. or synchronized (oid or a (alid return type Any name e&cept the class. )ethod names begin with a lowercase letter by con(ention ## usually the name of an action

this

,efers to another constructor in the same ,efers to an instance of the owning class. class. f used. it must be the first line of the *annot be used by static methods. constructor *alls the constructor of the parent class. f used. must be the first line of the constructor *onstructors are not inherited *alls an o(erridden method in the parent class )ethods are inherited

super

nheritance

3!.-ow are this/1 and super/1 used with constructors? 3onstructors use this to refer to another constructor in the same class with a different parameter list. 3onstructors use super to invoke the superclass>s constructor. f a constructor uses super* it must use it in the first lineD otherwise* the compiler will complain. 3'.What are the differences between 3lass 6ethods and nstance 6ethods?

3lass 6ethods

nstance 6ethods nstance methods on the other hand re'uire an instance of the class to e&ist before they can be called. so an instance of a class needs to be created by using the new %eyword. nstance methods operate on specific instances of classes. nstance methods of the class can also not be called from within a class method unless they are being called on an instance of that class. nstance methods are not declared as static.

*lass methods are methods which are declared as static. The method can be called without creating an instance of the class

*lass methods can only operate on class members and not on instance members as class methods are unaware of instance members. *lass methods are methods which are declared as static. The method can be called without creating an instance of the class.

3,.-ow are this/1 and super/1 used with constructors? 3onstructors use this to refer to another constructor in the same class with a different parameter list. 3onstructors use super to invoke the superclass>s constructor. f a constructor uses super* it must use it in the first lineD otherwise* the compiler will complain. 32.What are Access Epecifiers? 0ne of the techni#ues in ob"ect+oriented programming is encapsulation. t concerns the hiding of data in a class and making this class available only through methods. .ava allows you to control access to classes* methods* and fields via so+called access specifiers.. 37.What are Access Epecifiers available in .ava? .ava offers four access specifiers* listed below in decreasing accessibility& (ublic (rotected :efault/no specifier1+ (rivate + private methods and fields can only be accessed within the same class to which the methods and fields belong. private methods and fields are not visible within subclasses and are not inherited by subclasses. f you do not set access to specific level* then such a class* method* or field will be accessible from inside the same package to which the class* method* or field belongs* but not from outside this package. + protected methods and fields can only be accessed within the same class to which the methods and fields belong* within its subclasses* and within classes of the same package. + pu"lic classes* methods* and fields can be accessed from everywhere.

Eituation Accessible to class from same pac%age? Accessible to class from different pac%age?

public yes

protected yes no. unless it is a subclass

default yes

private no

yes

no

no

49.What is final modifier? $he final modifier keyword makes that the programmer cannot change the value anymore. $he actual meaning depends on whether it is applied to a class* a variable* or a method. final final final Methods- final method cannot "e overridden "y su"classes* .aria"lesfinal varia"le cannot "e changed once it is initiali/ed* 3lasses+ A final class cannot have subclasses. $here are two reasons for marking a method as final& :isallowing subclasses to change the meaning of the method. ncreasing efficiency by allowing the compiler to turn calls to the method into inline .ava code. 42.What is static block? Etatic block which e%actly e%ecuted e%actly once when the class is first loaded into .F6. ;efore going to the main method the static block will e%ecute. 43.What are static variables? Fariables that have only one copy per class are known as static variables. $hey are not

attached to a particular instance of a class but rather belong to a class as a whole. $hey are declared by using the static keyword as a modifier.

static t#pe var$dentifier;

where* the name of the variable is var dentifier and its data type is specified by type. 5ote& Etatic variables that are not e%plicitly initiali@ed in the code are automatically initiali@ed with a default value. $he default value depends on the data type of the variables. 44.What is the difference between static and non+static variables? A static variable is associated with the class as a whole rather than with specific instances of a class. 5on+static variables take on uni#ue values with each ob"ect instance. 4!. 6ethods declared with the keyword static as modifier are called static methods or class methods. $hey are so called because they affect a class as a whole* not a particular instance of the class. Etatic methods are always invoked without reference to a particular instance of a class. 5ote&$he use of a static method suffers from the following restrictions& static method can only call other static methods* static method must only access static data* static method cannot reference to the current o"0ect using #eywords super or this* 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java code in one platform (eg Windows and can e!ecute the class in any other supported platform eg ("inu!#$olaris#etc . %. What is a J&'? J&' is Java &irtual 'achine which is a run time environment for the compiled java class files. (. )re J&'*s platform independent? J&'*s are not platform independent. J&'*s are platform specific run time implementation provided by the vendor. +. What is the difference between a J,- and a J&'? J,- is Java ,evelopment -it which is for development purpose and it includes e!ecution environment also. .ut J&' is purely a run time environment and hence you will not be able to compile your source files using a J&'. /. What is a pointer and does Java support pointers? Pointer is a reference handle to a memory location. 0mproper handling of pointers leads to memory lea1s and reliability issues hence Java doesn*t support the usage of pointers. 2. What is the base class of all classes? java.lan%.&bject 3. ,oes Java support multiple inheritance? Java doesn*t support multiple inheritance. 4. 0s Java a pure object oriented language? Java uses primitive data types and hence is not a pure object oriented language. 15. )re arrays primitive data types? 0n Java# )rrays are objects. 11. What is difference between Path and 6lasspath? Path and 6lasspath are operating system level environment variales. Path is used define where the system can find the e!ecutables(.e!e files and classpath is used to specify the location .class files. 12. What are local variables? "ocal varaiables are those which are declared within a bloc1 of code li1e methods. "ocal variables should be initialised before accessing them. 1%. What are instance variables? 0nstance variables are those which are defined at the class level. 0nstance variables need not be initiali7ed before using them as they are automatically initiali7ed to their default values. 1(. 8ow to define a constant variable in Java? 9he variable should be declared as static and final. $o only one copy of the variable e!ists for all instances of the class and the value can*t be changed also.static final int '$ ( ).*+; is an e!ample for constant. 1+. $hould a main( method be compulsorily declared in all java classes? :o not re;uired. main() method should be defined only if the source class is a java application. 1/. What is the return type of the main( method? Main() method doesn*t return anything hence declared void. 12. Why is the main( method declared static? main() method is called by the J&' even before the instantiation of the class hence it is declared as static. 13. What is the arguement of main( method? main() method accepts an array of $tring object as arguement. 14. 6an a main( method be overloaded? <es. <ou can have any number of main() methods with different method signature and implementation in the class.

25. 6an a main( method be declared final? <es. )ny inheriting class will not be able to have it*s own default main() method. 21. ,oes the order of public and static declaration matter in main( method? :o. 0t doesn*t matter but void should always come before main(). 22. 6an a source file contain more than one class declaration? <es a single source file can contain any number of 6lass declarations but only one of the class can be declared as public. 2%. What is a pac1age? Pac1age is a collection of related classes and interfaces. pac1age declaration should be first statement in a java class. 2(. Which pac1age is imported by default? java.lan% pac,a%e is imported by default even without a pac1age declaration. 2+. 6an a class declared as private be accessed outside it*s pac1age? :ot possible. 2/. 6an a class be declared as protected? ) class can*t be declared as protected. only methods can be declared as protected. 22. What is the access scope of a protected method? ) protected method can be accessed by the classes within the same pac1age or by the subclasses of the class in any pac1age. 23. What is the purpose of declaring a variable as final? ) final variable*s value can*t be changed. final variables should be initiali7ed before using them. 24. What is the impact of declaring a method as final? ) method declared as final can*t be overridden. ) sub=class can*t have the same method signature with a different implementation. %5. 0 don*t want my class to be inherited by any other class. What should i do? <ou should declared your class as final. .ut you can*t define your class as final# if it is an abstract class. ) class declared as final can*t be e!tended by any other class. %1. 6an you give few e!amples of final classes defined in Java )P0? java.lan%. trin%, java.lan%.Math are final classes. %2. 8ow is final different from finally and finali7e( ? final is a modifier which can be applied to a class or a method or a variable. final class can*t be inherited# final method can*t be overridden and final variable can*t be changed. finally is an e!ception handling code section which gets e!ecuted whether an e!ception is raised or not by the try bloc1 code segment. finali!e() is a method of >bject class which will be e!ecuted by the J&' just before garbage collecting object to give a final chance for resource releasing activity. %%. 6an a class be declared as static? We can not declare top level class as static# but only inner class can be declared static.

public class -est { static class $nner"lass { public static void $nnerMethod() { #stem.out.println(. tatic $nner "lass/.); } } public static void main( trin% ar%s01) { -est.$nner"lass.$nnerMethod(); } } //output2 tatic $nner "lass/

%(. When will you define a method as static? When a method needs to be accessed even before the creation of the object of the class then we should declare the method as static. %+. What are the restriction imposed on a static method or a static bloc1 of code? ) static method should not refer to instance variables without creating an instance and cannot use ?this? operator to refer the instance. %/. 0 want to print ?8ello? even before main( is e!ecuted. 8ow will you acheive that? Print the statement inside a static bloc1 of code. $tatic bloc1s get e!ecuted when the class gets loaded into the memory and even before the creation of

an object. 8ence it will be e!ecuted before the main() method. )nd it will be e!ecuted only once. %2. What is the importance of static variable? static variables are class level variables where all objects of the class refer to the same variable. 0f one object changes the value then the change gets reflected in all the objects. %3. 6an we declare a static variable inside a method? $tatic varaibles are class level variables and they can*t be declared inside a method. 0f declared# the class will not compile. %4. What is an )bstract 6lass and what is it*s purpose? ) 6lass which doesn*t provide complete implementation is defined as an abstract class. )bstract classes enforce abstraction. (5. 6an a abstract class be declared final? :ot possible. )n abstract class without being inherited is of no use and hence will result in compile time error. (1. What is use of a abstract variable? &ariables can*t be declared as abstract. only classes and methods can be declared as abstract. (2. 6an you create an object of an abstract class? :ot possible. )bstract classes can*t be instantiated. (%. 6an a abstract class be defined without any abstract methods? <es it*s possible. 9his is basically to avoid instance creation of the class. ((. 6lass 6 implements 0nterface 0 containing method m1 and m2 declarations. 6lass 6 has provided implementation for method m2. 6an i create an object of 6lass 6? :o not possible. "lass " should provide implementation for all the methods in the $nterface $. $ince "lass " didn*t provide implementation for m* method# it has to be declared as abstract. )bstract classes can*t be instantiated. (+. 6an a method inside a 0nterface be declared as final? :o not possible. ,oing so will result in compilation error. public and abstract are the only applicable modifiers for method declaration in an interface. (/. 6an an 0nterface implement another 0nterface? 0ntefaces doesn*t provide implementation hence a interface cannot implement another interface. (2. 6an an 0nterface e!tend another 0nterface? <es an 0nterface can inherit another 0nterface# for that matter an 0nterface can e!tend more than one 0nterface. (3. 6an a 6lass e!tend more than one 6lass? :ot possible. ) 6lass can e!tend only one class but can implement any number of 0nterfaces. (4. Why is an 0nterface be able to e!tend more than one 0nterface but a 6lass can*t e!tend more than one 6lass? .asically Java doesn*t allow multiple inheritance# so a 6lass is restricted to e!tend only one 6lass. .ut an 0nterface is a pure abstraction model and doesn*t have inheritance hierarchy li1e classes(do remember that the base class of all classes is >bject . $o an 0nterface is allowed to e!tend more than one 0nterface. +5. 6an an 0nterface be final? :ot possible. ,oing so so will result in compilation error. +1. 6an a class be defined inside an 0nterface? <es it*s possible. +2. 6an an 0nterface be defined inside a class? <es it*s possible. +%. What is a 'ar1er 0nterface? )n 0nterface which doesn*t have any declaration inside but still enforces a mechanism. +(. Which object oriented 6oncept is achieved by using overloading and overriding? Polymorphism. ++. Why does Java not support operator overloading? >perator overloading ma1es the code very difficult to read and maintain. 9o maintain code simplicity# Java doesn*t support operator overloading. +/. 6an we define private and protected modifiers for variables in interfaces? :o. +2. What is @!ternali7able? @!ternali7able is an 0nterface that e!tends $eriali7able 0nterface. )nd sends data into $treams in 6ompressed Aormat. 0t has two methods# 3rite4xternal(&bject&uput out) and read4xternal(&bject$nput in) +3. What modifiers are allowed for methods in an 0nterface? >nly public and abstract modifiers are allowed for methods in interfaces. +4. What is a local# member and a class variable? &ariables declared within a method are ?local? variables. &ariables declared within the class i.e not within any methods are ?member? variables (global variables . &ariables declared within the class i.e not within any methods and are defined as ?static? are class variables. /5. What is an abstract method? )n abstract method is a method whose implementation is deferred to a subclass. /1. What value does read( return when it has reached the end of a file? 9he

read() method returns 5* when it has reached the end of a file. /2. 6an a .yte object be cast to a double value? :o# an object cannot be cast to a primitive value. /%. What is the difference between a static and a non=static inner class? ) non=static inner class may have object instances that are associated with instances of the class*s outer class. ) static inner class does not have any object instances. /(. What is an object*s loc1 and which object*s have loc1s? )n object*s loc1 is a mechanism that is used by multiple threads to obtain synchroni7ed access to the object. ) thread may e!ecute a synchroni7ed method of an object only after it has ac;uired the object*s loc1. )ll objects and classes have loc1s. ) class*s loc1 is ac;uired on the class*s 6lass object. /+. What is the B operator? 0t is referred to as the modulo or remainder operator. 0t returns the remainder of dividing the first operand by the second operand. //. When can an object reference be cast to an interface reference? )n object reference be cast to an interface reference when the object implements the referenced interface. /2. Which class is e!tended by all other classes? 9he >bject class is e!tended by all other classes. /3. Which non=Cnicode letter characters may be used as the first character of an identifier? 9he non=Cnicode letter characters 6 and 7 may appear as the first character of an identifier /4. What restrictions are placed on method overloading? 9wo methods may not have the same name and argument list but different return types. 25. What is casting? 9here are two types of casting# casting between primitive numeric types and casting between object references. 6asting between numeric types is used to convert larger values# such as double values# to smaller values# such as byte values. 6asting between object references is used to refer to an object by a compatible class# interface# or array type reference. 21. What is the return type of a program*s main( method? void. 22. 0f a variable is declared as private# where may the variable be accessed? ) private variable may only be accessed within the class in which it is declared. 2%. What do you understand by private# protected and public? 9hese are accessibility modifiers. 'rivate is the most restrictive# while public is the least restrictive. 9here is no real difference between protected and the default type (also 1nown as pac1age protected within the conte!t of the same pac1age# however the protected 1eyword allows visibility to a derived class in a different pac1age. 2(. What is ,owncasting ? ,owncasting is the casting from a general to a more specific type# i.e. casting down the hierarchy 2+. What modifiers may be used with an inner class that is a member of an outer class? ) (non=local inner class may be declared as public# protected# private# static# final# or abstract. 2/. 8ow many bits are used to represent Cnicode# )$600# C9A=1/# and C9A=3 characters? Cnicode re;uires 1/ bits and )$600 re;uire 2 bits )lthough the )$600 character set uses only 2 bits# it is usually represented as 3 bits. C9A=3 represents characters using 3# 1/# and 13 bit patterns. C9A=1/ uses 1/=bit and larger bit patterns. 22. What restrictions are placed on the location of a pac1age statement within a source code file? ) pac1age statement must appear as the first line in a source code file (e!cluding blan1 lines and comments . 23. What is a native method? ) native method is a method that is implemented in a language other than Java. 24. What are order of precedence and associativity# and how are they used? >rder of precedence determines the order in which operators are evaluated in e!pressions. )ssociatity determines whether an e!pression is evaluated left=to=right or right=to=left. 35. 6an an anonymous class be declared as implementing an interface and e!tending a class? )n anonymous class may implement an interface or e!tend a superclass# but may not be declared to do both. 31. What is the range of the char type? 9he range of the char type is 5 to 21/ = 1 (i.e. 5 to /++%+. 32. What is the range of the short type? 9he range of the short type is =(21+ to 21+ = 1. (i.e. =%2#2/3 to %2#2/2 3%. Why isn*t there operator overloading? .ecause 6DD has proven by e!ample that operator overloading ma1es code almost impossible to maintain. 3(. What does it mean that a method or field is ?static?? $tatic variables and methods are instantiated only once per class. 0n other words they are class variables# not instance variables. 0f you change the

value of a static variable in a particular object# the value of that variable changes for all instances of that class. $tatic methods can be referenced with the name of the class rather than the name of a particular object of the class (though that wor1s too . 9hat*s how library methods li1e #stem.out.println() wor1. out is a static field in the java.lan%. #stem class. 3+. 0s null a 1eyword? 9he null value is not a 1eyword. 3/. Which characters may be used as the second character of an identifier# but not as the first character of an identifier? 9he digits 5 through 4 may not be used as the first character of an identifier but they may be used after the first character of an identifier. 32. 0s the ternary operator written ! E y ? 7 or ! ? y E 7 ? 0t is written x 8 # 2 !. 33. 8ow is rounding performed under integer division? 9he fractional part of the result is truncated. 9his is 1nown as rounding toward 7ero. 34. 0f a class is declared without any access modifiers# where may the class be accessed? ) class that is declared without any access modifiers is said to have pac1age access. 9his means that the class can only be accessed by other classes and interfaces that are defined within the same pac1age. 45. ,oes a class inherit the constructors of its superclass? ) class does not inherit constructors from any of its superclasses. 41. :ame the eight primitive Java types. 9he eight primitive types are byte# char# short# int# long# float# double# and boolean. 42. What restrictions are placed on the values of each case of a switch statement? ,uring compilation# the values of each case of a s3itch statement must evaluate to a value that can be promoted to an int value. 4%. What is the difference between a while statement and a do while statement? ) 3hile statement chec1s at the beginning of a loop to see whether the ne!t loop iteration should occur. ) do 3hile statement chec1s at the end of a loop to see whether the ne!t iteration of a loop should occur. 9he do 3hilestatement will always e!ecute the body of a loop at least once. 4(. What modifiers can be used with a local inner class? ) local inner class may be final or abstract. 4+. When does the compiler supply a default constructor for a class? 9he compiler supplies a default constructor for a class if no other constructors are provided. 4/. 0f a method is declared as protected# where may the method be accessed? ) protected method may only be accessed by classes or interfaces of the same pac1age or by subclasses of the class in which it is declared. 42. What are the legal operands of the instanceof operator? 9he left operand is an object reference or null value and the right operand is a class# interface# or array type. 43. )re true and false 1eywords? 9he values true and false are not 1eywords. 44. What happens when you add a double value to a $tring? 9he result is a $tring object. 155. What is the diffrence between inner class and nested class? When a class is defined within a scope od another class# then it becomes inner class. 0f the access modifier of the inner class is static# then it becomes nested class. 151. 6an an abstract class be final? )n abstract class may not be declared as final. 152. What is numeric promotion? :umeric promotion is the conversion of a smaller numeric type to a larger numeric type# so that integer and floating=point operations may ta1e place. 0n numerical promotion# byte# char# and short values are converted to int values. 9he int values are also converted to long values# if necessary. 9he long and float values are converted to double values# as re;uired. 15%. What is the difference between a public and a non=public class? ) public class may be accessed outside of its pac1age. ) non=public class may not be accessed outside of its pac1age. 15(. 9o what value is a variable of the boolean type automatically initiali7ed? 9he default value of the boolean type is false. 15+. What is the difference between the prefi! and postfi! forms of the DD operator? 9he prefi! form performs the increment operation and returns the value of the increment operation. 9he postfi! form returns the current value all of the e!pression and then performs the increment operation on that value. 15/. What restrictions are placed on method overriding? >verridden methods must have the same name# argument list# and return type. 9he overriding method may not limit the access of the method it overrides. 9he overriding method may not throw any e!ceptions that may

not be thrown by the overridden method. 152. What is a Java pac1age and how is it used? ) Java pac1age is a naming conte!t for classes and interfaces. ) pac1age is used to create a separate name space for groups of classes and interfaces. Pac1ages are also used to organi7e related classes and interfaces into a single )P0 unit and to control accessibility to these classes and interfaces. 153. What modifiers may be used with a top=level class? ) top=level class may be public# abstract# or final. 11+. What is constructor chaining and how is it achieved in Java ? ) child object constructor always first needs to construct its parent (which in turn calls its parent constructor. . 0n Java it is done via an implicit call to the no=args constructor as the first statement. 11/. What is the difference between the .oolean F operator and the FF operator? 0f an e!pression involving the .oolean F operator is evaluated# both operands are evaluated. 9hen the F operator is applied to the operand. When an e!pression involving the FF operator is evaluated# the first operand is evaluated. 0f the first operand returns a value of true then the second operand is evaluated. 9he FF operator is then applied to the first and second operands. 0f the first operand evaluates to false# the evaluation of the second operand is s1ipped. 112. Which Java operator is right associative? 9he G operator is right associative. 113. 6an a double value be cast to a byte? <es# a double value can be cast to a byte. 114. What is the difference between a brea1 statement and a continue statement? ) brea, statement results in the termination of the statement to which it applies (switch# for# do# or while . ) continue statement is used to end the current loop iteration and return control to the loop statement. 125. 6an a for statement loop indefinitely? <es# a for statement can loop indefinitely. Aor e!ample# consider the followingE for(;;); Can there be an abstract class with no abstract methods in it? Can an Interface be final? Can an Interface have an inner class? - Yes. - No public interface abc { static int i(9; void dd(); class a* { a*() { int j; #stem.out.println(.inside.); }; public static void main( trin% a*01) { #stem.out.println(.in interfia.); } } } Can we define private and protected modifiers for variables in interfaces? What is Externalizable? What modifiers are allowed for methods in an Interface? What is a local, member and a class variable? What are the different identifier states of a hread? What are some alternatives to inheritance? Wh! isn"t there operator overloadin#? What does it mean that a method or field is $static$? %ow do I convert a n&meric I' address li(e )*+.),.*-..* into a hostname li(e /ava.s&n.com? - 0tatic variables and methods are instantiated onl! once per class. In other words the! are class variables, not instance variables. If !o& chan#e the val&e of a static variable in a partic&lar ob/ect, the val&e of that variable chan#es for all instances of that class. 0tatic methods can be referenced with the name of the class rather than the name of a partic&lar ob/ect of the class 1tho&#h that wor(s too2. hat"s how librar! methods li(e 0!stem.o&t.println12 wor(. o&t is a static field in the /ava.lan#.0!stem class. - 3eca&se C44 has proven b! example that operator overloadin# ma(es code almost impossible to maintain. In fact there ver! nearl! wasn"t even method overloadin# in 5ava, b&t it was tho&#ht that this was too &sef&l for some ver! basic methods li(e print12. Note that some of the classes li(e 6ata7&tp&t0tream have &noverloaded methods li(e writeInt12 and write3!te12. 6ele#ation is an alternative to inheritance. 6ele#ation means that !o& incl&de an instance of another class as an instance variable, and forward messa#es to the instance. It is often safer than inheritance beca&se it forces !o& to thin( abo&t each messa#e !o& forward, beca&se the instance is of a (nown class, rather than a new class, and beca&se it doesn"t force !o& to accept all the methods of the s&per class8 !o& can provide onl! the methods that reall! ma(e sense. 7n the other hand, it ma(es !o& write more code, and it is harder to re-&se 1beca&se it is not a s&bclass2. he different identifiers of a hread are8 9 - 9&nnin# or r&nnable thread, 0 0&spended thread, CW - hread waitin# on a condition variable, :W - hread waitin# on a monitor loc(, :0 - hread s&spended waitin# on a monitor loc( -

;ariables declared within a method are $local$ variables. ;ariables declared within the class i.e not within an! methods are $member$ variables 1#lobal variables2. ;ariables declared within the class i.e not within an! methods and are defined as $static$ are class variables - 7nl! p&blic and abstract modifiers are allowed for methods in interfaces. - Externalizable is an Interface that extends 0erializable Interface. <nd sends data into 0treams in Compressed =ormat. It has two methods, writeExternal17b/ect7&p&t o&t2 and readExternal17b/ectInp&t in2 trin% hostname ( $net:ddress.%et;#<ame(.*=).*>.=?.@=.).%etAost<ame(); 6ifference between 59E>5;:>56?? Wh! do threads bloc( on I>7? What is s!nchronization and wh! is it important? Is n&ll a (e!word? Which characters ma! be &sed as the second character of an identifier,b&t not as the first character of an identifier? What modifiers ma! be &sed with an inner class that is a member of an o&ter class? %ow man! bits are &sed to represent @nicode, <0CII, @ =-)A, and @ =-, characters? What are wrapped classes? What restrictions are placed on the location of a pac(a#e statement within a so&rce code file? What is the difference between preemptive sched&lin# and time slicin#? What is a native method? What are order of precedence and associativit!, and how are the! &sed? What is the catch or declare r&le for method declarations? Can an anon!mo&s class be declared as implementin# an interface and extendin# a class? What is the ran#e of the char t!pe? - he ran#e of the char t!pe is B to +C)A - ). - <n anon!mo&s class ma! implement an interface or extend a s&perclass, b&t ma! not be declared to do both. - If a chec(ed exception ma! be thrown within the bod! of a method, the method m&st either catch the exception or declare it in its throws cla&se. - 7rder of precedence determines the order in which operators are eval&ated in expressions. <ssociatit! determines whether an expression is eval&ated left-tori#ht or ri#ht-to-left - < native method is a method that is implemented in a lan#&a#e other than 5ava. - @nder preemptive sched&lin#, the hi#hest priorit! tas( exec&tes &ntil it enters the waitin# or dead states or a hi#her priorit! tas( comes into existence. @nder time slicin#, a tas( exec&tes for a predefined slice of time and then reenters the pool of read! tas(s. he sched&ler then determines which tas( sho&ld exec&te next, based on priorit! and other factors. - < pac(a#e statement m&st appear as the first line in a so&rce code file 1excl&din# blan( lines and comments2. Wrapped classes are classes that allow primitive t!pes to be accessed as ob/ects. @nicode reD&ires )A bits and <0CII reD&ire - bits. <ltho&#h the <0CII character set &ses onl! - bits, it is &s&all! represented as , bits. @ =-, represents characters &sin# ,, )A, and ), bit patterns. @ =-)A &ses )A-bit and lar#er bit patterns. - < 1non-local2 inner class ma! be declared as p&blic, protected, private, static, final, or abstract. he di#its B thro&#h * ma! not be &sed as the first character of an identifier b&t the! ma! be &sed after the first character of an identifier. - he n&ll val&e is not a (e!word. - With respect to m&ltithreadin#, s!nchronization is the capabilit! to control the access of m&ltiple threads to shared reso&rces. Witho&t s!nchronization, it is possible for one thread to modif! a shared ob/ect while another thread is in the process of &sin# or &pdatin# that ob/ect"s val&e. his often leads to si#nificant errors. - hreads bloc( on i>o 1that is enters the waitin# state2 so that other threads ma! exec&te while the I>7 operation is performed.

What is 3onstructor? =ou see that something in your design will change fre#uently. f various implementations only share method signatures then it is better to use nterfaces. you need some classes to use some methods which you don>t want to be included in the class* then you go for the interface* which makes it easy to "ust implement and make use of the methods defined in the interface. 3an we instantiate an interface?

+ 5o + =es What are static methods? 8.What are the uses of final method?

focuses on the outside view of an o'7ect *i-e- the interface+ Encaps"lation *information hiding+ prevents clients from seeing it8s inside view, where the 'ehavior of the a'straction is implemented-

You might also like