File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can someone spot an error here? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Can someone spot an error here?" Watch "Can someone spot an error here?" New topic
Author

Can someone spot an error here?

Xara Mithra
Greenhorn

Joined: Nov 17, 2003
Posts: 12
I took this partial prrogram from JavaRules Vol 2 :
------------------------------------------------
public class StringBuffer{
public StringBuffer() {
this(16);
}
public StringBuffer(int length) {
value = new char[length];
shared = false;
}
public StringBuffer(String str) {
this(str.length() + 16);
append(str);
}
public static void main(String args[])
{
}
}
Errors :
---------
StringBuffer.java:8: cannot resolve symbol
symbol : variable value
location: class StringBuffer
value = new char[length];
^
StringBuffer.java:9: cannot resolve symbol
symbol : variable shared
location: class StringBuffer
shared = false;
^
StringBuffer.java:14: cannot resolve symbol
symbol : method append (java.lang.String)
location: class StringBuffer
append(str);
^
3 errors
Suggest : Can someone suggest what to write in main() method. So I understand these constructors?
Sorry if the questions are too silly
Simon Klaiber
Greenhorn

Joined: Nov 13, 2003
Posts: 9
You have to declare the variables...
If you want them local (what i don't think) use:

and

If you want them as instance variables (what I do think you want)
declare them inside the class but outside the methods as

and

if you want to use

You need a method called append that takes a String object as parameter:
for example:

or

if you want to encapsulate the method within the constructors or other public methods.
BTW when you use

it does the same as

but makes the code easier to read.
Simon
[ November 20, 2003: Message edited by: Simon Klaiber ]
[ November 20, 2003: Message edited by: Simon Klaiber ]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Can someone spot an error here?
 
Similar Threads
StringBuffer
jiris mock question
plz delete
The Programme is not Compiling
Compile