OCP Java17 SE Developers 复习题11

============================  答案  ==============================

================================================================

================================================================

A, C, D, E.  A method that declares an exception isn't required to throw one, making option A correct. Unchecked exceptions can be thrown in any method, making options C and E correct. Option D matches the exception type declared, so it's also correct. Option B is incorrect because a broader exception is not allowed.

============================  答案  ==============================

================================================================

================================================================

F.  The code does not compile because the throw and throws keywords are incorrectly used on lines 6, 7, and 9. If the keywords were fixed, the rest of the code would compile and print a stack trace with YesProblem at runtime. For this reason, option F is correct.

============================  答案  ==============================

================================================================

================================================================

A, D, E.  Localization refers to user-facing elements. Dates, currency, and numbers are commonly used in different formats for different countries, making options A, D, and E correct. Class and variable names, along with lambda expressions, are internal to the application, so there is no need to translate them for users.

============================  答案  ==============================

================================================================

================================================================

E.  The order of catch blocks is important because they're checked in the order they appear after the try block. Because ArithmeticException is a child class of RuntimeException, the catch block on line 7 is unreachable (if an ArithmeticException is thrown in the try block, it will be caught on line 5). Line 7 generates a compiler error because it is unreachable code, making option E correct.

============================  答案  ==============================

================================================================

================================================================

C, F.  The code compiles and runs without issue. When a CompactNumberFormat instance is requested without a style, it uses the SHORT style by default. This results in both of the first two statements printing 100K, making option C correct. If the LONG style were used, then 100 thousand would be printed. Option F is also correct, as the full value is printed with a currency formatter.

============================  答案  ==============================

================================================================

================================================================

E.  A LocalDate does not have a time element. Therefore, a date/time formatter is not appropriate. The code compiles but throws an exception at runtime, making option E correct. If ISO_LOCAL_DATE were used, the code would print 2022 APRIL 30.

============================  答案  ==============================

================================================================

================================================================

E.  The first compiler error is on line 12 because each resource in a try-with-resources statement must have its own data type and be separated by a semicolon (;). Line 15 does not compile because the variable s is already declared in the method. Line 17 also does not compile. The FileNotFoundException, which inherits from IOException and Exception, is a checked exception, so it must be handled in a try/catch block or declared by the method. Because these three lines of code do not compile, option E is the correct answer.

============================  答案  ==============================

================================================================

================================================================

C.  Java will first look for the most specific matches it can find, starting with Dolphins_en_US.properties. Since that is not an answer choice, it drops the country and looks for Dolphins_en.properties, making option C correct. Option B is incorrect because a country without a language is not a valid locale.

============================  答案  ==============================

================================================================

================================================================

D.  When working with a custom number formatter, the 0 symbol displays the digit as 0, even if it's not present, while the # symbol omits the digit from the start or end of the String if it is not present. Based on the requested output, a String that displays at least three digits before the decimal (including a comma) and at least one after the decimal is required. It should display a second digit after the decimal if one is available. For this reason, option D is the correct answer.

============================  答案  ==============================

================================================================

================================================================

B.  An IllegalArgumentException is used when an unexpected parameter is passed into a method, making option B correct. Option A is incorrect because returning null or -1 is a common return value for searching for data. Option D is incorrect because a for loop is typically used for this scenario. Option E is incorrect because you should find out how to code the method and not leave it for the unsuspecting programmer who calls your method. Option C is incorrect because you should run!

============================  答案  ==============================

================================================================

================================================================

B, E, F.  An exception that must be handled or declared is a checked exception. A checked exception inherits Exception but not RuntimeException. The entire hierarchy counts, so options B and E are both correct. Option F is also correct, as a class that inherits Throwable but not RuntimeException or Error is also checked.

============================  答案  ==============================

================================================================

================================================================

B, C.  The code does not compile as is because the exception declared by the close() method must be handled or declared. Option A is incorrect because removing the exception from the declaration causes a compilation error on line 4, as FileNotFoundException is a checked exception that must be handled or declared. Option B is correct because the unhandled exception within the main() method becomes declared. Option C is also correct because the exception becomes handled. Option D is incorrect because the exception remains unhandled.

============================  答案  ==============================

================================================================

================================================================

