This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin Cookbook and have Ken Kousen on-line!
See this thread for details.
Win a copy of Kotlin Cookbook this week in the Kotlin forum!

Campbell Ritchie

Marshal
+ Follow
since Oct 13, 2005
Cows and Likes
Cows
Total received
255
In last 30 days
0
Total given
571
Likes
Total received
6428
Received in last 30 days
47
Total given
377
Given in last 30 days
8
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Campbell Ritchie

Are you still allowed to use newInstance()? That link suggests an alternative because of problems with exception handling.
48 minutes ago
The gory details are all in the JLS (=Java® Language specification). It says that a protected member or constructor is accessible in code responsible for the implementation of the object. So an instance method or constructor or instance field declaration (I think) can use that protected member or constructor, but a static method can't. Nor can other classes in a different package access a protected member or constructor in a class inhering it from a superclass in a different package. There are more restrictions; see the JLS link.

It may be bad practice to use a protected member or constructor method in a constructor.

[edit]Strike out some text and add “method”.
53 minutes ago
If they don't contact you soon, you will have to assume you have been unsuccessful with your application.
1 hour ago
Get yourself a copy of Java Puzzlers, Excellent book. Or borrow Liutauras' copy. You can't have mine, which I have now found.
Let's see what it says. Obscuring appears on pages 163‑167 and page 182. I read page 163 and knew why I have seen that sort of code before: OP: please always tell us where code comes from. Maybe somebody showed you that code and didn't tell you where it came from. You will find the version with casting nulls on page 166.

Bloch and Gafter pages 163‑164 wrote:. . . . Does the program print Black? Does it print White? Is it even legal?. . . The compiler generally rejects ambiguous programs . . . . it should be illegal . . . it is legal and prints White. . . . When a variable and a type have the same name . . . the variable name takes precedence. . . . obscure the type name.
. . . To remove all ambiguity . . . simply rewrite it to obey the naming conventions. . . .
Their emphasis.

There is a lot more; you will have to read the original to get that section in its full glory.
The book quotes two Java® Language Specification (=JLS) sections:- JLS‑§6.5.2 and JLS‑§6.3.2 (nowadays §6.4.2). They also say that class names like UUID or URL or URI would be better spelt in mixed case than upper case.
Sorry to be the bearer of bad news, but you will have to look on that as, “Is that a no then?”
2 hours ago
That table is slightly inaccurate about protected access. There are some circumstances when a protected class member/constructor is invisible in a subclass.
3 hours ago
Welcome to the Ranch and good luck fining the right person for your job.

Please note we require a location in the thread title for all job offers (“distance working” or similar is permissible), so please go back and edit the thread title.
3 hours ago
Don't know. I don't however think you will get anything by waiting; applications are sifted pretty quickly.
3 hours ago
Welcome to the Ranch

I suggest you show us the code you are running please. “Wrong name” errors are often caused by having a package name in the code and putting the .class file in a folder with a name different from its package. As JJ says, you can run an uncompiled single XYZ.java file in Java11+; the fact that it isn't complaining suggests your .class files have a different name. Please copy'n'paste the text from your command line in future because it is much easier to handle like that. I can't see the screenshot from here, and had to open your post twice.
3 hours ago
Line 6 isn't a statement; it might be if it had a second ; at the end of it in which case it might become a kind of expression statement. Please check carefully what the book says, to verify where the actual error is.
11 hours ago

Ankit Garg wrote:. . . On the certification exam? . . .

No. Maybe in Java Puzzlers, but I can't check that until tomorrow.

Stefan Doe wrote:. . . Can this be considered a lack of consistency?

No. The internal representation of a float number is different from a double. They are both kinds of IEEE754 numbers, however.
An int and a long both have the same internal representation (two's complement), only different sizes.
Welcome back I have a book about Modern Java Recipes which I find very useful.
20 hours ago
It would allow the implementation of the writeObject, writeResolve, readObject and readResolve methods to test for serialisability using something like if (!obj instanceof Serializable) ...

[edit]I am leaving it as an exercise for the reader to find the error in my post.
Welcome to the Ranch Thank you, Ron, for finding the complete code.

Jonathan Graef wrote:. . . my processor has an internal advertisment for 2 gigahertz. I get 5 megs. Where did they all go?

Divide your 2GHz by 400 ticks per operation and you will get 5MHz.
Don't know any more about that.
1 day ago