Java language oddities
javaworld.com
javaworld.com
http://example.com/ showNotification();
It compiled without problem because http: is label and // commented out the rest of the line:)
switch (whatever)
{
E_START:
// code
break;
E_PAUSE:
// code
break;
E_END:
// code
break;
}
i.e. accidentally using labels instead of "case E_START:". GCC at least had the decency of generating a warning about unused labels, while I suppose `javac` does no such thing.This mistake (unsurprisingly) isn't possible in Java:
"Syntax error on token "{", case expected after this token"
With an unused label I get the warning "The label E_START is never explicitly referenced"
A good software process prevents these types of errors. You shouldn't have any warning in your project at all, and if you see one you'll know to check it out. You should use @SuppressWarnings for any warnings you have reviewed and have determined are not errors. Your IDE should mark warnings clearly at the project level, the file, and the offending line. They also should have an overall list of warnings (and errors) and you should go through them before building a release.
That’s the definition of private, that only the declaring class can access. I believe the main beef is that one object _can access_ another object, even though they are the same type. That makes perfect sense to me. How else would equals and hashcode work?
I desperately need better nomenclature, but it is essentially what I think of as "implementation hiding for security and reliability reasons". You specify a small-ish set of methods that depend on the internal state of only this object, you verify their goodness, and then calmly implement all other operations in terms of those.
Then Java is based on "implementation hiding for maintainability reasons" -- i.e. it's really important that if you refactor something private in a file, your commit should only have to mention that file, and no other file can depend on private members in other files.
In this case, the "reliabiliy" perspective confers greater maintainability, at least in one dimension. On the other hand, much lower flexibility, as several people have mentioned already.
In some loose sense, it's the distinction between a syntactic perspective (boundary crossing happens at the file level; the characters on screen determine what implementation hiding means) and a semantic perspective (the objects should occupy an utopia where they do not distinguish between each other based on class, if you excuse the pun. What matters is their allowed behaviour and that interaction.)
I am afraid I have failed to express this in neutral terms because of my preexisting biases, but I hope the idea comes across anyway.
It also makes perfect sense to me. Visibility is type-based, not instance-based. But to answer the hypothetical question: one would have to introduce class-private (package private?) getter methods for all relevant truly-private fields. I'm happy that's not the case.
"protected" stuff can be accessed by classes in the same package, even if they not inherit the class with the "protected" member. I find this very annoying as I use protected and package-private for entirely different semantics.
No scope qualifier means package-private for classes and public for interfaces. I never could wrap my head around this. That's bad user interface design. As well, I have package-private interfaces sometimes (which is perfectly possible), but their methods can only be public (which is unwanted if the interface is package-private).
Legend goes that Gosling went around Sun offices and almost everyone failed to get unsigned versus signed math right, so they went with signed only types.
http://www.gotw.ca/publications/c_family_interview.htm
> Quiz any C developer about unsigned, and pretty soon you discover that almost no C developers actually understand what goes on with unsigned, what unsigned arithmetic is. Things like that made C complex. The language part of Java is, I think, pretty simple. The libraries you have to look up.
At least Java 8 introduced unsigned math helper methods.
Except chars
> At least Java 8 introduced unsigned math helper methods.
They still aren't enough IMO. They don't have way ways to take LE/BE bytes out of integers or vice versa (not worth creating ByteBuffer for). I always end up recreating these utilities in projects where it isn't worth depending on or shading an entire Guava, e.g. [0]
0 - https://github.com/cretz/javan-warty-pig/blob/master/fuzz/sr...
I have to ask, why would you be trying to, I presume, be directly manipulating bytes in Java?
Video / audio codecs.
Cryptographic algorithms. (encrypt / decrypt, hash functions)
Cryptographic random number generators.
Ordinary random number generators.
PKI (key generation, validation)
Packing / unpacking binary structures used in wire protocols or message formats. (Example: a certificate, public key, jpeg, protocol buffers)
Implementing things like Protocol Buffer. (Language neutral binary format)
Implementing BigInteger. JDBC drivers.
Java libraries that create, compile, decompile or otherwise manipulate Java Byte Code.
Java libraries that create or manipulate other types of binary executable code. (eg, an EXE file)
Implementing Class Loaders for java.
The reasons you might work with bytes in Java are as endless as why you would work with bytes in C or any other language.
Thank you for the reminder!
Thanks for answering!
I’m sure you’re aware of all this and I don’t want to backseat drive/code. It’s just I was on a project once where microsecond latency mattered and it was written in Java, but with a custom String class and custom garbage collection (using a custom object pool instead of relying on JVM’s to avoid any GC halt, which would be intolerable). It was a really fun project tech wise, but at that point, C/C++ would have made wayyyyyy more sense and saved us a lot of headaches.
https://www.ptc.com/en/products/developer-tools/perc
https://www.aicas.com/cms/en/JamaicaVM
https://www-03.ibm.com/software/products/bg/real-time
Then there are the Java variants out of Mountain View, although Android's performance is not in the same league as those ones.
This are just the most well known ones, Java is not only the OpenJDK.
As for microsecond latency, I guess it matters a lot to the US military.
http://www.militaryaerospace.com/articles/2006/10/lockheed-m...
"PERC Ultra offered Lockheed Martin the responsiveness it needed to meet its most demanding timing requirements. In addition to real-time threading and deterministic garbage collection, PERC Ultra provided the instrumentation and VM management tools necessary to support the mission-critical real-time requirements of the Aegis Weapon System."
"The Lockheed Martin-developed Aegis Weapon System is the sea-based element of the U.S. Ballistic Missile Defense System. The Aegis Weapon System is a radar and missile system integrated with its own command and control system, capable of simultaneous operation defending against advanced air, surface, and subsurface threats."
Edited: but Yes, and they're not the only ones that did radar or embedded software with PERC. There was a time (5-10 years ago ?) it was all the rage...
[0]: https://www.amazon.com/Java-Puzzlers-Traps-Pitfalls-Corner/d...
For 'Object x', x is nothing but a (typed) pointer.
Pointer manipulation is heavily limited, but technically, Java has pointers.