Tim Mousaw

Greenhorn
+ Follow
since May 05, 2024
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Tim Mousaw

The flashcard asks:

What is the first parameter type that preparedStatement.setNull() takes?



The answer is correctly int, but the reasoning seems wrong unless I misunderstand the question. It says:

It represents the data type the null value will be stored in.



But isn't it the parameterIndex? See here.
In the last sentence on page 644, it states:

Even when the property wasn't found in en_CA or en resource bundles, the program preferred using Zoo.properties (the default resource bundle) rather than Zoo_en_US.properties (the default locale).



I believe it is imprecise to say that the program prefers using the default resource bundle rather than the resource bundle for the default locale. Unless I'm misunderstanding, the program will never use the resource bundle for the default locale. I tried this out locally by changing the Zoo_en_US.properties file as follows:


Then replacing line 18 of the program with


As I expected, I got a MissingResourceException. Saying the program prefers the default resource bundle over the resource bundle for the default locale could be read to suggest that the resource bundle for the default locale is considered after that.

Paul Clapham wrote:
(Actually "extend from Exception" is close but not quite right. There's a few other classes which can be thrown but I'm a little bit foggy about what they are, so I invite you to research that topic.)



You're right. It's extend from Throwable since you can throw an Error (which is presently the only other class that extends from Throwable). That's the sort of slip of the mind that's going to bite me when I get to this exam!
As I state in the subject, this may be considered a nitpick, but with an exam that tries to trick you at every turn, I thought it might be worth calling out. At the end of the first paragraph on the page under the Throwing an Exception heading, it states:

For example, MyMadeUpException is clearly an exception.



However, this code is perfectly valid and is not an exception:


While I understand your point that many times they'll tell you that there is a custom exception called MyMadeUpException (or similar) and they don't expressly show you the code for the exception, I wouldn't put it past the exam designers to show you a code listing with the code above as well as something like:

and then expect you to know that you can't throw a class that doesn't extend from Exception.
@Piet
Yes, that's perfectly legal. You're taking an instance of a String and calling the equals method on it with a method reference. If used in a stream method like filter assuming strings in a collection it would filter for all Strings that were Yes (case sensitive, or else you should have used "Yes"::equalsIgnoreCase).
The relevant paragraphs are as follows:

Lambda expressions, or lambdas, allow passing around blocks of code. The full syntax look like this:


The parameter types can be omitted. When only one parameter is specified without a type, the parentheses can also be omitted. The braces and return statement can be omitted for a single statement making the short form as follows:


While I understand this shows the most abbreviated form, it begs the question of where b comes from. And using the same body as the full syntax may lead to one believing the latter is intended to be the short form of the former. It may be more straightforward to use a different body (e.g. a -> a.toUpperCase())

The summary gives the full syntax of a lambda expression as:


It then goes on to describe the syntax of the short form and gives the lambda as:


While this could be valid assuming b is defined in an instance variable, static variable, local variable, or method parameter (for local variable and method parameter, only if final or effectively final) in code that is omitted, it seems more logical to think the authors intended to show the abbreviated form of the previous full syntax. That is:

I wasn't questioning whether between truncates. I was simply asserting the statement didn't follow as rounding would have the same net effect.
The full context is as follows. The line the paragraph describes is:


The full paragraph is:

In the fourth example, we start with the third rule, which tells us to consider 1 + 2. Both operands are numeric, so the first rule tells us the answer is 3. Then we have 3 + "c", which uses the second rule to give us "3c". Notice all three rules are used in one line?



I suppose the authors' intent could have been, "Do you notice all three rules are used in one line?". Like I noted in the topic, it's minor and probably doesn't make a large amount of difference. In my opinion, it reads more to me like a statement rather than a question. But I could see an argument that the question mark is intended.
In the sidebar on page 203 it states:

...


The first print statement shows that between truncates rather than rounds.
...



However, the result would be 1 even if it rounds, so the first print statement doesn't actually show that...
At the end of the fourth paragraph, it states:

Notice all three rules are used in one line?



This is a statement and should use a period at the end of the sentence.

Try changing the encoding to platform default and to UTF‑16 and see what happens.



Notepad++ supports both UTF-16 big-endian and little-endian. I updated the default to these and compiled the same program and got many errors. I'd include the errors below, but it makes the post too long. If I compile either of these files with the -encoding UTF-16, they compile and run just fine in Git Bash.

I also tried the same file in Ubuntu 22.04.3 LTS on WSL 2. Created it using the vi editor. It compiled and ran on my Linux installation no problem without specifying the encoding.

In reality, many different text editors use many different encoding settings. I think in Notepad++ you can configure the encoding to use for new files, so if you set it to the system locale's default encoding, you won't have to specify the -encoding option when calling javac.



I checked my preferences in Notepad++ using Settings -> Preferences -> New Document and the default is already set to UTF-8. So, I'm confused why this doesn't just work assuming javac pays attention to the encoding of my source file.

But the easiest way to deal with all of this is to simply limit the characters you use in source files to those that can be encoded in 7-bit ASCII.



Unless I'm mistaken, there's no way to render € with 7-bit ASCII. While I understand what you are saying, limiting myself to 7-bit ASCII seems to make the point my post impossible.
I used Notepad++ and the file itself is UTF-8 encoded. At least, according to Notepad++ it is...
Ah, I just re-read this and realize my mistake. It says it is in scope only inside the initializer. Not that it is in scope on line 7.