This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Convention for displaying class data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Convention for displaying class data" Watch "Convention for displaying class data" New topic

Convention for displaying class data

Charles Bradley
Ranch Hand

Joined: Oct 04, 2009
Posts: 32
Many classes contain methods that display the data in the object. Is there a convention for the names of methods that provide various levels of detail? For example, consider a class called Point containing floats for x and y coordinates of the point. One method might display "2.0, 3.0" and another might display "(x=2.0, y=3.0)". A more complicated class might have several formats.
David Newton

Joined: Sep 29, 2008
Posts: 12617

None that I'm aware of.

The toString() method is usually used to create a human-readable string representation of the object, but the level of detail is up to the person overriding it. Anything beyond that is at the programmer's discretion. For example, for a detailed representation I usually use something like dump(). You could also create a method that takes an enum that defines granularity, similar to logging levels.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20193

If you're really feeling bold you can write your own Format subclass.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Convention for displaying class data
jQuery in Action, 3rd edition