Abid Sami

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

Recent posts by Abid Sami

Congrats Elena!!!. The score is not a true measure of your Java skills and concepts as it depends on a number of other factors (prep time, luck, distractions, etc). Whether you clear with 69% or 96% it still implies that you know your stuff!!!


Abid Sami
SCJP,SCWCD
18 years ago
Thanks Pat, Nizar and Mikalai. I am currently looking at Struts (Struts Cookbook and the Struts Complete Reference guide). My work experience has been mostly in Core Java API so everything is new to me as of now. I intend to take the SCBCD exam maybe at the end of april (but that very much depends upon my job workload )
18 years ago
Thats Cool Deepak. Best of luck with SCWCD Exam!!!
18 years ago
Thats a good score Tsang. Best of luck with SCWCD. You will find it much easier now that you have cleared SCJP and built up your confidence.
18 years ago
Thanks to Frederick, Bert, Marc, Mani, Veena, Scott, Vivek, Vishwas, Sanjay, Marcus, Patrick, Mikalai, Krishna, Wise, Marcelo, Joyce and everyone else on the java ranch for their help and advice. I cleared SCWCD with 88%. I had cleared the SCJP 1.4 (81%) a month back. For SCWCD I had read HFSJ, Professional Java Server Programming (WROX publishers) Servlet and JSP specs and had done the whizlab mock exams. I had made my notes but had refered to notes from the SCWCD links page as well. The notes from Frederic were priceless and really helped me revise. I made only 59% on the final mock exam in HFSJ so I was not all that confident. The questions in the exam are not as easy as I expected . I lost many points in tag libraries, standard actions and Custom tags even though I had spent extra time on the topics. Best of Luck to everyone else preparing for the exam.

Section Analysis
Servlet Technology Model : 100%
Structure and Deployment of Web Applications : 100%
Web Container Model : 100%
Session Management : 71%
Web Application Security : 83%
JSP : 100%
JSP EL : 80%
JSP standard actions: 75%
JSP Tag Libraries : 75%
Custom Tags : 80%
J2EE design patterns : 100%

[ March 24, 2006: Message edited by: Abid Sami ]
[ March 24, 2006: Message edited by: Abid Sami ]
18 years ago
Congrats!!! Thanks for the tips.
18 years ago
String does not have an append method. But if you were to modify your program so as to use String instead of StringBuffer.



You will get an output: ABAA

But the output in the StringBuffer eample will be ABABCABC.

[ February 04, 2006: Message edited by: Abid Sami ]
As Sumit clearly stated, the thing to remember is that when you pass a reference (copy of the reference) to a method, you can actually modify the object using this copy of the reference because it is pointing to the object. But you cannot for example make the reference set to null in the method and expect the object to be garbage collected because after all its a copy of the original reference (an instance variable)which is still pointing to the object. In case of primitives (as in the 2nd example), you are again passing a copy of the actual primitive value. If in the method, you try to change the primitive variable (this is now a method local variable) don't expect the original primitive instance variable value to change. In both cases you are always passing a copy of the variable.
[ February 04, 2006: Message edited by: Abid Sami ]

Originally posted by Enrique Villamizar:
[QB]What about using a tool for simulating objects in memory. I know there is one called ObjectTool but I don't have it. Maybe JProfiler.

I also found this: Boldface two written by me. Taken from Fundamentals of the Java Programming Language, Sun Mycrosystem 2005. SL-110, Student Guide, Page 5-20.
QB]



Thanks Enrique. Maybe that explicitly explains about the creation of two objects. It does say that using the new keyword for the creation of Strings, does create two objects after all. I haven't really used a tool for simulating objs in memory before but thats a very good way of verifying it. Anyways, the correct answer would then be 5.
The answer is 4 as explained before by me.

I think most of you guys seem to have misunderstood the concept of String Literal pool. Refer to the article for a better understanding
http://www.javaranch.com/journal/200409/ScjpTipLine-StringsLiterally.html

What is the String Literal Pool? Most often, I hear people say that it is a collection of String objects. Although that's close, it's not exactly correct. Really, it's a collection of references to String objects. Strings, even though they are immutable, are still objects like any other in Java. Objects are created on the heap and Strings are no exception. So, Strings that are part of the "String Literal Pool" still live on the heap, but they have references to them from the String Literal Pool.

When you say
String s = new String ("abc");

This will create only one object on the heap with s referencing it. At the same time there will be a reference for it created in the String Literal pool. All Objects live on the heap. There is no String Literal pool heap as most of the people seem to be suggesting on the forum
I am not saying Kathy and Bates are wrong, but they need to clarify this point.
[ January 31, 2006: Message edited by: Abid Sami ]
There are 4 obj created.

String s1 = "abc";
This will create obj 1 refered by s1 and there will be a reference for it in the String literal pool as well.


String s2 = new String("xyz");
This will create a new object obj 2, (There won't be a "String Literal object")

s2 = s1;
No new object created. s2 now simply referes to the obj referenced by s1. The original object refered by s2 is eligible for gc, but the question is how many objects are created?


s1.toUpperCase();
This will create an obj 3 which will be immediately lost since it is not assigned.

String s3 = "abc";
This will not create a new obj because of the String Literal pool. s3 will simply point to the obj referenced by s1.


String s4 = s3.replace('a','A');

This will create the obj 4 referenced by s4.
[ January 26, 2006: Message edited by: Abid Sami ]
String sss = new String("abc");
This will create an obj on the heap that is referenced by sss. Will it also have a reference in the String Literal pool?
If I had said String sss = "abc" only then it would have created a reference to them from the String Literal Pool.Am I right?

This is another question.
If I were to say
String s1 = new String("abc");
s2="abc";

Will this create a new object for s2 ?, Since there is already a reference to the string object("abc") in the string literal pool. s2 will now refer to the obj created in line 1 and refered to by s1

[ January 26, 2006: Message edited by: Abid Sami ]

[ January 26, 2006: Message edited by: Abid Sami ]

[ January 26, 2006: Message edited by: Abid Sami ]
[ January 26, 2006: Message edited by: Abid Sami ]
The correct answer is 4. When you use the keyword "new," the JVM is obliged to create a new String object at run-time but there is no "String literal pool object" created.

http://www.javaranch.com/journal/200409/ScjpTipLine-StringsLiterally.html
People tend to get confused about the String Literal pool

What is the String Literal Pool? Most often, I hear people say that it is a collection of String objects. Although that's close, it's not exactly correct. Really, it's a collection of references to String objects.

Originally posted by marc weber:

Of course, you're correct! I misread the ^ as "to the power of." (Doh!)




Thanks Ven and Marc for the answers. I always misread ^ as "to the power of." as well.
[ January 26, 2006: Message edited by: Abid Sami ]


Now, how many objects are created?

[ January 26, 2006: Message edited by: Craig Tyler ][/qb]<hr></blockquote>

Correct me if I am wrong. The answer is 4
Both s1 and s2 refer to the same String object "abc". The new String("xyz") will create ONLY one new object and s3 will refer to it. "unome" will be another literal object that will be soon lost. s2 is then reassigned to refer to a String object "abcxyzunome".

The answer for the original question is also 4. Refer
http://www.javaranch.com/journal/200409/ScjpTipLine-StringsLiterally.html
People tend to get confused about the String Literal pool

What is the String Literal Pool? Most often, I hear people say that it is a collection of String objects. Although that's close, it's not exactly correct. Really, it's a collection of references to String objects.

[ January 26, 2006: Message edited by: Abid Sami ]
[ January 26, 2006: Message edited by: Abid Sami ]