Tiam Bezalel

Ranch Hand
+ Follow
since Feb 02, 2020
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Tiam Bezalel

hi,I would like to understand why line 2 causes a compilation error.



thanks
1 year ago


hi, I don’t understand the explanation below. it’s the explanation to the above exercise. Can you help me understand this explanation better?

If you supply a pattern with multiple grouping characters(such as comma), the interval between the last one and the end of the integer is the one that is used.  For the pattern "###,##,#", interval is just 1 digit. Hence, `df1.format(1231)` returns "1,2,3,1"  For the pattern "##,###,#", interval is just 1 digit. Hence, `df2.format(1231)` returns "1,2,3,1"   Hence, output is: true


thanks

1 year ago
hi, I want to prepare the 1Z0-900 oracle certification. I would like this book in pdf format.

1Z0-900 oracle certification

Do you have a better book on the subject in PDF format to offer me?

thanks
hi, I would like to understand why this program waits indefinitely while the lock is lifted by two threads.


Variable 'cb' infers to CyclicBarrier type.

`new CyclicBarrier(2, () -> System.out.println("START..."));` means 2 threads must call await() so that Cyclic Barrier is tripped and barrier action is executed.

At Line n2, await() is invoked on 'cb' by Main-Thread and it waits until one more thread would invoke await() on the same object.
1 year ago
hi.on the line 1, how does the java runtime determine which version of "remove" to use?
why doesn't he do auto-boxing?





thanks
1 year ago
hi, I'd like to understand the execution of the above program better. Why does it display "-1" instead of "1999".


Here is my reasoning:

The subclass replaces the methods of the superclass but hides the variables of the superclass.

Line n5 hides the variable created at Line n1, there is no rules related to hiding (type and access modifier can be changed).

Line n7 correctly replaces the Parent() method of the Parent class.

new Child() on line n9 calls the constructor of the Parent class. The compiler has added super(); as the first instruction inside this constructor, so control goes to the no-argument constructor of the Parent class, which in turn calls the no-argument constructor of the Object class. The no-argument constructor of the Object class finishes its execution and control returns to the constructor of the Parent class, which executes the Parent() method inside it.

However, the method has been redefined and the instance variable "id" has been hidden, so it's the Parent() method redefined in "Child" that will be executed. According to me, it's 1999 that should be displayed.

thanks


1 year ago
thanks .I need your advice on determining the total number of strings created in the stringPool. Is hashing the right approach?
1 year ago
There are three popular ways of creating strings in Java:

   1-String literal
   2-Using new keyword
   3-Using String.intern() method


1-the first approach creates a string literal in the String Constant Pool.Whenever a string literal is created, the compiler checks the String Constant Pool first. If it encounters the same string, then instead of creating a new string, it returns the same instance of the existing string to the variable.

2-We can create new String objects using the new keyword. When we create new string literals using the new keyword, memory is allocated to those String objects in the Java heap memory outside the String Pool. However, we can stop this kind of memory allocation to String objects using the String.intern() method in Java.

3-Creating strings using the new keyword allocates memory to the string object in the heap but outside the string constant pool. When we use the String.intern() method, JVM puts the string literal in the String Pool (if not already present), and its reference is stored in the variable. However, if the String Constant Pool already contains a string equal to the String object to be created, its reference is returned.






1 year ago

All you have demonstrated so far is that some strings which are identical have the same hash code. This is simply a rule of how hash codes behave and it has nothing to do with the system's string pools.



String pool is a storage space in the Java heap memory where string literals are stored. It is also known as String Constant Pool or String Intern Pool. It is privately maintained by the Java String class. By default, the String pool is empty. A pool of strings decreases the number of String objects created in the JVM, thereby reducing memory load and improving performance.



how can i determine the number of strings that are created in the string pool? i use the hashCode to implement this rule. should i proceed differently?

thanks
1 year ago

Carey Brown wrote:Output of histogram:
Note that the hash code is determined by the characters and sequence that they appear in the String. It has nothing to do with any "pool".



I'm currently trying to better understand the creation of strings in the string pool of heap memory. Using the little program I've created, I'd like to determine the number of objects (strings of characters) that are created definitively in the string pool of heap memory.

Whenever a string literal is created, the compiler checks the String Constant Pool first. If it encounters the same string, then instead of creating a new string, it returns the same instance of the existing string to the variable.



two strings with the same hash value will be referenced in the string. here's the logic I'd like to implement

With my approach, Norm Radder's and yours, I think I've succeeded.

1 year ago

Norm Radder wrote:

yes !!!


Ok, which of the two choices is the one?
Or do you want both?



Can you show me both?
1 year ago

Norm Radder wrote:

determine the number of strings that are definitely created in the string pool


Given the hashCodes of 1,2,1,2,2  what is the desired results?
2 unique hashCodes
max count of 3 with same hashCodes



yes !!!
1 year ago
Do you want to compare each element against all the other elements?---> yes

I would like to compare the hash code of each string with the other strings in order to determine which strings have the same hash value. I will be able to determine the number of strings that are definitely created in the string pool.  

1 year ago
there are actually two strings created in the string pool of the heap memory. although the two methods (yours and mine) give the same results, your approach is simpler. thank you for correcting me.
1 year ago
strings with the same hashCode
1 year ago