CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2009
    Location
    USA
    Posts
    49

    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

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Java I/O Question & toString question

    Quote Originally Posted by coder752 View Post
    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.

  3. #3
    Join Date
    Jul 2009
    Location
    USA
    Posts
    49

    Re: Java I/O Question & toString question

    Quote Originally Posted by dlorde View Post
    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.

  4. #4
    Join Date
    Apr 2007
    Posts
    425

    Re: Java I/O Question & toString question

    Quote Originally Posted by coder752 View Post
    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 View Post
    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!

  5. #5
    Join Date
    Jul 2009
    Location
    USA
    Posts
    49

    Re: Java I/O Question & toString question

    System as in what the computer is calculating aka (procedures done internally)

  6. #6
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    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
  •  





Click Here to Expand Forum to Full Width

Featured