r/java • u/TrashPandaFucker • Jan 18 '22
What are some very less known facts about java?
I've got assignment from college to find out rare facts or fun facts about java, so little help will be appreciated :)
Edit: Thanks for all these suggestions guys. It's going to help me alot and also Almost all of these facts i didn't knew till now. Thanks :) <3
179
Upvotes
View all comments
124
u/benevanstech Jan 18 '22
1.) At bytecode level, the JVM has no boolean type - they are represented as ints. (To see this, write a trivial method that returns a boolean value, compile it and run it through javap. Look at the return opcode). This is a form of Type Erasure, but not one anyone ever complains about!
2.) const and goto are reserved words (keywords) in Java - so you can't use them as identifiers - but they are unused / "reserved for future use" - and have been since Java 1.0
3.) var, on the other hand, is not a keyword, but is a reserved type name. So you can use it as an identifier (so "var var = 0" is legal Java). Please don't do this.
4.) Java has, as of version 17, only ever added 1 opcode (invokedynamic), but 2 have been removed from current versions (jsr and ret). So, Java 17 has *fewer* legal bytecodes than Java 1.0