Jesper de Jong wrote:What do you mean by "it doesn't work"? Does it compile (when you correct the spelling error)? Does it run? Is the output different from what you expect?
Dim Dioannou wrote:@kumarjit banerjee thank you
this is what i need
but can you explain the code in line 38, please?
Dim Dioannou wrote:I want to find a word in a text file and then to take a part of it and to
save it in a String.
for example I have this part of text
and when I find the word ''xmlns:'' I want to take the word after : till =
(rdf in this case) and to put it in a string.
Any idea how to do it?
Mohamed Sanaulla wrote:The array in your example is not public.
And this- 4. Methods in ClassA use public variables in ClassB - is the reason why C is true. For something to be public- it has to be declared as public.
Jesper de Jong wrote:
What exactly is your question with Case 2?
Run the program with a profiler
Manjula Weerasinghe wrote:Hi Kumarjit,
Please read this article http://www.javaranch.com/journal/200409/ScjpTipLine-StringsLiterally.html. It has more information about String literal pool (String constant pool) and garbage collection with some descriptive images.
Each time you execute "java" command a new JVM instance is created for executing relevant class main method. Therefore you will get a new string literal pool for that JVM and will not be able to get the same reference. Since each JVM instance is a separate process and because one process cannot access the memory use by another process, you will get one String literal pool for each JVM independent from other instances.
Thanks & Regards,
Jeanne Boyarsky wrote:Rakesh,
The point of such an interview question is to show you can write a simple algorithm. Forget about Java. If you were doing this by hand, what would you do? What would you write down or keep track of in your head? Try explaining it here and we can help you clarify your ideas.
Can you think of a simpler way to do it? That approach is much more complicated than it needs to be. I'm not clear on why you need the Collections.sort or helper objects to solve the problem.
Manjula Weerasinghe wrote:For reducing the memory usage, java uses something called "String Constant Pool" which is a part of JVM memory. It is a pool of currently using Strings of JVM. If you use,
Then JVM first check whether there is any String equals to "this is a test" exists in the String Constants pool.
*) If there is a string identical to "this is a test" exists in the String Constant pool, JVM get the reference to that String and assign that reference value to "s" reference variable without creating a new String object. So in this case, there is no call to constructor happens.
*) If there is no such string with the value "this is a test" exists in the string constant pool, JVM will create a new String object with the value "this is a test", then add the newly created String object to String constant pool, and assign the reference to newly created string object to "s" variable. Therefore in this occasion, Constructor is called by the JVM to create new String object.