4

'javac' is the Java compiler which converts java code(.java) into bytecode(.class).

According to Oracle

  • The compiler accepts source code defined by the Java Language Specification (JLS)
  • and produces class files defined by the Java Virtual Machine Specification (JVMS)

Does the same 'javac' come with all the JDKs like OpenJDK, Oracle JDK or they implement their own 'javac'?

Community
  • 1
  • 1
Aman Arora
  • 1,232
  • 1
  • 10
  • 26
  • `javac` is compatible between all compliant JDKs. There are different Sun/Oracle versions with different JDK versions, and I think there is at least one "open source" version. But the code produced by any `javac` version should be compatible with any JVM so long as the target version specified/defaulted on the `javac` command is equal to or less than the version of the JVM. – Hot Licks Nov 28 '13 at 15:27
  • OpenJDK and Oracle JDK should be based on the same codebase anyway. I'd wager that there is no difference between the compilers at all, Oracle JDK could just include some non-free classes in the runtime library. – millimoose Nov 28 '13 at 15:28
  • Now, Eclipse's `ecj` compiler does actually have some notable differences. For one it seems to be capable of emitting (for development purposes) bytecode for source code that only partially compiles somehow, IIRC by replacing the broken parts with stubs that throw an exception. This means it's possible to write (invalid) Java code that (kinda-sorta) compiles but that another compiler will reject completely. (Although this assertion relies a fair bit on playing with semantics.) – millimoose Nov 28 '13 at 15:33
  • ideally all java compilers should *behave the same* – ZhongYu Nov 28 '13 at 17:43

3 Answers3

0

Yes it is same in all the JDKs except for a few minor bugs and changes. Javac is not vendor specific, but yes, different compilers can have different bugs in their own implementation and this can cause a slight difference.

So it is possible that a code compiled in one JDK 'may' not compile in the other in the JDK, thus when switching between JDK's it is best to do some rigorous testing to make sure that everything is working fine

Saif Asif
  • 5,516
  • 3
  • 31
  • 48
  • 3
    Any reference stating the same will be a help. Thanks – Aman Arora Nov 28 '13 at 15:11
  • These similar posts maybe helpful [link_one](http://stackoverflow.com/questions/4696611/jdk-jre-java-version-confusion?lq=1). [link_two](http://stackoverflow.com/questions/8705061/is-the-openjdk-jvm-the-same-as-the-oracle-java-se-jvm?lq=1). [link_three](http://stackoverflow.com/questions/1977238/why-should-i-use-the-oracle-jdk-over-the-openjdk-or-vice-versa?lq=1) – Saif Asif Nov 28 '13 at 15:22
0

As far as I could find searching, wikipedia compilers list only have 5 Java compilers listed and of them, Javac is the only one that would be used by the JDKs you listed. Probably IBM's JDK would use their own compiler. I've not find any link or reference for the IBM assumption but it would make sense.

Jonathan Drapeau
  • 2,610
  • 2
  • 26
  • 32
0

It tends to be the same Java compiler in all modern JDKs - but Eclipse uses its own Java compiler, not the JDK's compiler.

Robin Green
  • 32,079
  • 16
  • 104
  • 187
  • Any source to back that java compiler is same in all the JDKs? – Aman Arora Nov 29 '13 at 12:39
  • No, but the JDK was open sourced as OpenJDK, and anyway, even before that happened, third-party JDKs often found it cheaper to license Sun's implementation and modify it than to write their own from scratch. – Robin Green Nov 29 '13 at 15:57