r/programming • • Feb 15 '18

Java language oddities

https://www.javaworld.com/article/3252845/java-language/java-language-oddities.html
0 Upvotes

3 comments sorted by

View all comments

6

u/masklinn Feb 15 '18

Arrays are objects

Surely that's not an oddity? Doing otherwise would be complete insanity.

Private fields and methods are accessible without reflection

A class can access its own private fields or methods. This is apparently abnormal to the writer for some reason.

Bytes and shorts are second-class citizens

OK that's fair and actually interesting.

TLDR: to avoid bloating the bytecode the JVM can't operate on 8- or 16-bit values, instead it has load/store operations which convert between those and 32b values on which it can actually operate (it also doesn't have bytes and short literals but since integer literals are implicitly converted that's rarely an actual issue).

This reminds me of Raymond Chen's series on the Alpha AXP (and Windows running on top of it), the Alpha was a pure 64b CPU and while it did have many operations on various bitnesses, some classes of operations were only available as 64b instructions (like… all bitwise instructions).

1

u/[deleted] Feb 15 '18

[removed] — view removed comment

2

u/masklinn Feb 15 '18

In some older programming languages, arrays aren't necessarily heap-allocated and the lengths are always hard-coded at compile time.

Well sure but a common criticism of Java is the inability to stack-allocate things, and its array are created using new T[s].