Henry Wong

author
+ Follow
since Sep 28, 2004
Henry likes ...
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
New York City
Cows and Likes
Cows
Total received
140
In last 30 days
0
Total given
665
Likes
Total received
2231
Received in last 30 days
0
Total given
328
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Henry Wong

Sanjana Senthil wrote:
Hey everyone, I keep getting a syntax error for the else statement....i'm pretty sure my curly brackets are fine .....help would be very appreciated!



There is no such a thing as a while-else statement (meaning else following while) in Java.

Henry
2 weeks ago

Vaibhav Gargs wrote:
Hi Campbell, I am not sure if any such CPU exists but since these are some special instructions such as CAS etc. which made me think that these instructions will be supported by all CPUs or not?



The CAS instruction is supported by all modern day processors. Keep in mind that the CAS instruction is also needed by the JVM to implement synchronization, so, if the CAS instruction doesn't exist (like with really old JVMs), then a work around has already been implemented.

Henry

Arun Singh Raaj wrote:what kind of lock system does AtomicInteger uses?



The AtomicInteger class uses a technique call "optimistic locking". This means that there isn't any locks...  

Instead, there is a mechanism that is used to detect collisions -- and of course, if it does collide, then there is a mechanism to resolve it (which is just to retry the operation, in most cases). The idea is... since a collision will not happen for a majority of cases, it will run really fast (since there isn't any locks).

Henry

First, a big thanks to Roberto Infante for being here to promote the book Building Ethereum DApps: Decentralized Applications on the Ethereum Blockchain.

The winners are:

   Michael Krimgen
   Joe Cortee
   paul nisset
   ludoviko azuaje

Please send your snail mail address to bookpromotion AT javaranch DOT com. To ensure the quickest response, please provide the following:

Your name (first and last - if your CodeRanch name is different, please include both your real name and Ranch name)
Email
Country (needed even if requesting an e-book)
Address
Phone Number


Also, please include the following as the subject of your Email.

Book Promo Winner - Building Ethereum DApps: Decentralized Applications on the Ethereum Blockchain - Tuesday, May 14th, 2019


Image from https://m.media-amazon.com

As noted in the Book Promotion Eligibility Requirements and Legal type stuff, the winners have 8 days to submit their information. Within 3 days of receipt of your email, we will reply to let you know we got it. If you don't hear back, the goat might have eaten your email. Please let us know by posting in the Ranch Office so we can check on it. Once you have received your copy please let us know by editing the Book Promotions Winners Page and updating the 'Status' column to say you have it.

Thanks and congrats to all the winners.
1 month ago

This week, we're delighted to have Roberto Infante helping to answer questions about the new book Building Ethereum DApps: Decentralized Applications on the Ethereum Blockchain.


The promotion starts Tuesday, May 14th, 2019 and will end on Friday, May 17th, 2019

We'll be selecting four random posters in this forum to win a free copy of the book provided by the publisher, Manning Publications.


Image from https://m.media-amazon.com

Please see the Book Promotion page to ensure your best chances at winning!

Posts in this welcome thread are not eligible for the drawing, and should be reserved for welcoming the author. Questions posted in this topic are subject to removal.
2 months ago
Integer objects are immutable. You can't just increment it. When you do that in Java, the compiler will generate code (as syntactic sugar) to unbox, increment, and box the value again. This means that it is a completely different object after the increment.

And in your application, which has different references pointing to what was originally the same object -- they are now different references pointing to different objects (with different values).

Henry

John Losty wrote:

Then at runtime, order of evaluation is always left to right: ...



also this isn't clear to me as at some point he stopped evaluating from left to right and first evaluated inside brackets.



Actually, this is not true. Others have already posted information on how to interpret the evaluation, so, I will not continue on that... except to add...

Evaluation to completion are not equal -- meaning it takes longer to complete evaluation of a longer sub expression (either with parenthesis, or added parenthesis which were done to respect precedence/associativity). When the Java specification states that the evaluation is done "left to right" (in addition to the rules on respecting precedence/assoc, parameters, etc.), it is referring to when the evaluation of the sub expression starts -- and not when it completes.

If you review Stephen's example again, and look at when the evaluation starts, you will see that he is indeed, evaluating left to right.

EDIT: Okay, in reviewing again, it may not be that easy to see. If I have time later, I will do a quick write up, and the start points, and how it is left to right.

Henry
2 months ago

John Losty wrote:

in this case (after respecting parens, precedence, and assoc), requires that the left operand be evaluated before the right operand.

How do you apply it?



Stephen already showed you how it is done. He converted all the precedence/assoc rules into parenthesis -- so, it is easier to apply. Then, he showed you how it was done (evaluated) -- meaning the parens are used to determine the left and right operands for evaluation.

Henry
2 months ago

John Losty wrote:
you could go on like that as well?



Actually, no. The Java specification, in this case (after respecting parens, precedence, and assoc), requires that the left operand be evaluated before the right operand. So, the "2 * ( 2    - (--5))" sub expression, must be done (started and completed) before the "a" sub expression.

Henry
2 months ago

Robert Voorn wrote:
This explanation does not make sense to me: it could also be List<Exception> (in fact, it IS), and that would certainly fit
an Exception object, wouldn't it.

Can anybody explain it more clear to me? Thanks in advance.



Yes, it *could* be a List<Exception> ... but ... the compiler doesn't know that. The rules of wildcards does not have rules that searches other parts of code to find out exactly what type it is. It can only use the reference to determine the type. If you are going to use wildcards, you have to code with this lack of information, which means that you have to code that all cases will work.

Henry
2 months ago

First, a big thanks to Yan Cui for being here to promote Production-Ready Serverless (Operational Best Practices). It's a shame that we didn't get many questions...

The winners are:

   Carl Byrd
   Timur Radzhabov
   Divya Shiv

Please send your snail mail address to bookpromotion AT javaranch DOT com. To ensure the quickest response, please provide the following:

Your name (first and last - if your CodeRanch name is different, please include both your real name and Ranch name)
Email
Country (needed even if requesting an e-book)


Also, please include the following as the subject of your Email.

Promo Winner -  Production-Ready Serverless (Operational Best Practices) - Tuesday, April 16th, 2019


Image from https://images.manning.com

As noted in the Book Promotion Eligibility Requirements and Legal type stuff, the winners have 8 days to submit their information. Within 3 days of receipt of your email, we will reply to let you know we got it. If you don't hear back, the goat might have eaten your email. Please let us know by posting in the Ranch Office so we can check on it. Once you have received your copy please let us know by editing the Book Promotions Winners Page and updating the 'Status' column to say you have it.

Thanks and congrats to all the winners.
2 months ago
This week, we're delighted to have Yan Cui helping to answer questions about the new Production-Ready Serverless (Operational Best Practices).


The promotion starts Tuesday, April 16th, 2019 and will end on Friday, April 19th, 2019

We'll be selecting four random posters in this forum to win a free copy of the electronic book/resource (video) provided by the publisher, Manning Publications.


Image from https://images.manning.com

Please see the Book Promotion page to ensure your best chances at winning!

Posts in this welcome thread are not eligible for the drawing, and should be reserved for welcoming the author. Questions posted in this topic are subject to removal.
2 months ago

Ana Yo wrote:Sorry I meant to say why the array did not change at all.



Well, the array did change. It changed and changed back.

Basically, during the first iteration of the loop, it flipped the first and last elements. And during the last iteration of the loop, it flipped the last and first elements. Anyway, I will let you work out the other iterations of the loop.

Henry
3 months ago

rian bron wrote:
but here i do specify which constructor of the superclass to use , because there is only 1 constructor in the superclass in this case, why would it be by default then?
do i must to use the java word "super" to gain access to the superclass constructor?



Java follows the rules of its specification. And there isn't a rule that does what you want, and in the way that you want it -- meaning call the superclass constructor, using the parameters of the subclass constructor parameters, but in a different order. If you want that, you will have to do it yourself -- something like this...



Henry
3 months ago