0

I have a java jar file and I am trying to know in which platform (x86 or x64) it was generated for.

Basically I want to know if this jar file is x86 or x64.

How can I do this?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Willy
  • 9,848
  • 22
  • 141
  • 284

1 Answers1

3

Assuming this is a pure Java application without native dependencies, you don't need to know this. In fact, there is no such thing to determine as Java is compiled to a platform-independent byte-code for the Java Virtual Machine. It will work on any Java JVM (assuming it supports the target version of the compilation) irrespective of the underlying CPU platform.

Judging by your post history, you're used to working with C#/.NET, which compiles to x86/x64 or AnyCPU. Java has no such distinction. The only thing that is platform-dependent is the JVM and the JDK. Once compiled, your code can run on any CPU platform that has a JVM.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • so then why exists jdk for x86 and jdk for x64 available if it is platform-independent byte-code? and how can i know the target version of compilation? is it possible? – Willy Mar 03 '22 at 20:46
  • 1
    See [How can I find the target Java version for a compiled class?](https://stackoverflow.com/questions/698129/how-can-i-find-the-target-java-version-for-a-compiled-class), and [How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version](https://stackoverflow.com/questions/10382929/how-to-fix-java-lang-unsupportedclassversionerror-unsupported-major-minor-versi) for a list of class versions to Java versions. – Mark Rotteveel Mar 03 '22 at 20:50
  • 2
    The JDK is the JVM + compilation tools. It targets a specific CPU, so its runtime JIT can target the features of that CPU, and an x64 JVM can target a lot more memory than an x86 JVM (and the same goes for compilation tools). But the javac of a x86 JDK and a x64 JDK will output identical byte-code. So, contrary to C#, with Java the only platform-dependent part is the JVM (and other tools), the compiled code is platform-independent. You can compile on an Intel x86, and run the resulting byte-code run on x86, x64, aarch64, arm32, s390x, ppc64le, or any other platform that has a JVM. – Mark Rotteveel Mar 03 '22 at 20:53