Gautam Pandya

Greenhorn
+ Follow
since Sep 29, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Gautam Pandya

The methods on String class returns another String object.
For example in the code given below,
String s = " Hello";
String s1;
s1 = s.trim();
calling the method trim() on it will not change the object referenced by s but will return a different object which is being assigned to s1. So after execution, s1 will contain "Hello" where as s will still have " Hello".
Also, there can be a statement like,
s = s.trim();
In this also, s.trim() will return another String object and s is reassigned with the reference to the new object.
Thanks a lot Shan, Shailesh and Danish.
Gautam.
23 years ago
Hi All!
Yesterday evening I took the SCJP and cleared with 89% (53/59). Not a very good score - but not bad either (that's what I feel).
I changed two anwers from right to wrong during the review!!! That's me!!!
I found the real test easier than the mock exams. Its because all the questions are clearly worded and there is no ambiguity anywhere. On two to three questions, initially I thought the questions are not clear enough but reading them carefully it turned out to be proper questions.
There is a tradition of giving Javaranch's contribution in the score. My number is 89%!!! Not kidding - as without coming to this wonderful world, I wouldn't have dared to appear for SCJP at this time. After some exposure to Java, on one lucky day, I landed up on this site while surfing the net. First thing I did on this site is to take the rules roundup. The number of cows moved into the pen on first attempt motivated me to improve it further and in turn it put me on the path of the SCJP.
Big moose saloon is a forum where race, religion, nationality or any such bounds have no place. Everyone is helping each other and that's really great! I am really thankful to those who have put their doubts on the forum (and ofcourse who replied to them)as many of the questions wouldn't have come to my mind but were important in strenghening the subject.
I am very grateful to Ye Zhang, who very promptly sent me the notes on my request. They were really helpful in the last minute preparation. Thank you Ye Zhang.
My special thanks to Maha for putting all the informations on SCJP at one place. The discussions are very good.
Thanks to all the moderators on this site. Ajith, Paul, Maraputra, Bill ...
Once again thank you all ... and yes, this is not a goodbye note as I can not stop myself coming to this site. So see you soon ...
Gautam.
23 years ago
Hi,
I appeared for the test yesterday and yes, I can say that GridBagLayout is there. java.util is an important area. Number of questions are based on java.util
Gautam
23 years ago
Congratulations, Archana!!!
And thanks for the detailed note on the exam pattern.
Gautam.
23 years ago
I didn't find question no. 1 and 4 challenging. For question 2 and 3, I think the key is that toString() function returns a new String object. Am I right?
The reason is, the method replace() creates a new String object allocated from the heap.
In fact the allocation from String pool and subsequent optimization happens only in case of String literals. When we write a statement like,
String s3 = "arit";
s3 is assigned a reference to a String object stored in the String pool for the literal "arit". But in case of a statement like,
String s5 = new String("arit");
we are not assigning the variable s5 with a direct reference to String literal "arit". Here what happens is - a new String object is created with a value "arit" and s5 contains reference to this object. The allocation is from the heap and not from the pool. The same is true in case of replace() method.

Originally posted by Bharatesh H Kakamari:
String s1 = new String("amit"); // allocated from heap
String s3="arit"; //allocated from String pool
String s4="arit"; // no new reference created
String s2 = s1.replace('m','r'); // AS "arit" ALREADY EXISTS, SHOULD IT NOT BE ALLOCATED REFERENCE OF s3 ?
System.out.println(s2==s3);
System.out.println(s3==s4);
WHY DOES IT PRINT "false" FOR FIRST SOP ?


Ravi,
Your explanation is really good but I think the last part as quoted under is not correct. The method can be overloaded with a
method float Firstfunc(long a, long b, long c).
I mean, there is nothing wrong with the given code if modified as below.

Gautam.

Originally posted by ravi chan:

. . . And also a thing to note is you cannot change the overloaded declaration to float Firstfunc(long a, long b, long c)
will give you a compiler error if your method call is Firstfunc(1, 2, 3) because the compiler gets confused about both the overloaded methods.



Avani,
String literals are also instances of String class. In your question all the three String variables, s1, s2 and s3 are object references and they are not different. (from part 2 of your question I felt that you consider them to be different)
The question now you may have - why s1 == s2 is true?
That is because when s1 is assigned with a literal "QSQT", a new instance of String (to store "QSQT") is created to represent the literal which will reside in a pool (of Strings). Reference to this instance is assigned to the string variable s1.
When s2 is assigned with "QSQT", the compiler does not create a new instance of String. It uses the same instance and reference to this instance is assigned to s2. s1 has the same reference and hence s1 == s2 is true.
in case of s3, there is an explicit instantiation of String object in the assignment, and hence the s3 has reference to a different String object but having the same value "QSQT".
Which means s2 == s3 is false and s2.equals(s3) is true.

Originally posted by AVNI R:
[B]Thanks Ajit......

Ajith. I have two doubts here.......
1. Where does a literal(any literal-int,boolean,string etc)belong to.. Is it belonging to primitive datatypes? If yes then why do we have literals in the first place.... Can't we do without it..
2. In this example why cant we compare a string literal to an object reference in (1)? Why is it giving false... and why it is giving true at (2)...........
Mysterious strings.........

AVNI
[/B]


</BLOCKQUOTE>
[This message has been edited by Gautam Pandya (edited October 30, 2000).]
[This message has been edited by Gautam Pandya (edited October 30, 2000).]

Aru:
Your question has already been answered by Bill. The Runtime Exception thrown in the catch block is not caught because it is not within any try block. Any exception will be caught by the surrounding try block and the caught exception will be handled by the catch/finally or both blocks associated with that try block.

Originally posted by Aru Ven:
Hi All,
Can anyone tell me why the Runtime Exceptime thrown in the first catch statment not caught in the immediate next Catch. I mean....

Aruna


When the 'another' method is called from the method 'amethod' with passing the variable 'v', only the copy of the value stored in that variable (which is a reference to an object) is passed. Which means after the method another is called it will have a variable 'v' different from the variable 'v' of the calling method (amethod) but having the same value as that of the variable 'v' of the calling method. Which means both variables hold references which points to the same object.
So v.i = 20 statement in another affects the original object because v in both methods (before v=vh) refer only one object.
Now in another method, after the statement v=vh, v refer a new object but it does not change the value of v in the calling method thus v in the calling method still holds the original reference and not a new reference to the object created in the method - another.
Hi Vikram,
Congratulations!!!
That's a good score! This site is really great help in preparing for the SCJP as I am experiencing in my preparation for SCJP.
Functions asin, acos, and atan all are included in the Math class. Please look at the API specifications. Here is the link.
http://java.sun.com/products/jdk/1.2/docs/api/index.html
Gautam.
RHE stands for the book titled,
"The complete JAVA 2 Certificatioin Study Guide"
written by,
Simon Roberts, Phillip Heller and Michael Ernest.
By the way its a really good book to prepare for SCJP.

I am using the book titled "The UML User Guide" by Booch, Rumbaugh and Jacobson. Its really good and costs in the range of $40 to $50.