henry leu

Greenhorn
+ Follow
since Apr 23, 2016
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
6
Received in last 30 days
0
Total given
7
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by henry leu

Jeanne Boyarsky wrote:The NumberFormat class lets you specify formatting.  One of its format methods takes an Object as a parameter.  That Object can be a BigDecimal.



Hi Jeanne,

I also have the similar question to your answer above.

I see lots of programming book use NumberFormat class's format() method to format the BigDecimal object.

For example,




I check the documentation on Oracle's website. format() method in NumberFormat class only takes long and double as 1-argument. But why is BigDecimal is also valid as argument in format()?

Thanks!
2 days ago
Hi,

I see lots of programming book use NumberFormat class's format() method to format the BigDecimal object.

For example,


I check the documentation on Oracle's website. format() method in NumberFormat class only takes long and double as argument. But why is BigDecimal is also valid as argument in format()?

Thanks!
Hi,

1. What is the rounding technique used for Math.round()? I believe it is using HALF-UP rounding (The one we used to learn in elementary school).

2. I know float data type holds 7 significant digits and double holds 16 significant digits. However, when I tested it, the output looks weird.



output:
3.141592653589793 (why double type only outputs 15-significant digits? not 16 significant digits?)
3.1415923 (why is the 7th significant digit 3? What rounding technique does it use?)
3.141593 (why only shows 6-significant digits? not 7?)
1 week ago
Hi,

What does string concatenation return? Does it return from string pool or return a new String object?
I know when two string literals concatenates, it is in string pool.





Thanks,
Henry
Hi,

I'm studying Java 8 OCA 1Z0-808 using the book by Jeanne Boyarsky and Scott Selikoff.

Chapter 3 review question #19 says:

Which of the following are true? (Choose all that apply)
A. Two arrays with the same content are equal.
B. Two ArrayLists with the same content are equal.


Correct answer is A and B.

But why B?
If 2 same content ArrayLists using ==, they are NOT equal.
But if 2 same content ArrayLists using equals() method, they are equal.
Hi,

Can I assign "arrray" object to "non-array" object? I know the answer is no. But why the following code compiles?



Thanks,
Henry

henry leu wrote:Thanks for all the answers!

But I still have one question.

After line 2, we should have 2 Strings objects in the heap, right? "java" and "c++". What about after line 3? Do we get 2 String objects or 3 String objects on the heap?

For line 3, s2.intern() will check the string pool table and see if "c++" exists. This case it doesn't exist. So "c++" will be added to the string pool. Now, will Java create another new String object on the heap, another "c++" object?

What reference will s3 receive?

henry leu wrote:Thanks for all the answers!

But I still have one question.

After line 2, we should have 2 Strings objects in the heap, right? "java" and "c++". What about after line 3? Do we get 2 String objects or 3 String objects on the heap?

For line 3, s2.intern() will check the string pool table and see if "c++" exists. This case it doesn't exist. So "c++" will be added to the string pool. Now, will Java create another new String object on the heap, another "c++" object?

What reference will s3 receive?



See the attached picture for my understanding of the code above. Please verify if this is correct.

Thanks!
Thanks for all the answers!

But I still have one question.

After line 2, we should have 2 Strings objects in the heap, right? "java" and "c++". What about after line 3? Do we get 2 String objects or 3 String objects on the heap?

For line 3, s2.intern() will check the string pool table and see if "c++" exists. This case it doesn't exist. So "c++" will be added to the string pool. Now, will Java create another new String object on the heap, another "c++" object?

What reference will s3 receive?

Hi,

I'm studying Java 8 OCA 1Z0-808 using the book by Jeanne Boyarsky and Scott Selikoff.

In chapter 3 page 111, I am confused about whether it is string pool or String object. See the following code.
The book says it will create 27 String objects and these 27 String objects will be immediately available for garbage collection.
So my guess is, "" is a String object? Line 10. It looks like a string literal to me and should be in string pool?
And also any String concatenation is String object? Line 12
Another question is that I know String object can be garbage collected. What about literals in the string pool? Do they get garbage collected?



Thanks,
Henry
Hi,

I've learned that the switch value and the case value must have the same data type. But the following example do compile and run without error. Please advise. Thanks!


1 year ago
Hi,

I'm using the Oracle Certified Associate Java SE 8 Programmer I by Jeanne Boyarsky and Scott Selikoff. I am confused at the answers they provide to the questions on page 331, questions 17 and 18.

See attached pictures for the questions and answers. I think the answers are incorrect.

Problem #17: the answers are A, C, D, E. But why not B also? The roar() method's exception HasSoreThroatException extends Exception. I think B works too. No?

Problem #18: the answers are A, B, C, E. But I think A is incorrect. I think check exceptions MUST be handled and declared. Not ALLOWED.



[edit] removed images
So I cannot catch a checked exception if there is no checked exception thrown in the try block?
In another word, I can catch un-checked exception even though no exception is thrown in the try block?
1 year ago
Hi,

I don't understand the following code. Why doesn't it compile at the catch? Compiler says NoCarrotException is never thrown in the try statement. NOTE: NoCarrotException class is the user declared exception class.
But does it matter? If I use Exception in the catch parameter, it compiles.

1 year ago