This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Queries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Queries" Watch "Queries" New topic
Author

Queries

Deepali Aphale
Greenhorn

Joined: May 28, 2001
Posts: 8
I went through Java Caps exam and I have following queries
1. Select the correct answer for the code fragment given below?
public class TestBuffer {
public void myBuf( StringBuffer s, StringBuffer s1) {
s.append(" how are you") ;
s = s1;
}
public static void main ( String args[] ) {
TestBuffer tb = new TestBuffer();
StringBuffer s = new StringBuffer("Hello");
StringBuffer s1 = new StringBuffer("doing");
tb.myBuf(s, s1);
System.out.print(s);
}
}
A) Prints Hello how are you
B) Prints Hello
C) Prints Hello how are you doing
D) Compile time error

Answeris A)
I am confused with this answer, can some one explain me the same.

2. Chose the valid identifiers?
A) int100
B) byte
C) aString
D) a-Big-Integer
E) Boolean
F) strictfp
Answer is A,C, E

Can the names of wrapper classes be valid identifiers?

Thanks
Deepali
Scott Appleton
Ranch Hand

Joined: May 07, 2001
Posts: 195
Deepali, here's what I think is happening in Q1:
The StringBuffer object "Hello" is being passed by reference to the myBuf method. Anything that is done to that reference point in memory within the method will be reflected even after the method exits. However, the variable s declared in the main method and the local variable s (the one in myBuf) are not the same, even though they both point to the same place in memory when the myBuf method begins executing. The statement s.append(" how are you") alters the value in the place in memory where both the variable s in main() and the local variable s are pointing.
In the next line, the local variable s is redirected to the place in memory referenced by the local variable s1. However, this does not affect the variable s in main() in any way. Therefore, when the method myBuf returns, the variable s in main is still pointing to the location in memory where the value is "Hello how are you".
Does this clear that question up at all?
For your second question, the answer is that the name of any Class is a valid identifier, though for clarity you should probably avoid this practice.
Object Object = new Object(); // compiles fine
[This message has been edited by Scott Appleton (edited June 21, 2001).]
[This message has been edited by Scott Appleton (edited June 21, 2001).]
Deepali Aphale
Greenhorn

Joined: May 28, 2001
Posts: 8
Thanks, it was quite confusing but I am through with it.
In the example if the method would have
return s;
as the statement at the end of function then it would print "doing".
Correct me if I am wrong.
Scott Appleton
Ranch Hand

Joined: May 07, 2001
Posts: 195

Deepali, if the code is changed as below (changes from original in bold):

then you are correct, the output would be simply "doing".
Deepali Aphale
Greenhorn

Joined: May 28, 2001
Posts: 8
Thanks a lot , now I am very much clear about the example.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Queries