Bassam Gemayel

Greenhorn
+ Follow
since Feb 28, 2021
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
6
Given in last 30 days
3
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bassam Gemayel

Hey Jeanne, Scott, Staff team,

In the "Why the Hippo Program Printed C After AB" table

The penultimate sentence says:

"For the exam, you just need to know that a class must be initialized before it is referenced or used."

There is one catch to this rule, using constants in a class.

A constant is a static final variable that either of type primitive or String.

If the constant is defined in the same line as it is declared, the static initializer-blocks are no more called.

It is a corner case, thus, not really useful in real life, just thought I would share it.

For example,



Thanks,

Bassam
Hey Jeanne, Scott, Staff team,

Answer 19 should be A. and B.

binarySearch() will always yield the middle element index if it is a match regardless of whether the array is sorted or not.

I understand the intent is to explain the unpredictability of binarySearch() in case the array is unsorted.

I would suggest changing: B. to B. 0 and F. to F. one output is unpredictable

The term undefined might imply the wrong interpretation.

Thanks for a great book,

Bassam
Hey Jesse,

Use the instanceof type comparison operator for any non-primitive type.

If (koko instanceof T) is true then koko is of type T.

Bassam
Hey guys,

The answer should be A, B, C, F.

Every non-primitive type is of type Object. String is a non-primitive type, making option B correct. koko is both an Object and a String.

Thanks,

Bassam

Jesse Silverman wrote:
In terms of the sentence in the summary on page 208, I would change it to:
'Calling == on String references will check whether they point to the same object'



That would be correct but redundant. You can remove "String" and the statement would remain valid.

Jesse (edited) wrote:
'Calling == on (compatible type) references will check whether they point to the same object'



My intent was to add an informational value and underline the distinction between pooled and non-pooled strings.

Keep it up,

Bassam
@Jesse,

I would use "correct" instead of "precise" when describing an assertion.

"Precise" begs the question of how much precision is requested.

"Correct" is an absolute and does not have varying degrees of intensity or grade.

Thanks again,

Bassam
@Campbell,

We agree.

@Jesse,

The main discussion here is that readers understand that NOT ALL String objects are stored in the String Constant Pool (aka, pool).

Only compile-time constants Strings and Strings interned using the intern() method, are stored in the pool.

The rest of the String objects are stored somewhere else on the heap.

Thank you, both,

Bassam

Hey guys,

The third paragraph states: "Calling == on String objects will check whether they point to the same object in the pool."

This is correct for string compile-time constants, eg. literals, and interned Strings.

This is incorrect for all String objects since the POOL is NOT used for ALL String objects.

Suggested edit: "Calling == on literal or interned String objects will check whether they point to the same object in the pool. "

Thanks,

Bassam

Brilliant! Did not even think about trying this! :-)

Thus, you CAN have multiple classes in the file and they are compiled.

Thank you, Jeanne!

PS.: You and Scott created a gem, I learned faster and more accurately reading your book than I ever did reading any other Java material, kudos!
Hi Jeanne,

The second sentence states that "If two operators have the same level of precedence, then Java guarantees left-to-right evaluation".

This is incorrect as it does not apply to all operators. It does NOT apply to the assignment operators.

The correct statement would be:

"If two operators have the same level of precedence, then Java evaluates the expression left-to-right, except for the assignment operators that are evaluated right to left."

An example is as follows:

int a = 9;
int b = a = 10; //First a is assigned the value 10, Second b is assigned the value of a

Thanks,

Bassam
Hey Jeanne, Ilkay,

The java MyClasses.java option ONLY works for a SINGLE class in the file MyClasses.java.

It is the FIRST class that is declared.

If you have 2 or more classes, they are ignored.

You cannot extend another class in the file MyClasses.java.

If the first declared class extends another class in the same file MyClasses.java, the command will fail.

Hope this helps and thanks,

Bassam