Ranjith Suranga

Greenhorn
+ Follow
since Aug 19, 2014
Ranjith likes ...
Java Linux TypeScript
Hacker | Lecturer | Tyro Investor
Sri Lanka
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
5
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ranjith Suranga

Ya, my bad, silly question. I still can't figure out why it didn't come to my mind. Anyway, thank you very much, sir.  
2 weeks ago
Recently, I found this code snippet while searching on the subject cryptography and hashing. I could able to understand the most of it, apart from this padding with a zero part.
Why does it really require? What happens if we don't do that? Why do we pair this hexadecimal? I searched through the internet but I couldn't able to find a reasonable explanation.
I would like you guys to show me what I am missing here. Thank you.



Is it because each hex digit equivalent to 4 binary bits? So if we want to represnt a byte which is 8 bits, we gonna need to have two hex digits?
2 weeks ago
I am just curious about this. I don't think like this if there is only one CPU and all the threads slice that same CPU time. But today world, there are more than one processors we can find in our computers. So I think it is fair for me to think like this. Just imagine a situation where there are two threads that are run simultaneously by two processors, change the same static variable at the very same time (to the very nanosecond). What would happen? Is it possible or is it something that would never happen? Someone, please clarify this for me. To help you understand what I am talking about look below sample code.



Thank you.
1 year ago
Thank you for your all replies. I know it is not a big deal. I think that they stated it in more generic fashion there in the doc.  
1 year ago
Hi,

This may sound like bit silly. But just for the curiosity, I would like to know. Whenever we want to fetch a resource that is in our classpath, more often than not we use this getResource method and it returns us a URL object.

Why does it return a URL object? as it has been stated in the doc,

Class URL represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web.


If so, why does it use to represent a resource that is located in the local storage? I know it is not a big deal. But I would like to know some explanations. Thank you.
1 year ago
Sorry for replying late, but thank you for your answer. It helps me to clear my doubts furthermore.

https://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.5

Found this lately, and it's five step process is far more clear to me, rather than thinking Java compiler copies initializer blocks into every constructor.

I think you are right, it's a memorizing trick not what actually happens.

Thank you.
3 years ago
Hi,

I found this is bit confusing, I have heard & read in many times that "Java Compiler Copies Initializer Blocks Into Every Constructor".



If it is true, above code should be something like this, I guess.



and the end result would be something like this,

Initializing Block...!
Constructor 1
Initializing Block...!
Constructor 2

But in the first case result is something like this,

Initializing Block...!
Constructor 1
Constructor 2

So, "Does Java Compiler Copy Initializer Blocks Into Every Constructor"? I doubt. Is there any reference regarding this in JLS? I couldn't able to find.

Thank you.

3 years ago