Henry Wong

author
Sheriff
+ Follow
since Sep 28, 2004
Henry likes ...
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
Forum Moderator
Henry Wong currently moderates these forums:
New York City
Cows and Likes
Cows
Total received
125
In last 30 days
0
Total given
628
Likes
Total received
2145
Received in last 30 days
8
Total given
324
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Henry Wong


Personally, I think that your manager may have messed up.  Yes, "happy" employees are likely better employees, in terms of motivation. However, he/she got the cause and effect backwards. Happy employees smile more. Agreed. On the other hand, employees that smile more (due to being told to) aren't going to be happy employees...

Henry
1 week ago

First, a big thanks to Daniela Sfregola for being here to promote the new MEAP book Get Programming with Scala.

The winners are:

    paul nisset
    Alex Khvatov
    Will Myers
    Thomas Zink

Please send your the following to bookpromotion AT javaranch DOT com to claim your electronic prize:

Your name (first and last - if your CodeRanch name is different, please include both your real name and Ranch name)
Your email address
The name of the country that you reside in


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

Winner - Get Programming with Scala - Tuesday, Feb 6th, 2018

Please send your e-mail address to bookpromotion AT javaranch DOT com to claim your electronic prize.


Image from unknown

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 week ago
In my opinion, the Java Language Specification is complex enough as it is -- to add more checks that yields little is a bit silly.

The reason the <T extends Integer> generic is allowed is because it is possible to find a T that satisfies the bound. And even it can't (as with some interfaces) it can only do the checks as specified.

To add a check that if you find a T, and that T is final, and the bound is not an interface, etc. then it should be an error -- well, like I said the JLS is already complex enough as it is. It may be added in the future, but I wouldn't hold my breath.

... and also, how would the JLS word it? Yes, it is a valid bound, but since there is only one possible case, due to "final", this is inefficient, so, it will be an error (or warning)?

Henry
1 week ago

This week, we're delighted to have Daniela Sfregola here to launch the new MEAP (Manning early access program) book Get Programming with Scala and answer questions about it. 

This innovative program allows subscribers to fast-track their knowledge on a particular by reading a book chapter-by-chapter as it is released.  Receive the final eBook as soon as it's finished.

The promotion starts Tuesday, Feb 6th, 2018 and will end on Friday, Feb 9th, 2018.

We'll be selecting four random posters in this forum to win a free MEAP subscription provided by the publisher, Manning.


Image from unknown

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 weeks ago

Hate to throw a monkey wrench into this discussion, but JMS has both topics and queues. Consumers are for queuing. Subscribers are for topics. And yes, it is possible to create a listener for a subscriber.  Hence, it is possible to create a listener without the need to have a consumer...

Henry
2 weeks ago

raja singh kumar wrote:

The iteration order is ordered by some feature depending on the hash code.


Then how can you say a hashset is not ordered or sorted? I am still not getting.



Running something many times, and getting the same order does *not* mean that it is ordered. To be ordered, it has to be defined as ordered. This means that the same order must appear on every version of Java for every platform where it is defined as so.  Running something many times on the same platform and getting the same order is merely an implementation detail. It is not defined as ordered, and the developers of the class didn't do anything to make sure it does -- and will not do anything to make sure it does in future releases.

Another way to think about it is as such. The collection doesn't have an order means that there is no code to ensure the order. It doesn't mean that there is code to ensure that the order is random (or will change from run to run).

Henry
2 weeks ago

raja singh kumar wrote:Is it possible to say that hashset or any other hashing collection is sorted based on the hashing algorithm?



Are you asking whether you can sort a collection based on its hash code? If so, then the answer is yes, but ... why? Sorting, depending on a algorithm can have a time complexity of O(n log n) compared to hashing which has an average time complexity of O(1).

Sorting and Hashing are two different algorithms. It doesn't make sense to say sorting based on a hashing algorithm. Hashing is not sorting.

Also, there is a difference between ordered and sorted. Sorted means ordered, but not all ordered means sorted.

Henry
2 weeks ago

John Losty wrote:I was looking for this part and I don't think it is uncorrect?



Okay, so the statements that you posted are correct ... but ... how do these statements lead you to  believe that the code in your original post shouldn't compile?

Henry
2 weeks ago

Vedanshi Priyadarshi wrote:
Because reference predict the the type if it is the same class or diiferent class .....and after that it checks for acccesibilty in the parent class if it is public ,default, private or protected  which have some set of rules defined in Java ... and lastly if there is two different package we again check for access modifier. It’s all about acces modifier.



Take a look at the example again. It is not about the access modifier. Protected fields should be accessible from subclass types, as defined.

The rule that is being violated is the "responsible for the implementation" rule... see here...

https://docs.oracle.com/javase/specs/jls/se7/html/jls-6.html#jls-6.6.2

Henry

Vedanshi Priyadarshi wrote:
Child automatically inherit the parent property.



True, but that is *not* the OP's question. The question was  ... if a subclass instance needs to access another same type subclass instance (which obviously need a reference), why is it dependent on the type of the reference (under certain conditions)?

Henry

Well, in terms of "why?", as Stephan mentioned, it is because the Java Language Specification says so...

However, if you are wondering why the JLS is written as such, then take a look at this example...



A tiger is obvious a big cat, so hence, the Tiger class is a subclass of the BigCat class. A tiger is obviously not a lynx, so there is no other relationship.

Now, since a Tiger IS-A BigCat, then you are saying that Line A should work. After all, the Tiger class is using a BigCat reference, which it is of that type. This would would mean that any big cat subclass would be able to access any other big cat subclass' super class variables.... which IMHO, is not a good idea.

Henry

Biniman Idugboe wrote:
Now, how do I implement a method such as the following?

What does the method signature above mean? I am confused about it because the method seems to have a type and I thought that only classes can have types.



This is a generic method. And it is a different feature from generics -- which you have described in the earlier paragraph for classes.

Here is the Oracle tutorial regarding this feature...

https://docs.oracle.com/javase/tutorial/java/generics/methods.html

Henry
2 weeks ago

John Losty wrote:and if long is used in arithmetic operation it is not converted to int?



The long primitive type is wider than the int primitive type. And Java does not support the implicit narrowing of a long to an int -- if you want the result of the arithmetic operation to be converted to an int, you will need to explicitly cast it.

Henry
3 weeks ago

Mahesh sam wrote: I know a little C++ and there an object can be created by just saying  Classname Obj;
My wife says its because we can use a different class and a different constructor in Java, but I dont understand that. Can someone please help me understand?


C++ supports the allocation and freeing from the heap via the new/delete operators. C++ supports the instantiation with constructors. C++ also supports reference variables.... however, since reference variables are not commonly used, you are probably used to pointers instead.

So, assuming a pointer declaration, the C++ equivalent is probably ...

So, you do it for the same reason as C++. You want to declare a reference/pointer variable separately from the instance (as they may not be a fixed one to one relationship). And you want to define how to instantiate the instance (because the default may not work in every case).

Henry
3 weeks ago

Trying to guess what the OP is trying to ask...

In the Executors class ...

https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Executors.html

which is a convenience class for executors, there is a couple of cached thread pools methods. If this is the method call being asked, then the executor service being returned has an asked default size of zero threads, and a max thread size of MAX INT threads.

Henry