0

JRE is implementation of JVM specification and has to be platform dependant.

One of the main purpose of JDK is to compile source code and produce .class files. Is JDK written in Java ? If yes , why do we have different jdk for different OS.

Or is JDK written in C or some other language with implementations specific to OS ( Windows / MAC etc )?

lives
  • 1,243
  • 5
  • 25
  • 61

3 Answers3

1

Large portions of the JDK consists of native code, that needs to be compiled to be able to run on the target platform. In theory, toolchain and operating system should be independent factors, but in practice there's more or less a one-to-one correlation between target operating system and toolchain. (see official documentation https://openjdk.java.net/groups/build/doc/building.html)

Reto
  • 1,305
  • 1
  • 18
  • 32
0

Most JDK implementations are mostly written in Java, but have some natively implemented methods (e.g., most methods in java.lang.Object).

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • 1
    Other good examples are the nio and network libraries, which interact with the native APIs of the underlying operating system. – Jorn Vernee Jun 26 '21 at 13:09
-1

why do we have different jdk for different OS.

Minimally, because a JDK normally includes a JRE, and JREs are necessarily system dependent.

Additionally, it is common for some of the JDK components outside the JRE, such as the Java compiler, to be implemented with native code.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157