26
https://www.certification-questions.com/ 1Z0-809 PDF Oracle 1Z0-809 PDF is available. Enrolling now you will get access to 340 unique 1Z0-809 certification questions at: https://www.certification-questions.com/java8-free-pdf-download/1Z0-809-pdf.html This is a sample demo for 1Z0-809: Q1. Consider the following class. 1. public final class Program { 2. 3. final private String name; 4. 5. Program (String name){ 6. this.name = name; 7. 8. getName(); 9. } 10. 11. //code here 12. } Which of the following code will make an instance of this class immutable. A. public String getName(){return name;} B. public String getName(String value){ name=value; return value;} C. private String getName(){return name+"a";} D. public final String getName(){return name+="a";} E. All of Above.

1z0-809 pdf

Embed Size (px)

Citation preview

Page 1: 1z0-809 pdf

https://www.certification-questions.com/

1Z0-809PDF

Oracle 1Z0-809 PDF is available.

Enrolling now you will get access to 340 unique 1Z0-809 certification questions at: https://www.certification-questions.com/java8-free-pdf-download/1Z0-809-pdf.html

This is a sample demo for 1Z0-809:

Q1.Considerthefollowingclass.

1. publicfinalclassProgram{2. 3. finalprivateStringname;4. 5. Program(Stringname){6. this.name=name;7. 8. getName();9. }10. 11. //codehere 12. }

Whichofthefollowingcodewillmakeaninstanceofthisclassimmutable.

A. publicStringgetName(){returnname;}

B. publicStringgetName(Stringvalue){name=value;returnvalue;}

C. privateStringgetName(){returnname+"a";}

D. publicfinalStringgetName(){returnname+="a";}

E. AllofAbove.

Page 2: 1z0-809 pdf

https://www.certification-questions.com/

OptionA,Carecorrect.

OptionBandDhaveacompileerrorsincenamevariableisfinal.

OptionCisprivateanddoesn'tchangethenamevalue.

OptionAispublicanddoesn'tchangethenamevalue.

Examobjective:EncapsulationandSubclassing-Makingclassesimmutable.

OracleReference:https://docs.oracle.com/javase/tutorial/essential/concurrency/imstrat.html

Page 3: 1z0-809 pdf

https://www.certification-questions.com/

Q2.Considerthefollowingcode:

1. classSuperClass{2. protectedvoidmethod1(){3. System.out.print("MSuperC");4. }5. }6. 7. classSubClassextendsSuperClass{8. privatevoidmethod1(){9. System.out.print("MSubC");10. }11. 12. publicstaticvoidmain(String[]args){13. SubClasssc=newSubClass();14. sc.method1();15. }16. }

Whatwillbetheresult?

F. MSubC.

G. MSuperC.

H. MSuperCMSubC.

I. Compilationfails.

Noneofabove.

OptionDiscorrect.

Thecodefailstocompileatline8,cannotreducethevisibilityoftheinheritedmethodfromSuperClass.

Examobjective:EncapsulationandSubclassing-CreatinganduseJavasubclasses.

OracleReference:https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html

Page 4: 1z0-809 pdf

https://www.certification-questions.com/

Q3.Giventhefollowingclass:

1. publicclassTest{2. publicstaticvoidmain(Stringargs[]){3. //CodeHere4. Threadthread=newThread(r);5. thread.start();6. }7. }

WhichofthefollowinglineswillgiveavalidThreadcreation:

A. Threadr=()->System.out.println("Running");

B. Runr=()->System.out.println("Running");

C. Runnabler=()->System.out.println("Running");

D. Executabler=()->System.out.println("Running");

E. NoneOfAbove

OptionCiscorrect.

OptionA,B,andDareincorrecttheyarenotfunctionalinterface,soCistheonlyvalidoption.

Examobjective:Concurrency-CreatingworkerthreadsusingRunnableandCallable.

OracleReference:https://docs.oracle.com/javase/tutorial/essential/concurrency/

Page 5: 1z0-809 pdf

https://www.certification-questions.com/

Q4whichofthefollowingdatabaseurlarecorrect:

A. jdbc:mysql://localhost:3306

B. jdbc:mysql://localhost:3306/sample

C. jdbc:mysql://localhost:3306/sample/user=root?password=secret

D. jdbc:mysql://localhost:3306/sample?user=root&password=secret

E. All

OptionA,BandDarecorrect.

Thecorrecturlformatisthefollowing:

jdbc:mysql://[host][,failoverhost...]

[:port]/[database]

[?propertyName1][=propertyValue1]

[&propertyName2][=propertyValue2]...

SoCisincorrectandA,BandDarecorrect.

Examobjective:DatabaseApplicationswithJDBC-ConnectingtoadatabasebyusingaJDBCdriver.

OracleReference:https://docs.oracle.com/javase/tutorial/jdbc/overview/

Page 6: 1z0-809 pdf

https://www.certification-questions.com/

Q5.Giventhefollowingcode:

1. publicclassProgram{2. 3. publicstaticvoidmain(Stringargs[])throwsIOException{4. Consolec=System.console();5. inti=(int)c.readLine("Entervalue:");6. for(intj=0;j<i;j++){7. c.format("%2d",j);8. }9. }10. }

Whatwillbetheresultenteringthevalues5?

F. 12345

A. 01234

B. 02468

C. Thecodewillnotcompilebecauseofline5.

D. UnhandledexceptiontypeNumberFormatExceptionalline7.

OptionDiscorrect.

Themethodsignature"intreadLine(Stringfmt,Object...args)"doesn'texist,

therightmethodreturnaStringsoline5willgiveacompileerrorandoptionDisright.

Examobjective:I/OFundamentals-Readandwritedatafromtheconsole

OracleReference:https://docs.oracle.com/javase/tutorial/essential/io/cl.html

Page 7: 1z0-809 pdf

https://www.certification-questions.com/

Q6.Given

11. classSingleton{12. privateintcount=0;13. privateSingleton(){};14. publicstaticfinalSingletongetInstance(){returnnewSingleton();};15. publicvoidadd(inti){count+=i;};16. publicintgetCount(){returncount;};17. }18. 19. publicclassProgram{20. publicstaticvoidmain(String[]args){21. Singletons1=Singleton.getInstance();22. s1.add(3);23. Singletons2=Singleton.getInstance();24. s2.add(2);25. Singletons3=Singleton.getInstance();26. s2.add(1);27. System.out.println(s1.getCount()+s2.getCount()+s3.getCount());28. }29. }

Whatwillbetheresult?

A. 18

B. 7

C. 6

D. Thecodewillnotcompile.

E. Noneofabove

OptionCiscorrect.

Theclass"Singleton"isnotarealsingletonclass,infactateachmethodinvocation"getInstance()"anewobjectiscreated,andsos1,s2,s3countinstancevariableare3,2,1andthenoptionCiscorrect.

Examobjective:JavaClassDesign-Createandusesingletonclassesandimmutableclasses

OracleReference:https://docs.oracle.com/javase/tutorial/essential/concurrency/imstrat.html

Page 8: 1z0-809 pdf

https://www.certification-questions.com/

Q7.Given

1. publicclassProgram{2. 3. publicstaticvoidmain(String[]args){4. 5. List<Integer>list=Arrays.asList(4,6,12,66,3);6. 7. Strings=list.stream().map(i->{8. return""+(i+1);9. }).reduce("",String::concat);10. 11. System.out.println(s);12. }13. }

Whatwillbetheresult?

A. 4612663

B. 5713674

C. 3661264

D. Thecodewillnotcompilebecauseofline7.

E. UnhandledexceptiontypeNumberFormatExceptionalline8.

OptionBiscorrect.

TheProgramisapplyingamapfunctiontothestreamgeneratedfromlist.ForeachIntegerelement"i"thefunctionreturnanewStringwithvaluei+1.ThestreamisthenreducedtoaStringbytheconcatenationfunction"String::concat".SoOptionBiscorrect,andA,C,D,Eareincorrect.

Examobjective:CollectionsStreams,andFilters-Iteratingthroughacollectionusinglambdasyntax

OracleReference:https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html

Page 9: 1z0-809 pdf

https://www.certification-questions.com/

Q8.WhichofthefollowingarecorrectoverrideofObjectclass

I. publicinthashCode();II. publicStringtoString();III. publicbooleanequals(Objectobj);IV. publicClassgetClass();

A. I,II,III,IV.

B. I,II,III.

C. I,II.

D. III,IV.

E. All.

OptionBiscorrect.

TheObjectclasshasallthemethodsignaturespecifiedabovesotheoverrideispossibleonalloptionslessIVbecauseisdeclaredfinalinObjectclass,soBiscorrect.

Examobjective:JavaClassDesign-OverridehashCode,equals,andtoStringmethodsfromObjectclass

OracleReference:https://docs.oracle.com/javase/tutorial/java/IandI/objectclass.html

Page 10: 1z0-809 pdf

https://www.certification-questions.com/

Q9.Given

1. publicclassTest{2. publicstatic<T>intcount(T[]array,Telem){3. intcount=0;4. for(Te:array)5. if(e.compareTo(elem)>0)++count;6. 7. returncount;8. }9. publicstaticvoidmain(String[]args){10. Integer[]a={1,2,3,4,5};11. intn=Test.<Integer>count(a,3);12. System.out.println(n);13. }14. }

whatwillbetheresult?

A. 2

B. 3

C. Thecodewillnotcompilebecauseofline5.

D. Anexceptionisthrown.

E. NoneofAbove.

OptionCiscorrect.

Ciscorrectbecausethevariable"e"isageneric"T"typesothecompilehasnoknowledgeofmethod"compareTo",tomakeitcompileline2needtobechangedin:

publicstatic<TextendsComparable<T>>intcount(T[]array,Telem){

Examobjective:CollectionsandGenerics-Creatingacustomgenericclass

OracleReference:https://docs.oracle.com/javase/tutorial/java/generics/methods.html

Page 11: 1z0-809 pdf

https://www.certification-questions.com/

Q10.Given

1. publicclassProgram{2. publicstaticvoidmain(String[]args){3. 4. Threadth=newThread(newRunnable(){ 5. 6. static{7. System.out.println("initial");8. }9. 10. @Override11. publicvoidrun(){12. System.out.println("start");13. }14. });15. 16. th.start();17. }18. }

Whatwillbetheresult?

A. startinitial

B. initialstart

C. initial

D. Aruntimeexceptionisthrown.

E. Thecodewillnotcompilebecauseofline6.

OptionEiscorrect.

Becauseyoucannotdeclarestaticinitializersinananonymousclass,thecompilationfailatline6,soEiscorrectandA,B,C,Dincorrect.

Examobjective:InterfacesandLambdaExpressions-Anonymousinnerclasses

OracleReference:https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html

Page 12: 1z0-809 pdf

https://www.certification-questions.com/

Q11.Considerthefollowingclass.

1. finalclassA{2. privateStrings;3. publicA(Strings){4. this.s=s;5. }6. publicStringtoString(){returns;};7. publicvoidsetA(Stringa){this.s+=a;};8. }9. 10. publicfinalclassImmutable{11. privatefinalAa;12. publicImmutable(Aa){13. this.a=a;14. }15. publicStringtoString(){returna.toString();};16. publicstaticvoidmain(String[]args){17. 18. Aa=newA("Bye");19. Immutableim=newImmutable(a);20. System.out.print(im);21. 22. a.setA("bye");23. System.out.print(a);24. }25. }

Whatwillbetheresult?

A. Byebye

B. ByeBye

C. ByeByebye

D. Compilationfail

E. NoneofAbove

OptionBiscorrect.

Theobject"im"isnotreallyanimmutableobject.TheclassDon'tprovide"setter"methods,fieldisfinalandprivate,don'tallowsubclassestooverridemethods,unfortunatelyinconstructurObjectaismutableandpassbyreferencewithoutmakeaprotectioncopyoftheobject.

Examobjective:EncapsulationandSubclassing-Makingclassesimmutable.

OracleReference:https://docs.oracle.com/javase/tutorial/essential/concurrency/imstrat.html

Page 13: 1z0-809 pdf

https://www.certification-questions.com/

Q12.Given

1. //CodeHere2. @Override3. publicvoidrun(){4. for(inti=0;i<10;i++)5. System.out.print(i);6. }7. }8. 9. publicclassTest{10. publicstaticvoidmain(Stringargs[]){11. Taskt=newTask();12. Threadthread=newThread(t);13. thread.start();14. }15. }

Whichofthefollowinglineswillgivetheresult:

0123456789

A. classTaskextendsRunnable{

B. classTaskimplementsRunnable{

C. classTaskimplementsThread{

D. classTaskextendsThread{

E. NoneOfAbove

OptionBiscorrect.

WecancreateathreadbypassinganimplementationofRunnabletoaThreadconstructor,

sotheonlycorrectoptionisB

Examobjective:Concurrency-CreatingworkerthreadsusingRunnableandCallable.

OracleReference:https://docs.oracle.com/javase/tutorial/essential/concurrency/

Page 14: 1z0-809 pdf

https://www.certification-questions.com/

Q13.Given

1. publicclassProgram{2. 3. publicstaticvoidmain(String[]args){4. 5. Callable<String>c=newCallable<String>(){6. @Override7. publicStringcall()throwsException{8. Strings="";9. for(inti=0;i<10;i++){s+=i;}10. returns;11. }12. };13. 14. ExecutorServiceexecutor=Executors.newSingleThreadExecutor();15. Future<String>future=executor.submit(c);16. try{17. Stringresult=future.wait();18. System.out.println(result);19. }catch(ExecutionExceptione){20. e.printStackTrace();21. }22. }23. }

Whatwillbetheresult?

A. 0123456789

B. 12345678910

C. UnhandledexceptiontypeInterruptedExceptionalline17

D. Thecodewillnotcompilebecauseofline5.

E. Thecodewillnotcompilebecauseofline17.

OptionEiscorrect.

WearecreatingaCallableobjectwithananonymousclassatline5,syntaxiscorrectsooptionCisincorrect.Passingtheobject"c"toanexecutorandgetasreturntypeaFuturetowaitforthreadends.Butatline17methodwaitofClassFuturedoesn'texistsoEiscorrect.

Examobjective:Concurrency-CreatingworkerthreadsusingRunnableandCallable.

OracleReference:https://docs.oracle.com/javase/tutorial/essential/concurrency/

Page 15: 1z0-809 pdf

https://www.certification-questions.com/

Q14.WhichofthefollowingsarevalidExecutorsfactorymethods:

I. ExecutorServicees1=Executors.newSingleThreadExecutor(4);II. ExecutorServicees1=Executors.newFixedThreadPool(10);III. ExecutorServicees1=Executors.newScheduledThreadPool();IV. ExecutorServicees1=Executors.newScheduledThreadPool(10);V. ExecutorServicees1=Executors.newSingleThreadScheduledExecutor();

A. I,II,III

B. II,III,IV,V

C. I,IV,V

D. II,IV,IV

E. All

OptionDiscorrect.

Themethod"newSingleThreadExecutor"cannotacceptparametersIisincorrect,themethod"newScheduledThreadPool"withparametersdoesn'texistssoIIIisincorrect.

Examobjective:Concurrency-UsinganExecutorServicetoconcurrentlyexecutetasks.

OracleReference:https://docs.oracle.com/javase/tutorial/essential/concurrency/

Page 16: 1z0-809 pdf

https://www.certification-questions.com/

Q15.Given

1. classA{2. privateStrings;3. publicA(Stringin){this.s=in;}4. 5. publicbooleanequals(Objectin){6. if(getClass()!=in.getClass())returnfalse;7. Aa=(A)in;8. booleanret=(this.s.equals(a.s));9. returnret;10. }11. };12. 13. publicclassProgram{14. publicstaticvoidmain(String[]args){15. Aa1=newA("A");16. Aa2=newA("A");17. if(a1==a2)System.out.println("true");18. elseSystem.out.println("false");19. }20. }

Whatwillbetheresult?

A. true

B. false

C. Thecodewillnotcompilebecauseofline17.

D. UnhandledexceptiontypeClassCastExceptionalline7.

E. Noneofabove

OptionBiscorrect.

InclassAthemethodequalsisbeenoverrideinacorrectway,anywaytheoperator"=="willcontinuetocompareobjectreference,sooptionBiscorrect.

Examobjective:JavaClassDesign-OverridehashCode,equals,andtoStringmethodsfromObjectclass

OracleReference:https://docs.oracle.com/javase/tutorial/java/IandI/objectclass.html

Page 17: 1z0-809 pdf

https://www.certification-questions.com/

Q16.Giventheclassdefinition

1. classG<T>{2. privateTt;3. 4. publicvoidset(Tt){this.t=t;}5. publicTget(){returnt;}6. }

WhichofthefollowingarevalidGClassinstantiation.

I. G<String>gen=newG<String>();II. G<>gen=newG<>();III. Ggen=newG();IV. G<A<String>>gen=newG<A<String>>();V. G<int>gen=newG<int>();

F. I,II,III.

G. I,II,IV.

H. I,III.

I. I,III,IV.

J. All.

OptionDiscorrect.

Atypevariablecanbeanynon-primitivetypeandanothertypevariable,sooptionI,IVarecorrectandVincorrect,optionIIisincorrectbecausemissthetypevariable,optionIIIiscorrectbecauseistherawtypeofG<T>.

Examobjective:CollectionsandGenerics-Creatingacustomgenericclass

OracleReference:https://docs.oracle.com/javase/tutorial/java/generics/types.html

Page 18: 1z0-809 pdf

https://www.certification-questions.com/

Q17.Given

1. classPerson{2. privateStringname;3. privateintage;4. Person(Stringname,intage){5. this.name=name;6. this.age=age;7. }8. publicStringtoString(){returnname+""+age;}9. 10. publicstaticComparator<Person>COMPARATOR=newComparator<Person>(){11. publicintcompare(Persono1,Persono2){12. return(o1.age-o2.age);13. } 14. }; 15. }16. publicclassProgram{17. 18. publicstaticvoidmain(String[]args){19. List<Person>list=newArrayList<Person>();20. list.add(newPerson("John",50));21. list.add(newPerson("Frank",15));22. list.add(newPerson("Adam",20));23. 24. Collections.sort(list,Person.COMPARATOR);25. list.forEach(a->System.out.print(a.toString()+""));26. }27. }

whatwillbetheresult?

A. Adam20Frank15John50

B. John50Adam20Frank15

C. Frank15Adam20John50

D. Thecodewillnotcompilebecauseofline24.

E. UnhandledexceptiontypeClassCastExceptionalline24.

OptionCiscorrect.

WiththeuseofTheComparatorObjectdefinedinline10wesortobjectsinanorderotherthantheirnaturalordering,thatistheageinstanceattribute,thanoptionCiscorrectmeanwhileAandBincorrect.ThecodehasnocompileerrorandnoexceptionwillthrowsooptionDeEareincorrect.

Examobjective:CollectionsandGenerics-Orderingcollections

OracleReference:https://docs.oracle.com/javase/tutorial/collections/interfaces/order.html

Page 19: 1z0-809 pdf

https://www.certification-questions.com/

Q18.Giventhefollowingcode

1. interfaceA{2. publicvoidm();3. };4. publicclassProgram{5. publicstaticvoidmain(String[]args){6. inty=0;7. //CodeHere8. }9. }

Whatarevalidanonymousclassdeclaration:

I. newA(){voidm1(){};publicvoidm(){};};

II. newA(){staticintx;publicvoidm(){};

};III. newA(){

publicvoidm(){y++;};};

IV. newA(){staticfinalintx=0;publicvoidm(){};

};

F. I,II,III.

G. I,IV.

H. I,II.

I. II,IV.

J. All.

OptionBiscorrect.

Ananonymousclasscannotaccesslocalvariablesinitsenclosingscopethatarenotdeclaredasfinaloreffectivelyfinal,soIIIisincorrect.Ananonymousclasscanhavestaticmembersprovidedthattheyareconstantvariables,thenIIisincorrect.OptionIandIVarevaliddeclaration,soBiscorrect.

Examobjective:InterfacesandLambdaExpressions-Anonymousinnerclasses

OracleReference:https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html

Page 20: 1z0-809 pdf

https://www.certification-questions.com/

Q19.Given

1. classPerson{2. privateStringname;3. privateintage;4. Person(Stringname,intage){5. this.name=name;6. this.age=age;7. }8. 9. publicStringtoString(){returnname+""+age;}10. 11. publicstaticComparator<Person>COMPARATOR=newComparator<Person>(){12. publicintcompare(Persono1,Persono2){13. return(o1.age-o2.age);14. }; 15. }; 16. };17. publicclassProgram{18. 19. publicstaticvoidmain(String[]args){20. Set<Person>list=newTreeSet<Person>(Person.COMPARATOR);21. list.add(newPerson("John",50));22. list.add(newPerson("Frank",15));23. list.add(newPerson("Adam",15));24. list.forEach(a->System.out.print(a.toString()+""));25. }26. }

whatwillbetheresult?

A. Frank15John50

B. John50Adam20Frank15

C. Frank15Adam20John50

D. Thecodewillnotcompilebecauseofline20.

E. UnhandledexceptiontypeClassCastExceptionalline20.

OptionAiscorrect.

TreeSetisaSortSetsoweneedtopassaComparatorobjectintheconstructorormaketheobjectPersonComparable.TheSetcollectiondoesn'tallowduplicatekeysandmethod"compare"isusedforobjectequality,butwearecomparingonlyageattributeandthanOptionAiscorrectandBandCareincorrect.ThecodehasnocompileerrorandnoexceptionwillthrowsooptionDeEareincorrect.

Examobjective:CollectionsandGenerics-Orderingcollections

OracleReference:https://docs.oracle.com/javase/tutorial/collections/interfaces/order.html

Page 21: 1z0-809 pdf

https://www.certification-questions.com/

Q20.Given

1. publicclassProgram{2. 3. publicstaticvoidmain(String[]args){4. Stringurl="jdbc:derby:testdb;create=true";5. try{6. Connectionconn=DriverManager.getConnection(url); 7. 8. Stringquery="selectnamefromcontacts";9. Statementstmt=conn.createStatement();10. 11. ResultSetrs=stmt.execute(query);12. while(rs.next()){13. Stringname=rs.getString("Name");14. System.out.println(name);15. }16. }catch(SQLExceptione){17. System.out.println(e.getMessage());18. }19. }20. }

Whatwillbetheresult?

A. Thecodewillnotcompilebecauseofline11.

B. Theprogramwillrunsuccessful.

C. Thecodewillnotcompilebecauseofline9.

D. Anexceptionisthrown.

E. NoneofAbove.

OptionAiscorrect.

OptionAiscorrectasthecodefailstocompile,themethod"execute"doesn'treturnaResultSetbuttrueifthefirstobjectthatthequeryreturnsisaResultSetobject,tomakethecodecompiletherightmethodis"executeQuery".

Examobjective:DatabaseApplicationswithJDBC-Submittingqueriesandgetresultsfromthedatabase.

OracleReference:https://docs.oracle.com/javase/tutorial/jdbc/overview/

Page 22: 1z0-809 pdf

https://www.certification-questions.com/

Q21.Given

1. publicclassProgram{2. publicstatic<T>intcount(T[]array){3. intcount=0;4. for(Te:array)++count;5. returncount;6. }7. publicstaticvoidmain(String[]args){8. Integer[]a={1,2,3,4,5};9. //Codehere10. System.out.println(n);11. }12. }

whichofthefollowingarevalidmethod'sinvocation.

A. intn=<Integer>Program.count(a);

B. intn=Program.<Integer>count(a);

C. intn=Program.count<Integer>(a);

D. intn=Program.count(a);

E. All

OptionBandDarecorrect.

OptionAandCareincorrectsyntaxforgenericmethodinvocation,optionBisthecorrectsyntaxforgenericmethodinvocation,typeinferenceallowsyoutoinvokeagenericmethodasanordinarymethodsooptionDiscorrectaswell.

Examobjective:CollectionsandGenerics-Creatingacustomgenericclass

OracleReference:https://docs.oracle.com/javase/tutorial/java/generics/methods.html

Page 23: 1z0-809 pdf

https://www.certification-questions.com/

Q22.WhichofthefollowingStatementaretrue

I. Ananonymousclasshasaccesstothemembersofitsenclosingclass.

II. Ananonymousclasscannotaccesslocalvariablesinitsenclosingscopethatarenot

declaredasfinaloreffectivelyfinal.

III.Youcannotdeclarestaticinitializersormemberinterfaces.

IV. Ananonymousclasscanhavestaticmembersprovidedthattheyareconstantvariables.

A. I,II,III.

B. I,II.

C. II,III,IV.

D. III,IV.

E. All.

OptionEiscorrect.

Examobjective:InterfacesandLambdaExpressions-Anonymousinnerclasses

OracleReference:https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html

Page 24: 1z0-809 pdf

https://www.certification-questions.com/

Q23.Given

1. classA{2. privateStrings;3. publicA(Strings){this.s=s;};4. publicStringtoString(){returns;}5. }6. publicclassProgram{7. 8. publicstaticvoidmain(String[]args){9. 10. List<A>list=newArrayList<A>();11. list.add(newA("flower"));12. list.add(newA("cat"));13. list.add(newA("house"));14. list.add(newA("dog"));15. Collections.sort(list);16. list.forEach(a->System.out.print(a.toString()+""));17. }18. }

Whatwillbetheresult?

A. houseflowerdogcat

B. catdogflowerhouse

C. flowercathousedog

D. Thecodewillnotcompilebecauseofline15.

E. UnhandledexceptiontypeClassCastExceptionalline15.

OptionDiscorrect.

Object"list"isatypeAArrayList,theCollections"sort"methodhassignatureasfollowing:

Collectios<TextendsComparable<?superT>>voidsort(List<T>list)

SothecodewillnotcompilebecauseclassAdoesn'timplementComparableinterface,andthanD

iscorrectandA,B,CandEareincorrect.

Examobjective:CollectionsandGenerics-Orderingcollections

OracleReference:https://docs.oracle.com/javase/tutorial/collections/interfaces/order.html

Page 25: 1z0-809 pdf

https://www.certification-questions.com/

Q24.WhichofthosearevalidStandardStreams

I. System.in

II. System.error

III.System.out

IV. System.input

V. System.output

A. I.

B. II,IV,V.

C. I,II,III.

D. I,III.

E. Anyofabove.

OptionDiscorrect.

System.error,System.inputandSystem.outputarenotvalidsyntax,sothecorrectanswerisD.

Examobjective:I/OFundamentals-Readandwritedatafromtheconsole

OracleReference:https://docs.oracle.com/javase/tutorial/essential/io/cl.html

Page 26: 1z0-809 pdf

https://www.certification-questions.com/

Q25.Whichis/aretrue?

I. InFileInputStreamandFileOutputStreameachreadorwriterequestishandleddirectly

bytheunderlyingOS.

II. Programsusebytestreamstoperforminputandoutputof8-bitbytes.

III.CharacterstreamI/Oautomaticallytranslatesthisinternalformattoandfromthe

localcharacterset.

IV. Therearetwogeneral-purposebyte-to-character"bridge"streams:InputStreamReader

andOutputStreamWriter.

A. I,II,III,IV.

B. II,III.

C. II,III,IV.

D. III,IV.

E. All.

OptionEiscorrect.

Examobjective:I/OFundamentals-Usingstreamstoreadandwritefiles

OracleReference:https://docs.oracle.com/javase/tutorial/essential/io