实例介绍
【实例简介】
oracle公司java8 Java SE 8 Programmer II 认证考试1z0-809题库 总128题
IntStream newStream stream map(in fu. apply aiNt (10) Answer: D Question: 3 Given the code fragment List<Integer> values Arrays asList(1, 2, 3); values. stream o map(n→>n*2 //line n1 peek(System. out: print) //line n2 counto What is the result? A.246 B The code produces no output C. A compilation error occurs at line n1 D. A compilation error occurs at line n2 Answer: A Question: 4 Given the code fragment public class Foo i public static void main(String [ args)I Map<Integer, String> unsortMap= new HashMap<>(; unsortMap. put(10, z; unsortMap put 5, b") unsortMap put(1,"d); unsortMap. put(7, "e); unsortMap. put(50, ) Map<Integer, String>treeMap new TreeMap <Integer, String>(new Comparator<Integer>(i @Overridepublicintcompare(Integerol,Integero2)freturno2.compareTo 01);}} treeMap. putAll(unsortMap; for(Map Entry<Integer, String> entry: treeMap. entrySet o)i System. out. print(entrygetvalue(+") What is the result? A. A compilation error occurs B d be zj Cjz e b d D.zbd Answer: c Question: 5 Which two reasons should you use interfaces instead of abstract classes? A You expect that classes that implement your interfaces have many common methods or fields, or require access modifiers other than public B You expect that unrelated classes would implement your interfaces. C. You want to share code among several closely related classes D. You want to declare non -static on non -final fields E You want to take advantage of multiple inheritance of type Answer:,e Explanation Refere http://www.programmerinterview.com/index.php/java-questions/interface-vs-abstract-class/ Question: 6 Given public class counter i public static void main(String[ args)i int a=10 nt b=-1: assert(b>=1): Invalid Denominator int c=a/b; System. out. println(c) What is the result of running the code with the -ea option? A.-10 C. An assertion Error is thrown D. A compilation error occurs Answer: b Question: 7 Given: class bird i public void fly oi system. out. print( Can fly); y class Penguin extends Bird i public void fly oi system. out. print( Cannot fly); and the code fragment class Birdie i public static void main (String args)i fly((->new Bird() fly(enguin: new); / line n1*/ Which code fragment when inserted at line n1, enables the birdie class to com pile? A static void fly(consumer< Bird> bird)i bird: fly (; B static void fly(Consumer<? extends bird> bird)i bird. accept() fly o; C static void fly Supplier< Bird> bird)t d get( fly o D static void fly (supplier<? extends bird> bird)t LOST Answer: C NOTE: Very confusing question. There is no logic in the options Question: 8 Given 1. abstract class Shape i 2345 Shapeoi system out printIn ("Shape") protected void area oi System. out println"Shape);y 6. class Square extends shape i int side Square int side i / insert code here * 10 this side side: 11 12. public void area(i System. out. println( "square);J 13 14. class rectangle extends square 15. int len br 16. Rectangle(int x, inti 17 / insert code here 18 len =X, br=y; 19 20. void area(i System. out. printIn ("Rectangle");I Which two modifications enable the code to compile? A. At line 1. remove abstract B At line 9, insert super (; C At line 12, remove public D. At line 17, insert super(x E. At line 17, insert super (; super side=X; F. At line 20, use public void area([ Answer: CD Question: 9 Given class Sum extends Recursive Action I //line n1 static final int THRESHold size =3: int stlndex, listindex int[ data; public Sum(int ]data, int start, int end)i his stIndex= start. this. Stundeⅹ=end protected void computed int sum=o if (lstlndex-stlndex <=THRESHOLD SIZE)I for(int i= stIndex; i< lstIndex i++)i sum + data [i] System. out. printIn(sum) F else i new Sum(data, stlndex THRESHOLD SIZE, Istlndex)fork() new Sum(data, stlndex, Math. min(lstIndex, stIndex +THRESHOLD SIZE) ) compute 0: and the code fragment Forkjoin Pool fjpool new ForkJoin Pool( int data[]={1,2,3,4,5,6,7,8,9,10} fPool invoke(new Sum(data, 0, data length)) and given that the sum of all integers from 1 to 10 is 55 Which statement is true? A. The program prints several values that total 55 B The program prints 55 C. a compilation error occurs at line n1 D. The program prints several values whose sum exceeds 55 Answer: c Question: 10 Given: public class Fook, V> I private K key private V value; public Foo (k key, v value)(this key =key; this value=value public static <T> Foo<T, T> twice(T value)(return new Foo<T, T>(value, value);) public k getKey o(return key public V getvalueo(return value; Which option fails? A Foo<String, Integer> mark= new Foo<String Integer>("Steve,100); B Foo<String, String> pair Foo <String>twice("Hello World! C Foo<?, ? percentage new Foo <>(97, 32) D Foo<String, String> grade new Foo <>John",A"; Answer: c Question: 11 Given the code fragment Stream<List<String>> iStr= Stream of Arrays. asList ("1",John") Arrays. aslist( 2", null)0 Stream<<String> nInSt =iStr flat MapTolnt((x)->Xstream o) nInSt forEach( System. out: print) What is the result? A. 1John2null B.12 C. A NullPointerException is thrown at run time D. A compilation error occurs Answer: C Question: 12 Given the code fragment Path file= Paths. get "courses. txt") // line n1 Assume the courses. txt is accessible Which code fragment can be inserted at line n1 to enable the code to print the content of the courses txt file? A. ListsString> fc= Files list(file); fc stream( forEach(s-> System. out. printIn(s)) B. Stream<String> fc= Files. readAll Lines(file) fc. for Each(s-> System. out. printIn(s) C. List<string> fc= readAllLines (file) fc stream(for Each(s-> System. out. printIn s)) D. Stream<String> fc= files. lines (file); fc. for Each(s-> System. out. printIn(s)); Answer: B Question: 13 Given the code fragment public void recDelete(String dir Name) throws IOException i File d listofFiles new File(dirName). listFileso if (listofFiles =null & listofFiles length >0)[ for(File a File: listOfFiles)i if (aFile is Directory o) Delete(aFile. getAbsolute Path () s else i if (aFilegetName(ends With("class") a File delete 0: Assume that projects contains subdirectories that contain. class files and is passed as an argument to the recdelete o method when it is invoked What is the result? A. The method deletes all the. class files in the projects directory and its subdirectories. B the method deletes the. class files of the projects directory only. C. The method executes and does not make any changes to the projects directory D. The method throws an loException Answer: B Question: 14 Given the code fragments 4. void dostuff( throws ArithmeticException, NumberFormatException, Exception i if(Math. random >-1 throw new Exception " Try again); 6.} and 24. try t 25 dostuff (: 26.] catch(ArithmeticException I NumberFormatException Exception e)i 27. System. out. println(e getMessage(); 1 28. catch(Exception e[ 29 System. out. printIn(e getMessage(); 1 Which modification enables the code to print try again? A. Comment the lines 28, 29 and 30 B Replace line 26 with y catch(Exception ArithmeticException Number FormatException e)t C Replace line 26 with 3 catch(ArithmeticException NumberFormatException e) D. Replace line 27 with throw e Answer: c Question: 15 Given the definition of the Country class public class country i public enum Continent ASIA, EUROPEy String name; Continent region; public Country( String na, Continent reg name = na, region = reg public String getName(return name public Continent getRegion ireturn region; 1 and the code fragment List< Country> couLis= Arrays. asList( new Country(Japan", Country. Continent ASIA) new Country italy, Country. Continent. EUROPE) new Country germany", Country Continent EUROPED) Map<Country. Continent, List<string>> region Names= coulist stream o collect(Collectors. grouping By (Country: getRegion, Collectors. mapping country: getName, Collectors tolist()); System. out. println(region Names What is the output? A. EUROPE=[Italy Germany, asia japan] B. ASIA= [Japan, EUROPE =[Italy, Germany ly C. EUROPE =[Germany, Italy, ASIA=[Japanll D. EUROPE =[Germany], EUROPE =[Italy], ASIA=[Japan1] Answer: A Question: 16 Given the code fragment Map<Integer, String> books new TreeMap<>o books. put(1007,“A"); books. put(1002,“C"); books. put(1001,“B"); books. put(1003,“B"); System. out. printIn(books) What is the result? A.{1007=A,1002=C,1001=B,1003=B B.{1001=B,1002=C1003=B,1007=A C.{1002=C1003=B,1007=A} D.{1007=A,1001=B,1003=B,1002=C} Answer: D Question: 17 Given: class book i String name public book(int id, String namei this name s name public boolean equals(object obj) / line n1 boolean output false: Book b=(Book)obj if (this name. equals(b name)) output true return output and the code fragment Book b1= new Book(101, Java Programing); Book b2= new Book(102, Java programing)i System. out. println(b1.equals(b2)) //line n2 Which statement is true? A. the program prints true B The program prints false C. A compilation error occurs. To ensure successful compilation, replace line n1 with boolean equals (Book obj) D. A compilation error occurs. To ensure successful compilation replace line n2 with: System. out. printIn(b1.equals(object) b2)) Answer: C Question: 18 Given the content of /resourses/Message properties welcome 1="Good day! and given the code fragment Properties prop= new Properties o FilelnputStream fis= new FilelnputStream("/resources/Message properties; prop. load(fis); System. out. printIn(prop. getProperty welcome"); 【实例截图】
【核心代码】
oracle公司java8 Java SE 8 Programmer II 认证考试1z0-809题库 总128题
IntStream newStream stream map(in fu. apply aiNt (10) Answer: D Question: 3 Given the code fragment List<Integer> values Arrays asList(1, 2, 3); values. stream o map(n→>n*2 //line n1 peek(System. out: print) //line n2 counto What is the result? A.246 B The code produces no output C. A compilation error occurs at line n1 D. A compilation error occurs at line n2 Answer: A Question: 4 Given the code fragment public class Foo i public static void main(String [ args)I Map<Integer, String> unsortMap= new HashMap<>(; unsortMap. put(10, z; unsortMap put 5, b") unsortMap put(1,"d); unsortMap. put(7, "e); unsortMap. put(50, ) Map<Integer, String>treeMap new TreeMap <Integer, String>(new Comparator<Integer>(i @Overridepublicintcompare(Integerol,Integero2)freturno2.compareTo 01);}} treeMap. putAll(unsortMap; for(Map Entry<Integer, String> entry: treeMap. entrySet o)i System. out. print(entrygetvalue(+") What is the result? A. A compilation error occurs B d be zj Cjz e b d D.zbd Answer: c Question: 5 Which two reasons should you use interfaces instead of abstract classes? A You expect that classes that implement your interfaces have many common methods or fields, or require access modifiers other than public B You expect that unrelated classes would implement your interfaces. C. You want to share code among several closely related classes D. You want to declare non -static on non -final fields E You want to take advantage of multiple inheritance of type Answer:,e Explanation Refere http://www.programmerinterview.com/index.php/java-questions/interface-vs-abstract-class/ Question: 6 Given public class counter i public static void main(String[ args)i int a=10 nt b=-1: assert(b>=1): Invalid Denominator int c=a/b; System. out. println(c) What is the result of running the code with the -ea option? A.-10 C. An assertion Error is thrown D. A compilation error occurs Answer: b Question: 7 Given: class bird i public void fly oi system. out. print( Can fly); y class Penguin extends Bird i public void fly oi system. out. print( Cannot fly); and the code fragment class Birdie i public static void main (String args)i fly((->new Bird() fly(enguin: new); / line n1*/ Which code fragment when inserted at line n1, enables the birdie class to com pile? A static void fly(consumer< Bird> bird)i bird: fly (; B static void fly(Consumer<? extends bird> bird)i bird. accept() fly o; C static void fly Supplier< Bird> bird)t d get( fly o D static void fly (supplier<? extends bird> bird)t LOST Answer: C NOTE: Very confusing question. There is no logic in the options Question: 8 Given 1. abstract class Shape i 2345 Shapeoi system out printIn ("Shape") protected void area oi System. out println"Shape);y 6. class Square extends shape i int side Square int side i / insert code here * 10 this side side: 11 12. public void area(i System. out. println( "square);J 13 14. class rectangle extends square 15. int len br 16. Rectangle(int x, inti 17 / insert code here 18 len =X, br=y; 19 20. void area(i System. out. printIn ("Rectangle");I Which two modifications enable the code to compile? A. At line 1. remove abstract B At line 9, insert super (; C At line 12, remove public D. At line 17, insert super(x E. At line 17, insert super (; super side=X; F. At line 20, use public void area([ Answer: CD Question: 9 Given class Sum extends Recursive Action I //line n1 static final int THRESHold size =3: int stlndex, listindex int[ data; public Sum(int ]data, int start, int end)i his stIndex= start. this. Stundeⅹ=end protected void computed int sum=o if (lstlndex-stlndex <=THRESHOLD SIZE)I for(int i= stIndex; i< lstIndex i++)i sum + data [i] System. out. printIn(sum) F else i new Sum(data, stlndex THRESHOLD SIZE, Istlndex)fork() new Sum(data, stlndex, Math. min(lstIndex, stIndex +THRESHOLD SIZE) ) compute 0: and the code fragment Forkjoin Pool fjpool new ForkJoin Pool( int data[]={1,2,3,4,5,6,7,8,9,10} fPool invoke(new Sum(data, 0, data length)) and given that the sum of all integers from 1 to 10 is 55 Which statement is true? A. The program prints several values that total 55 B The program prints 55 C. a compilation error occurs at line n1 D. The program prints several values whose sum exceeds 55 Answer: c Question: 10 Given: public class Fook, V> I private K key private V value; public Foo (k key, v value)(this key =key; this value=value public static <T> Foo<T, T> twice(T value)(return new Foo<T, T>(value, value);) public k getKey o(return key public V getvalueo(return value; Which option fails? A Foo<String, Integer> mark= new Foo<String Integer>("Steve,100); B Foo<String, String> pair Foo <String>twice("Hello World! C Foo<?, ? percentage new Foo <>(97, 32) D Foo<String, String> grade new Foo <>John",A"; Answer: c Question: 11 Given the code fragment Stream<List<String>> iStr= Stream of Arrays. asList ("1",John") Arrays. aslist( 2", null)0 Stream<<String> nInSt =iStr flat MapTolnt((x)->Xstream o) nInSt forEach( System. out: print) What is the result? A. 1John2null B.12 C. A NullPointerException is thrown at run time D. A compilation error occurs Answer: C Question: 12 Given the code fragment Path file= Paths. get "courses. txt") // line n1 Assume the courses. txt is accessible Which code fragment can be inserted at line n1 to enable the code to print the content of the courses txt file? A. ListsString> fc= Files list(file); fc stream( forEach(s-> System. out. printIn(s)) B. Stream<String> fc= Files. readAll Lines(file) fc. for Each(s-> System. out. printIn(s) C. List<string> fc= readAllLines (file) fc stream(for Each(s-> System. out. printIn s)) D. Stream<String> fc= files. lines (file); fc. for Each(s-> System. out. printIn(s)); Answer: B Question: 13 Given the code fragment public void recDelete(String dir Name) throws IOException i File d listofFiles new File(dirName). listFileso if (listofFiles =null & listofFiles length >0)[ for(File a File: listOfFiles)i if (aFile is Directory o) Delete(aFile. getAbsolute Path () s else i if (aFilegetName(ends With("class") a File delete 0: Assume that projects contains subdirectories that contain. class files and is passed as an argument to the recdelete o method when it is invoked What is the result? A. The method deletes all the. class files in the projects directory and its subdirectories. B the method deletes the. class files of the projects directory only. C. The method executes and does not make any changes to the projects directory D. The method throws an loException Answer: B Question: 14 Given the code fragments 4. void dostuff( throws ArithmeticException, NumberFormatException, Exception i if(Math. random >-1 throw new Exception " Try again); 6.} and 24. try t 25 dostuff (: 26.] catch(ArithmeticException I NumberFormatException Exception e)i 27. System. out. println(e getMessage(); 1 28. catch(Exception e[ 29 System. out. printIn(e getMessage(); 1 Which modification enables the code to print try again? A. Comment the lines 28, 29 and 30 B Replace line 26 with y catch(Exception ArithmeticException Number FormatException e)t C Replace line 26 with 3 catch(ArithmeticException NumberFormatException e) D. Replace line 27 with throw e Answer: c Question: 15 Given the definition of the Country class public class country i public enum Continent ASIA, EUROPEy String name; Continent region; public Country( String na, Continent reg name = na, region = reg public String getName(return name public Continent getRegion ireturn region; 1 and the code fragment List< Country> couLis= Arrays. asList( new Country(Japan", Country. Continent ASIA) new Country italy, Country. Continent. EUROPE) new Country germany", Country Continent EUROPED) Map<Country. Continent, List<string>> region Names= coulist stream o collect(Collectors. grouping By (Country: getRegion, Collectors. mapping country: getName, Collectors tolist()); System. out. println(region Names What is the output? A. EUROPE=[Italy Germany, asia japan] B. ASIA= [Japan, EUROPE =[Italy, Germany ly C. EUROPE =[Germany, Italy, ASIA=[Japanll D. EUROPE =[Germany], EUROPE =[Italy], ASIA=[Japan1] Answer: A Question: 16 Given the code fragment Map<Integer, String> books new TreeMap<>o books. put(1007,“A"); books. put(1002,“C"); books. put(1001,“B"); books. put(1003,“B"); System. out. printIn(books) What is the result? A.{1007=A,1002=C,1001=B,1003=B B.{1001=B,1002=C1003=B,1007=A C.{1002=C1003=B,1007=A} D.{1007=A,1001=B,1003=B,1002=C} Answer: D Question: 17 Given: class book i String name public book(int id, String namei this name s name public boolean equals(object obj) / line n1 boolean output false: Book b=(Book)obj if (this name. equals(b name)) output true return output and the code fragment Book b1= new Book(101, Java Programing); Book b2= new Book(102, Java programing)i System. out. println(b1.equals(b2)) //line n2 Which statement is true? A. the program prints true B The program prints false C. A compilation error occurs. To ensure successful compilation, replace line n1 with boolean equals (Book obj) D. A compilation error occurs. To ensure successful compilation replace line n2 with: System. out. printIn(b1.equals(object) b2)) Answer: C Question: 18 Given the content of /resourses/Message properties welcome 1="Good day! and given the code fragment Properties prop= new Properties o FilelnputStream fis= new FilelnputStream("/resources/Message properties; prop. load(fis); System. out. printIn(prop. getProperty welcome"); 【实例截图】
【核心代码】
标签:
好例子网口号:伸出你的我的手 — 分享!
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论