• Post Reply Bookmark Topic Watch Topic
  • New Topic

JDK and method naming as described in various Java coding standard  RSS feed

 
Peter Kovac
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm kinda confused with method naming as described in various Java coding standards .

Particularly:

* a class property should be accessed via getter/setters, but JDK often uses no get/set prefix, such as string charAt or swing table’s columnAtPoint, etc.. Shouldn’t be they named getCharAt() or getColumnAtPoint()? The latter is strange (at least for me) as there’s a getColumn(Object o) method and not column(Object o).

* methods names should be verbs, but why are there methods, such as absoluteOf or locationsOfLines w/o verbing the name?

Could you guys shed some lights on these? Thanks.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

The classes in the standard Java library are not a good example of a consistently designed API; the library has grown over the years, many different people have worked on it and different styles have been used for naming methods, classes, interfaces etc. For example, you can find methods called size(), length(), getSize(), getLength() etc. in different standard classes. It's a mess!

For your own code, it's important that you follow a consistent pattern - that will make it easier for you or someone else to read your code later. It also helps if you use a style that matches what most Java programmers would expect. There's a document: Code Conventions for the Java Programming Language, written long ago by people at Sun, but I guess still relevant for the most part, that describes a de-facto coding style that I think most people base their Java code style on.
 
Peter Kovac
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. It seems that no project has consistent method naming...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!