Vidhya Ramaswamy

Ranch Hand
+ Follow
since Oct 10, 2007
Merit badge: grant badges
For More
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vidhya Ramaswamy

I am using WYSIWYG control in my form (Source : http://www.openwebware.com)

I want to validate the data in the control using javascript and check for null/blank/multiple blank spaces.



The control accepts multiple blank spaces. I need help to validate this.
1. I tried using regex - "/^(\s+)$/" to check for multiple spaces directly on the 'message' variable.
2. Tried using WYSIWYG.removeFormat() - removes all HTML formatting, and multiple spaces are replaced with a single space) and then checked for occurence of a single space.


But, nothing seems to work. Regex does not work with WYSIWYG control, nor does checking for a space. Is there a way to get this working?
Also, the control's innerHTML's length for a single space is 7 characters(after truncating multiple spaces).

Vidhya
Hi Ranchers,

I cleared my SCJP 1.5 with a score of 81%. I have to thank Javaranch for helping me with the preparation. I read through K&B book, revised and did the mock exam in the CD that comes with the book in Open book mode and also coded a lot. I couldn't do other mocks, was running short of time and my voucher was going to expire. Maybe I should have given more mocks. However, I am happy with the score, and happy to have finally given SCJP which I have been planning to since a while.

Many of my doubts have been cleared from the SCJP forum, the replies have been prompt.
Thanks, again.
Vidhya

15 years ago
Thanks, Harvinder.
I thought that finalize() can be invoked only once for an object(program or JVM).
Taken from MasterExam:

I thought that finalize() can only be called once for an object, and since the program is already calling finalize(), gc will not call it.
Please explain.
Hi Preetha,

Replacing the code with
Object obj = n2;
if(n1.equals(obj))s+="1";

calls the Object class equals(), which just does a direct compare(==).
So, 1 is not printed in this case.

The reason it shows set.size() as 2 is because both the references do not refer to the same object, as(n1!=n2).

Try this out(assigns n1 to obj, so both refer to the same object):

Object obj = n1;
if(n1.equals(obj))s+="1"; //calls Object class equals()
if(n1==n2)s+="2";
Set<Nearly> set = new HashSet<Nearly>();
set.add(n1);
set.add((Nearly)obj); //trying to add duplicate
System.out.println(s + " " + set.size());

Now, set.size() will print 1.
Thanks Ankit for your quick response.
Is this what happens?
calls equals() in the Nearly class.
equals() and hashCode() are called before adding to HashSet. But here, the equals() called is of Object class(since Nearly class does not override equals() properly. So, n2 is added to the set.
Please correct me if I'm wrong.

Question taken from LearnKey MasterExam.
Why is the set allowing duplicates, and showing the size as 2?
I understand, it is because the equals() is not properly overridden, it doesn't take an Object. So, is the set allowing duplicate because of the equals() in Nearly class?
Thanks, Ankit.
I'm still not very clear. There are exam questions which ask you to identify if an exception is thrown by the JVM or progamatically thrown.
How do you identify?
I am getting confused in identifying whether an exception is thrown by JVM or by the Program.
Why are ArrayIndexOutOfBounds and NullPointerException thrown by the JVM, whereas IllegalArgumentException thrown by the application?
Can someone please explain?
Consider the following code:


And this is the result:

Tue Jan 01 00:00:00 PST 2008
parse exc



I can't seem to understand why there is an exception with the getDateInstance(DateFormat.MEDIUM)
whereas, for the same string, there is no exception when used with
getDateInstance(DateFormat.SHORT)
Hello Bert,
Thanks for replying to the post and letting us know that String pool is not on te exam.

However, can you pls clarify the doubt-what happens to the string in the pool which doesn't have a reference as in #1?

This code surely creates 2 objects, one in the string pool (literal "Hello") and another String object in the heap referenced by s.

Now, my question is: What happens to the "Hello" created in the pool?
Is the same one used for the other string references too? (s1 and s2)??
I don't think so, wanted to confirm.
I think there are 2 string objects in the pool and 1 in the heap.


According to my understanding, the line 1 creates a string literal "Hello" in the string pool. However, this one is not used for reference s: another string object is created in the heap.
Now, the string "Hello" created in the pool, does not have a reference.
So in the lines 2 and 3,is the same string "Hello" used from the pool used or is a new string created in the pool?
At the end of these lines of code, how many objects are in the pool?

I feel the first "Hello" in pool cannot be used later. Pls confirm.
A top-level class can only be declared with only public or default(no modifier) access.
Just think about: if you declare a class as private, nobody can access it.

However, it is possible to declare an inner class as private.