String Representations of Java Objects: An Empirical Study

  • Matúš SulírEmail author
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 12011)


String representations of objects are used for many purposes during software development, including debugging and logging. In Java, each class can define its own string representation by overriding the toString method. Despite their usefulness, these methods have been neglected by researchers so far. In this paper, we describe an empirical study of toString methods performed on a corpus of Java files. We are asking what portion of classes defines toString, how are these methods called, and what do they look like. We found that the majority of classes do not override the default (not very useful) implementation. A large portion of the toString method calls is implicit (using a concatenation operator). The calls to toString are used for nested string representation building, exception handling, in introspection libraries, for type conversion, and in test code. A typical toString implementation consists of literals, field reads, and string concatenation. Around one third of the string representation definitions is schematic. Half of such schematic implementations do not include all member variables in the printout. This fact motivates the future research direction – fully automated generation of succinct toString methods.


ToString methods Java Quantitative study Qualitative study 



This work was supported by Project VEGA No. 1/0762/19 Interactive pattern-driven language development. This work was also supported by FEI TUKE Grant no. FEI-2018-57 “Representation of object states in a program facilitating its comprehension”.


  1. 1.
    Bezirgiannis, N., Jeuring, J., Leather, S.: Usage of generic programming on hackage: experience report. In: Proceedings of the 9th ACM SIGPLAN Workshop on Generic Programming, WGP 2013, pp. 47–52. ACM, New York (2013).
  2. 2.
    Chiş, A., Nierstrasz, O., Syrel, A., Gîrba, T.: The moldable inspector. In: 2015 ACM International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software, Onward! 2015, pp. 44–60. ACM, New York (2015).
  3. 3.
    Dyer, R., Rajan, H., Nguyen, H.A., Nguyen, T.N.: Mining billions of AST nodes to study actual and potential usage of Java language features. In: Proceedings of the 36th International Conference on Software Engineering, ICSE 2014, pp. 779–790. ACM, New York (2014).
  4. 4.
    Kalliamvakou, E., Gousios, G., Blincoe, K., Singer, L., German, D.M., Damian, D.: The promises and perils of mining GitHub. In: Proceedings of the 11th Working Conference on Mining Software Repositories, MSR 2014, pp. 92–101. ACM, New York (2014).
  5. 5.
    Lemay, M.J.: Understanding Java usability by mining GitHub repositories. In: 9th Workshop on Evaluation and Usability of Programming Languages and Tools (PLATEAU 2018). OpenAccess Series in Informatics (OASIcs), vol. 67, pp. 2:1–2:9. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany (2019).
  6. 6.
    Ma, H., Amor, R., Tempero, E.: Usage patterns of the Java standard API. In: Proceedings of the XIII Asia Pacific Software Engineering Conference, APSEC 2006, pp. 342–352. IEEE Computer Society, Washington (2006).
  7. 7.
    Pawlak, R., Monperrus, M., Petitprez, N., Noguera, C., Seinturier, L.: Spoon: a library for implementing analyses and transformations of Java source code. Softw. Pract. Exp. 46(9), 1155–1179 (2016). Scholar
  8. 8.
    Qiu, D., Li, B., Leung, H.: Understanding the API usage in Java. Inf. Softw. Technol. 73(C), 81–100 (2016). Scholar
  9. 9.
    Rozenberg, D., Beschastnikh, I.: Templated visualization of object state with Vebugger. In: Proceedings of the 2014 Second IEEE Working Conference on Software Visualization, VISSOFT 2014, pp. 107–111. IEEE Computer Society, Washington (2014).
  10. 10.
    Schwarz, N.: DoodleDebug, objects should sketch themselves for code understanding. In: 5th Workshop on Dynamic Languages and Applications, DYLA 2011 (2011)Google Scholar
  11. 11.
    Sulír, M., Juhár, J.: Draw this object: a study of debugging representations. In: Proceedings of the Conference Companion of the 3rd International Conference on Art, Science, and Engineering of Programming, pp. 20:1–20:11. ACM (April 2019).
  12. 12.
    Sulír, M., Porubän, J.: Augmenting source code lines with sample variable values. In: Proceedings of the 2018 26th IEEE/ACM International Conference on Program Comprehension (ICPC), pp. 344–347 (May 2018).
  13. 13.
    Tempero, E., et al.: The Qualitas Corpus: a curated collection of Java code for empirical studies. In: Proceedings of the 2010 Asia Pacific Software Engineering Conference, APSEC 2010, pp. 336–345. IEEE Computer Society, Washington (2010).
  14. 14.
    Terra, R., Miranda, L.F., Valente, M.T., Bigonha, R.S.: Qualitas.class corpus: a compiled version of the Qualitas Corpus. SIGSOFT Softw. Eng. Notes 38(5), 1–4 (2013). Scholar
  15. 15.
    Wohlin, C., Runeson, P., Höst, M., Ohlsson, M.C., Regnell, B., Wesslén, A.: Experimentation in Software Engineering. Springer, Berlin (2012). Scholar
  16. 16.
    Xu, W., Huang, L., Fox, A., Patterson, D., Jordan, M.I.: Detecting large-scale system problems by mining console logs. In: Proceedings of the ACM SIGOPS 22Nd Symposium on Operating Systems Principles, SOSP 2009, pp. 117–132. ACM, New York (2009).

Copyright information

© Springer Nature Switzerland AG 2020

Authors and Affiliations

  1. 1.Technical University of KošiceKošiceSlovakia

Personalised recommendations