Skip to main content

String Representations of Java Objects: An Empirical Study

  • Conference paper
  • First Online:
Book cover SOFSEM 2020: Theory and Practice of Computer Science (SOFSEM 2020)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 12011))

  • 941 Accesses

Abstract

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    https://github.com/sulir/tostring-study.

References

  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). https://doi.org/10.1145/2502488.2502494

  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). https://doi.org/10.1145/2814228.2814234

  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). https://doi.org/10.1145/2568225.2568295

  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). https://doi.org/10.1145/2597073.2597074

  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). https://doi.org/10.4230/OASIcs.PLATEAU.2018.2

  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). https://doi.org/10.1109/APSEC.2006.60

  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). https://doi.org/10.1002/spe.2346

    Article  Google Scholar 

  8. Qiu, D., Li, B., Leung, H.: Understanding the API usage in Java. Inf. Softw. Technol. 73(C), 81–100 (2016). https://doi.org/10.1016/j.infsof.2016.01.011

    Article  Google Scholar 

  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). https://doi.org/10.1109/VISSOFT.2014.26

  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. 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). https://doi.org/10.1145/3328433.3328454

  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). https://doi.org/10.1145/3196321.3196364

  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). https://doi.org/10.1109/APSEC.2010.46

  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). https://doi.org/10.1145/2507288.2507314

    Article  Google Scholar 

  15. Wohlin, C., Runeson, P., Höst, M., Ohlsson, M.C., Regnell, B., Wesslén, A.: Experimentation in Software Engineering. Springer, Berlin (2012). https://doi.org/10.1007/978-3-642-29044-2

    Book  MATH  Google Scholar 

  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). https://doi.org/10.1145/1629575.1629587

Download references

Acknowledgments

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”.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Matúš Sulír .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2020 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Sulír, M. (2020). String Representations of Java Objects: An Empirical Study. In: Chatzigeorgiou, A., et al. SOFSEM 2020: Theory and Practice of Computer Science. SOFSEM 2020. Lecture Notes in Computer Science(), vol 12011. Springer, Cham. https://doi.org/10.1007/978-3-030-38919-2_39

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-38919-2_39

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-38918-5

  • Online ISBN: 978-3-030-38919-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics