Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

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
8
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by henry leu

Carey Brown wrote:"EventHandler" is a standard class, not an interface, nor abstract.



To Carey Brown, EventHandler is indeed an interface. See this link.

EventHandler Java 9
1 month ago
Hi,

From my knowledge, abstract class and interface class cannot use "new" key word to instantiate an object, right?

The following is an example of using anonymous class for the EventHandler.

Why does setOnAction() method take on a new EventHandler interface object? I know setOnAction() takes EventHandler object.



Thanks,

Henry
1 month ago

System.out.println(super.toString())



Actually, the above code that you mentioned compiles.
2 months ago
Hi Albert,

Thanks for the reply.

However, I have "this" in super class, not in sub class. And also, I'm not overriding print() in sub class.

So my understanding of polymorphic is when I use sub class variable to call print(), program will see that in my sub class, I don't have any print() or overridden print(). So program will go see the super class's print(). Now it ACTUALLY calls the print() in super class. But when it calls the "this", it will print the sub class information, not the super class object information?
2 months ago

henry leu wrote:When sub class inherits from super class, it automatically inherits super class's method.
I try to test it out the "this" functionality. I try to print out the super class object information from the sub class. Why doesn't "this" refer to SuperClass object, but it refers to SubClass object?








Output:

SubClass@1d251891



and the output is also the same for the Super Class to be like this...



2 months ago
When sub class inherits from super class, it automatically inherits super class's method.
I try to test it out the "this" functionality. I try to print out the super class object information from the sub class. Why doesn't "this" refer to SuperClass object, but it refers to SubClass object?








Output:

SubClass@1d251891
2 months ago

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!
3 months 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!
3 months ago
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?)
3 months 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?