一些Java关键字概念问题

发布于 2024-09-08 19:30:22 字数 113 浏览 9 评论 0原文

请帮助我用简单的示例概念化以下关键字的含义:

  • strictfp
  • assert
  • 瞬态
  • 本机
  • 同步

Please help me to conceptuallize meaning of following keywords with simple example :

  • strictfp
  • assert
  • transient
  • native
  • synchronised

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟凡古楼 2024-09-15 19:30:22

您想要的所有回复都在 Java 语言规范 中:

  • strictfp (对于 接口, 方法) 允许对代数运算进行一些特定的强制
  • assert 对于在代码中编写测试语句很有用,不幸的是被 Sun 规范作废了(以及需要在编译和执行期间启用它)
  • native 允许调用 so - 称为本机代码,即为平台编译的代码(使用正确的编译器参数编译的 C)
  • 同步(可应用于块和 方法总是令人好奇的结果)

All the replies you want are in the Java Language Specification :

  • strictfp (for classes, interfaces, methods) allows some specific coercion on algbraic operations
  • assert useful to write test statements in code, unfortunatly voided by Sun spec (and the need to enable it during both compilation and execution)
  • transient dirk is right, and I was wrong. transient relates to member fields that are not serialized.
  • native allows the call of so-called native code i.e. code compiled for platform (C compiled with the correct compiler args)
  • synchronized (which can be applied to both blocks and methods for always curious results)
绝不服输 2024-09-15 19:30:22

看看谷歌一下会给你带来什么。问题是,你为什么不自己用谷歌(bing,yahoo)搜索它?

http://en.wikipedia.org/wiki/List_of_Java_keywords

虽然此页面不包含例如,每个定义都有一个指向更详细定义的链接,在某些情况下,还有包含示例的资源。

See what a little google will get you. Question is, why didn't you google (bing, yahoo) it yourself?

http://en.wikipedia.org/wiki/List_of_Java_keywords

Although this page doesn't contain examples, each definition has a link to a much more detailed definition, and in some cases, resources that contain examples.

那一片橙海, 2024-09-15 19:30:22
  • strictfp:浮点计算取决于处理器的架构。处理器中的数字表示格式会略有不同,这会影响浮点运算的误差范围。 Java 的早期版本在所有实现中强制采用通用表示,而不管底层 CPU(x86、PPC 等)如何。这意味着浮点运算必须被解释并且不能像处理器那样快地完成。后来的 Java 版本(如果我没记错的话,是 1.2)消除了这个限制,直接使用处理器来获得更快的结果,但代价是浮点结果依赖于 CPU 架构。具有 scrictfp 的类或方法将强制结果独立于 CPU 架构。

  • assert:强制执行断言/“契约”。

  • native:用于 JNI(例如链接到 C 库)。

  • transient:用于(非)序列化。

  • synchronized:我只能推荐Java Concurrent in Practice

  • strictfp: Floating point computation depends on the architecture of the processor. There will be slight differences in the number representation format in the processor, which will influence the error margin of the floating point operations. Early versions of Java were forcing a common representation in all implementations, irrespectively of the underlying CPU (x86, PPC, ...). This meant that the floating point operations had to be interpreted and couldn't be done as fast as the processor would have done. Later versions of Java (1.2 if I remember well) removed that constraint, to make direct use of the processor for faster result, at the expense of making the floating point results depend on the CPU architecture. Classes or method with scrictfp will force the result to be independent of the CPU architecture.

  • assert: to enforce assertions/"contracts".

  • native: for JNI (linking to C libraries, for example).

  • transient: for (non) serialization.

  • synchronized: I can only recommend Java Concurrent in Practice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文