Java I/O Question & toString question
Few questions:
1) What's easier to use, BufferedReaders or Scanners?
2) What happens in the system if a program needs toString method and you don't use it? And how can you trace what's going on when toString is not in use? and when in use?
Thanks,
Coder752
Re: Java I/O Question & toString question
Quote:
Originally Posted by
coder752
1) What's easier to use, BufferedReaders or Scanners?
Easier in what way? They do different things, so it depends what you want to do. Read the API Javadocs for them to see which to use.
Quote:
2) What happens in the system if a program needs toString method and you don't use it?
Why not try it and see. Write a trivial program that calls toString on an instance of a class with no methods. See the API Javadocs for Object.toString().
Quote:
And how can you trace what's going on when toString is not in use? and when in use?
You'll have to explain what you mean.
Teachers open the door, but you must enter by yourself...
Chinese proverb
Re: Java I/O Question & toString question
Quote:
Originally Posted by
dlorde
Easier in what way? They do different things, so it depends what you want to do. Read the API Javadocs for them to see which to use.
Why not try it and see. Write a trivial program that calls toString on an instance of a class with no methods. See the API Javadocs for Object.toString().
You'll have to explain what you mean.
Teachers open the door, but you must enter by yourself...
Chinese proverb
[QUOTE
You'll have to explain what you mean.
[/QUOTE]
I mean what is the system doing while the toString is being used and what the system is doing while the program is suppose to have though it doesn't have it, or is commented out.
Re: Java I/O Question & toString question
Quote:
Originally Posted by
coder752
I mean what is the system doing while the toString is being used
What do you mean by system. What system.
Quote:
Originally Posted by
coder752
and what the system is doing while the program is suppose to have though it doesn't have it, or is commented out.
That depends on what your 'system' wanted to do.
toString() comes from Object. It can never be omitted. However, you can provide your own implementation of toString() for a class you create.
Re: Java I/O Question & toString question
System as in what the computer is calculating aka (procedures done internally)
Re: Java I/O Question & toString question
As Deliverance says, the toString() method is implemented in the Object class and any class can override it if required. If it isn't overridden in a class, and it is called on an instance of that class, the last overridden superclass implementation will be called (typically the Object implementation). In this situation, the result will probably not be what was wanted, because the Object implementation just returns the class name and its hash code.
Doing more things faster is no substitute for doing the right things...
S. R. Covey