File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Storm Applied this week in the Other Open Source APIs 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: 19972

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