toString method - cant understand this example

07/02/2014 17:05 fear-x#1
Code:
class PointCoordinates {

	private int x, y;
	public PointCoordinates(int x, int y) {
		this.x = x;
		this.y = y;
	}
	public int getX() {
		return x;
	}
	public int getY() {
		return y;
	}
}

public class ToStringDemo {

	public static void main(String args[]) {
		PointCoordinates point = new PointCoordinates(10, 10);
		// using the Default Object.toString() Method
		System.out.println("Object toString() method : " + point);
		// implicitly call toString() on object as part of string concatenation
		String s = point + " testing";
		System.out.println(s);
	}
}
i have this example from google. but i implemented it to my own script yet i still dont understand how it works and whats it for and what EXACTLY it does. :D
07/02/2014 17:12 tolio#2
you should read the full page and test it to see the difference
[Only registered and activated users can see links. Click Here To Register...]
07/02/2014 17:20 fear-x#3
i read it all but too complicated... and to me java seems too much complicated overall :D
07/02/2014 19:35 strubelz#4
The Method you wrote is an example of the default toString Method, if you want to implement a custom one, just read the complete site. Basicly what you need to do is just creating a class that extends the class for that you want to create a custom toString Method and Override the toString Method. Your Method needs to return a String, this String should contain all Information of the class in you own format.
07/03/2014 20:05 fear-x#5
whats the point of this toString though? if you can simply just return all the data one by one and see the values?
07/04/2014 01:04 -Epitaph-#6
Whats the point of C when u can "simply" do it in Assembler ;)

For instance if u want to print a lot of player stats more than one time to the screen u can do it with "player.toString()" rather than "Stamina: " + player.stamina + "\nAgility: " + player.agility and so on.

It just gives u the possibility to represent an object as a string.
But u don't have to use it :P

Please correct me if I'm wrong! ;)
07/04/2014 01:41 fear-x#7
now THAT ! cleared out well for me ! :) i get the point of it now :)

instead of printing 20 lines... prints one line and everything is returned :P cool ! like a debug-ish :D
07/04/2014 13:12 MrSm!th#8
toString is used for debug purposes mostly.
A nice debugger will show you the string representations of objects instead of some complex object tree. Hence you can easily see crucial information about your objects while stepping through your code.
07/04/2014 13:28 fear-x#9
thank you all guys ! :) thank you very much