Jon Aquino's Mental Garden

Engineering beautiful software jon aquino labs | personal blog

Wednesday, January 09, 2008

Programming: Method names: Statistics for the JDK

Here are some statistics on method names in Java 1.5 (method signatures, method names). By analyzing code of reasonably high quality like the JDK, we can derive rules of thumb for good, standardized function names. Useful for any language.

Number of methods in JDK 1.5:
    80818


Most common method names:
   1304 toString            
1219 run
663 equals
496 hashCode
440 actionPerformed
439 getName
383 contains
352 accept
320 remove
285 reset
280 get
278 getCharacterEncoding
277 paint
261 read
258 add
256 write
224 main
216 close
213 clone
204 getValue
199 getType
193 next
191 createUI
189 size
175 clear
168 getPreferredSize
167 print
159 init
152 newEncoder
152 newDecoder
150 propertyChange
145 update
140 historicalName
134 getMinimumSize
130 debug
120 translate
119 setValue
116 set
116 put
110 getEncoderIndex2
110 append
107 isEmpty
107 getInstance
104 initialize
103 getMaximumSize
102 getBorderInsets
102 error
102 dispose
101 writeObject


Most common 1-word prefixes:
  19984 get       
5449 set
3555 is
1604 to
1534 create
1441 visit
1180 add
776 remove
707 write
642 update
532 mouse
501 hash
500 check
477 new
471 has
468 print
449 action
412 read
374 install
357 parse
330 paint
302 uninstall
294 handle
260 put
258 init
252 process
223 next
223 find
220 end
217 load
217 build
202 can
198 make
195 do
171 window
166 type
161 start
159 compare
157 fire
152 property
141 impl
140 historical
140 clear
138 contains
137 jj_3
121 code
116 draw
109 show
109 focus


Most common 2-word prefixes:
  626 getAccessible
308 getCharacter
229 getPreferred
223 getDefault
190 getMinimum
183 getIcon
175 getClass
163 getSystem
160 getMaximum
130 getMax
129 getEncoder
128 getBorder
127 getFile
117 getLast
115 getDecoder
109 getNode
109 getInput
105 getNext
105 getCurrent
89 getType
89 getLocal
88 getColumn
88 getAttribute
87 getFont
82 getComponent
80 isValid
80 hasMore
78 getRow
75 visitType
75 getJvm
74 getElement
73 getData
72 getParent
65 getNum
62 getUser
62 getProperty
61 getMenu
60 getText
59 getStandard
57 visitConstant
57 getNative
57 getContext
57 getActual
57 addLayout
56 setDefault
56 getSelected
55 getError
54 getDocument
54 getContent


Most common 1-word method names:
 1219 run       
663 equals
383 contains
352 accept
320 remove
285 reset
280 get
277 paint
261 read
258 add
256 write
224 main
216 close
213 clone
193 next
189 size
175 clear
167 print
159 init
145 update
130 debug
120 translate
116 set
116 put
110 append
104 initialize
102 error
102 dispose
96 start
96 match
95 parse
94 eval
91 trace
83 create
83 compare
81 encode
72 finalize
71 flush
68 stop
68 insert
60 copy
57 check
55 render
54 matches
52 delete
50 process
50 name
47 skip
46 show


If you want to conduct your own analysis, view the JDK 1.5 method signatures and method names.

2 Comments:

  • That's actually really interesting.

    Are this numbers including inheritance? If so, I wonder what sort of data you would get if you only counted locally defined methods. i.e. toString is a very common method, but in a lot of cases it's contractually included in an object because the parent of the object has the method definied. The child class doesn't actually declare it.

    It would be interesting to see both sets of numbers and compare.

    By Blogger Grib, at 2/07/2008 8:34 AM  

  • Hi Grib - Interesting point. No these numbers do not exclude inherited methods. That would be intriguing to see.

    By Blogger Jonathan, at 2/07/2008 9:44 PM  

Post a Comment

<< Home