用java 1.5和1.5.0_06编译的类有区别吗

发布于 2024-11-15 02:43:14 字数 252 浏览 3 评论 0原文

我用java版本1.5编译了一个类。

当我将它部署在服务器中时,它给了我错误的版本错误。

如果我使用 java 版本 1.5.0_06 编译它,如果服务器具有版本 1.5.0_06 的 java

1.版本中的最后一个数字也会有所不同吗?

2.javap -verbose ClassName 给我次要版本和主要版本,但如何知道该类是用哪个更新编译的?

谢谢, 桑迪普

I have compiled a class with java version 1.5.

When i deployed it in the server it gave me bad version error.

If i compile it with java version 1.5.0_06 does that make a difference if the server is having java of version 1.5.0_06

1.Does the last number in version also make the difference??

2.javap -verbose ClassName gives me the minor and major version but how to know with which update the class is compiled with??

Thanks,
Sandeep

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

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

发布评论

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

评论(3

只是偏爱你 2024-11-22 02:43:14

JRE/JDK 1.5.0_06 是 Java 1.5(或 Java 5,具体取决于星期几)的实现。

所以不,没有区别,为 Java 1.5 编译的类应该在该版本上正常工作。

类版本不会告诉您该类是使用哪个 JDK 更新进行编译的,并且该信息也不应该是相关的。

The JRE/JDK 1.5.0_06 is an implementation of Java 1.5 (or Java 5, depending on which day of the week it is).

So no, there is no difference, classes compiled for Java 1.5 should work just fine on that version.

The class version won't tell you which update of the JDK the class was compiled with, and that information should also not be relevant.

最丧也最甜 2024-11-22 02:43:14

使用 JDK 1.5 和 JDK 1.5.0_06 编译一个类(任何类)。然后比较1.5编译的和1.5.0_06编译的主/次版本。如果它们相同,那么您应该可以在使用 Java 1.5.0_06 的服务器上运行用 1.5 编译的类。否则你不能。

Compile a class (any class) with both JDK 1.5 and JDK 1.5.0_06. Then compare the major/minor version of the one compiled with 1.5 with the one compiled with 1.5.0_06. If they were identical, you should be fine running the class compiled with 1.5 on a server that uses Java 1.5.0_06. Otherwise you can not.

倾`听者〃 2024-11-22 02:43:14

1.版本中的最后一个数字也有区别吗?

不。不应该。但是,由于较小的版本差异,我在运行时遇到了问题。进一步排查,发现是由于对API理解不全面造成的。开发人员期望 obj.getClass().getFields() 按声明顺序返回字段,并且在一个版本中就是这样工作的。在较新的更新中,它以不同的顺序返回字段。 API 明确表示“返回的数组中的元素未排序,并且不按任何特定顺序排列”。
故事的寓意:始终在完全相同的 Java 版本上进行开发、测试和部署。

2.javap -verbose ClassName 为我提供了次要版本和主要版本,但是如何
知道该类的更新
编译用??

你不能。类文件甚至不包含该信息。请参阅类文件格式: http://en.wikipedia.org/wiki/Java_class_file

你遇到的问题看起来很奇怪。如果您找到解决方案,请发布您的解决方案。

1.Does the last number in version also make the difference??

No. It should not. However, I have faced issues at runtime due to minor version differences. On further investigation, it was found to be due to incomplete understanding of APIs. The developer was expecting obj.getClass().getFields() to return the fields in the order of declaration and it was working that way in one version. In the newer update it was returning the fields in a different order. The API clearly says that "The elements in the array returned are not sorted and are not in any particular order."
Moral of the story: Always develop,test and deploy on the exact same version of Java.

2.javap -verbose ClassName gives me the minor and major version but how to
know with which update the class is
compiled with??

You cannot. The class file does not even carry that information. See the class-file format: http://en.wikipedia.org/wiki/Java_class_file

The problem that you are getting looks weird. Please post your solution if you get one.

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