A, B.  A try-with-resources statement does not require a catch or finally block. A traditional try statement requires at least one of the two. Neither statement can be written without a body encased in braces, {}. For these reasons, options A and B are correct.

============================  答案  ==============================

================================================================

================================================================

C.  Starting with Java 15, NullPointerException stack traces include the name of the variable that is null by default, making option A incorrect. The first NullPointerException encountered at runtime is when dewey.intValue() is called, making option C correct. Options E and F are incorrect as only one NullPointerException exception can be thrown at a time.

============================  答案  ==============================

================================================================

================================================================

C, D.  The code compiles with the appropriate input, so option G is incorrect. A locale consists of a required lowercase language code and optional uppercase country code. In the Locale() constructor, the language code is provided first. For these reasons, options C and D are correct. Option E is incorrect because a Locale is created using a constructor or Locale.Builder class. Option F is really close but is missing build() at the end. Without that, option F does not compile.

============================  答案  ==============================

================================================================

================================================================

F.  The code compiles, but the first line produces a runtime exception regardless of what is inserted into the blank, making option F correct. When creating a custom formatter, any nonsymbol code must be properly escaped using pairs of single quotes ('). In this case, it fails because o is not a symbol. Even if you didn't know o wasn't a symbol, the code contains an unmatched single quote. If the properly escaped value of "hh' o''clock'" were used, then the correct answers would be ZonedDateTimeLocalDateTime, and LocalTime. Option B would not be correct because LocalDate values do not have an hour part.

============================  答案  ==============================

================================================================

================================================================

D, F.  Option A is incorrect because Java will look at parent bundles if a key is not found in a specified resource bundle. Option B is incorrect because resource bundles are loaded from static factory methods. Option C is incorrect, as resource bundle values are read from the ResourceBundle object directly. Option D is correct because the locale is changed only in memory. Option E is incorrect, as the resource bundle for the default locale may be used if there is no resource bundle for the specified locale (or its locale without a country code). Finally, option F is correct. The JVM will set a default locale automatically.

============================  答案  ==============================

================================================================

================================================================

C.  After both resources are declared and created in the try-with-resources statement, T is printed as part of the body. Then the try-with-resources completes and closes the resources in the reverse of the order in which they were declared. After W is printed, an exception is thrown. However, the remaining resource still needs to be closed, so D is printed. Once all the resources are closed, the exception is thrown and swallowed in the catch block, causing E to be printed. Last, the finally block is run, printing F. Therefore, the answer is TWDEF and option C is correct.

============================  答案  ==============================

================================================================

================================================================

D.  Java will use Dolphins_fr.properties as the matching resource bundle on line 7 because it is an exact match on the language of the requested locale. Line 8 finds a matching key in this file. Line 9 does not find a match in that file; therefore, it has to look higher up in the hierarchy. Once a bundle is chosen, only resources in that hierarchy are allowed. It cannot use the default locale anymore, but it can use the default resource bundle specified by Dolphins.properties. For these reasons, option D is correct.

============================  答案  ==============================

================================================================

================================================================

G.  The main() method invokes go(), and A is printed on line 3. The stop() method is invoked, and E is printed on line 14. Line 16 throws a NullPointerException, so stop() immediately ends, and line 17 doesn't execute. The exception isn't caught in go(), so the go() method ends as well, but not before its finally block executes and C is printed on line 9. Because main() doesn't catch the exception, the stack trace displays, and no further output occurs. For these reasons, AEC is printed followed by a stack trace for a NullPointerException, making option G correct.

============================  答案  ==============================

================================================================

================================================================

C.  The code does not compile because the multi-catch block on line 7 cannot catch both a superclass and a related subclass. Options A and B do not address this problem, so they are incorrect. Since the try body throws SneezeException, it can be caught in a catch block, making option C correct. Option D allows the catch block to compile but causes a compiler error on line 6. Both of the custom exceptions are checked and must be handled or declared in the main() method. A SneezeException is not a SniffleException, so the exception is not handled. Likewise, option E leads to an unhandled exception compiler error on line 6.

============================  答案  ==============================

================================================================

================================================================

B.  For this question, the date used is April 5, 2022 at 12:30:20pm. The code compiles, and either form of the formatter is correct: dateTime.format(formatter) or formatter.format(dateTime). The custom format m returns the minute, so 30 is output first. The next line throws an exception as z relates to time zone, and date/time does not have a zone component. This exception is then swallowed by the try/catch block. Since this is the only value printed, option B is correct. If the code had not thrown an exception, the last line would have printed 2022.

============================  答案  ==============================

================================================================

================================================================

A, E.  Resources must inherit AutoCloseable to be used in a try-with-resources block. Since Closeable, which is used for I/O classes, extends AutoCloseable, both may be used, making options A and E correct.

============================  答案  ==============================

================================================================

================================================================

G.  The code does not compile because the resource walk1 is not final or effectively final and cannot be used in the declaration of a try-with-resources statement. For this reason, option G is correct. If the line that set walk1 to null were removed, then the code would compile and print blizzard 2 at runtime, with the exception inside the try block being the primary exception since it is thrown first. Then two suppressed exceptions would be added to it when trying to close the AutoCloseable resources.

============================  答案  ==============================

================================================================

================================================================

A.  The code compiles and prints the value for Germany, 2,40 €, making option A the correct answer. Note that the default locale category is ignored since an explicit currency locale is selected.

============================  答案  ==============================

================================================================

================================================================

B, F.  The try block is not capable of throwing an IOException, making the catch block unreachable code and option A incorrect. Options B and F are correct, as both are unchecked exceptions that do not extend or inherit from IllegalArgumentException. Remember, it is not a good idea to catch Error in practice, although because it is possible, it may come up on the exam. Option C is incorrect because the variable c is declared already in the method declaration. Option D is incorrect because the IllegalArgumentException inherits from RuntimeException, making the first declaration unnecessary. Similarly, option E is incorrect because NumberFormatException inherits from IllegalArgumentException, making the second declaration unnecessary. Since options B and F are correct, option G is incorrect.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/522904.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Android Glide

1.引入glide implementation com.github.bumptech.glide:glide:4.14.2 // Skip this if you dont want to use integration libraries or configure Glide. annotationProcessor com.github.bumptech.glide:compiler:4.14.2 //Glide 注解处理器 2.AndroidManifest.xml 中添加…

JVM 全景图

今天我重新复习了一下 jvm 的一些知识点。我以前觉得 jvm 的知识点很多很碎,而且记起来很困难,但是今天我重新复习了一下,对这些知识点进行了简单的梳理之后,产生了不一样的看法。虽然 jvm 的知识点很碎,但是如果你真的…

C# Web应用调用EXE文件的一些实践

目录 需求 范例运行环境 可执行文件的设计 调用可执行文件方法 RunExecuteFile RunShellExecuteFile 方法的区别 WEB调用举例 小结 需求 最近同事使用Python开发了一款智能文字转语音的程序,经讨论部署在WINDOWS环境服务器下,因此需要生成目标…

【御控物联】JavaScript JSON结构转换(19):数组To对象——规则属性重组

文章目录 一、JSON结构转换是什么?二、术语解释三、案例之《JSON数组 To JSON对象》四、代码实现五、在线转换工具六、技术资料 一、JSON结构转换是什么? JSON结构转换指的是将一个JSON对象或JSON数组按照一定规则进行重组、筛选、映射或转换&#xff0…

python画带阴影折线图

(1) # codinggbk import matplotlib.pyplot as plt import numpy as np# 创建一些示例数据 x np.linspace(-3, 3, 60) y_mean np.sin(x) y_std np.sin(x)# 画折线图 b-:蓝色实线 plt.plot(x, y_mean, b-, labelMean)# 填充阴影表示标准差 alpha…

机场新篇章:3D可视化技术引领航空智慧时代

在科技日新月异的今天,3D可视化技术正逐步渗透到我们生活的方方面面,为各行各业带来了前所未有的变革。3D可视化技术以其独特的魅力和实用性,正逐渐成为航空领域的新宠,引领着航空业迈向更加智能化、高效化的未来。 机场作为连接世…

OCm (Radeon Open Compute) 和 CUDA (Compute Unified Device Architecture)

OCm(Radeon Open Compute)和CUDA(Compute Unified Device Architecture)是两种旨在利用图形处理单元(GPU)进行通用计算的技术和框架。 OCm(Radeon Open Compute): OCm&…

MS9740B进行DUT插入损耗的评估,操作步骤?

使用MS9740B进行DUT(设备待测)插入损耗的评估,首先需要了解MS9740B的基本功能和配置。MS9740B是一款高精度光谱分析仪,支持多种光纤类型,包括SM光纤(ITU-T G.652)和GI光纤(50μm/125…

JavaScript - 你都知道哪些常用的HTTP状态码,他们的含义是什么

难度级别:中级及以上 提问概率:50% 目录 200 301 302 304 400 401 403 404

css- 4

1.浮动 1. 浮动最初用于实现文字环绕效果 2. 现在,浮动是主流的布局方式之一 1.1元素浮动之后的特点 元素浮动之后,称为浮动元素,具有如下特点: 1. 浮动元素脱离文档流 2. 多个浮动的元素会水平排列,一行放不下自动换…

RK3568 学习笔记 : 独立修改与编译 u-boot

前言 开发板:【正点原子】ATomPi-CA1 开发板,配置:RK3568,4GB DDRAM 64GB emmc 开发板资料给了 u-boot 与 Linux kernel 源码,尝试手动编译。 本篇记录 收到编译 RK3568 平台 u-boot 的方法 环境搭建 由于 RK 平台…

穿越代码之海:探寻结构体深层逻辑,展望未来应用新天地

欢迎来到白刘的领域 Miracle_86.-CSDN博客 系列专栏 C语言知识 先赞后看,已成习惯 创作不易,多多支持! 结构体作为一种数据结构,其定义和特点决定了它在各种应用中的广泛适用性。随着科技的进步和新兴行业的不断涌现&#xf…

2024年选择云渲染平台必须注意这5点!看完你就懂了

云渲染平台这么多,你是不是正在为选择哪一家而困惑? 随着云渲染技术的进一步发展,市面上的云渲染平台也越来越多,其中鱼龙混杂的也不在少数。对于设计师和设计公司来说,如何选择一个可靠且适合自己的云渲染平台成为一…

【ZIP技巧】ZIP分卷压缩包如何合并为一个?

通常,ZIP压缩文件文件体积过大的时候,大家可能都会选择“分卷压缩”来压缩ZIP文件,但是你是否遇到过需要将分卷压缩的文件合并回一个完整zip文件的情况?今天我们分享两个ZIP分卷压缩包合并的方法给大家。 方法一: 我…

java之static详细总结

static也叫静态,可以修饰成员变量、成员方法。 成员变量 按照有无static分为两种: 类变量:static修饰,属于类,与类一起加载一次,在内存中只有一份,会被类的全部对象共享实例变量(…

docker-compose安装adguard给局域网提供dns加速服务

启动配置 docker-compose.yaml配置文件 version: 3.3 services:adguard:image: adguard/adguardhome:latestcontainer_name: adguardrestart: unless-stoppedvolumes:- ./workdir:/opt/adguardhome/work- ./confdir:/opt/adguardhome/confports:- 53:53/tcp- 53:53/udp- 81:8…

蓝桥-回文日期

目录 题目链接 ​编辑 ​编辑 什么是回文数?​编辑 代码 100%过 90%暴力 优化写的暴力代码 题目链接 2.回文日期 - 蓝桥云课 (lanqiao.cn) 什么是回文数? 代码 100%过 把那个90%的代码的循环限制条件去掉就行了,题目只是限制了N…

每日一题(leetcode1026):节点与其祖先的最大差值--dfs

考虑到只能计算祖先之间的节点差而不能计算兄弟之间的节点差,所以思考使用dfs来解决该题。 /*** Definition for a binary tree node.* struct TreeNode {* int val;* TreeNode *left;* TreeNode *right;* TreeNode() : val(0), left(nullptr), ri…

axure谷歌插件(直接下载)

axure谷歌插件 在网上找一个谷歌的axure,不是登陆就是收费,离谱。找了好久才找到这个,我下载保存到网盘了,直接下载就ok,永久无提取码。 下载插件文件,打开开发者模式,直接拖进来就ok。 网盘…

YOLOv8改进 | 细节涨点篇 | 利用YOLOv8自带的RayTune进行超参数调优

一、本文介绍 本文给大家带来的改进机制是利用Ray Tune进行超参数调优,在YOLOv8的项目中目前已经自带了该超参数调优的代码,我们无需进行任何的改动,只需要调用该方法输入我们的一些指令即可,当然了,这些超参数的设置还是比较又学问的,本文的内容也是应群友的需求进行发…