|
-
July 28th, 2009, 07:52 PM
#1
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
-
July 29th, 2009, 04:32 AM
#2
Re: Java I/O Question & toString question
 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.
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().
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
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
July 29th, 2009, 09:33 AM
#3
Re: Java I/O Question & toString question
 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.
-
July 29th, 2009, 10:48 AM
#4
Re: Java I/O Question & toString question
 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.
 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.
------
If you are satisfied with the responses, add to the user's rep!
-
July 29th, 2009, 08:43 PM
#5
Re: Java I/O Question & toString question
System as in what the computer is calculating aka (procedures done internally)
-
July 30th, 2009, 05:08 AM
#6
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
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|