Abstract
Java 8 marked a shift in the Java development landscape by introducing functional-like concepts in its stream library. Java developers can now rely on stream pipelines to simplify data processing, reduce verbosity, easily enable parallel processing and increase the expressiveness of their code. While streams have seemingly positive effects in Java development, little is known to what extent Java developers have incorporated streams into their programs and the degree of adoption by the Java community of individual stream’s features.
This paper presents a replication study on which we analyze the stream usage of 610 Java projects. Our findings show that the Java streams are used mostly by software libraries rather than regular applications. Developers rarely use parallel processing, and when they do so, they only superficially use parallelism features and most of the parallel streams are used on simple forEach operations. The most common used pipelines involve map, filter and collect operations. We carefully describe a number of stream idioms we identified, and detail how we addressed the challenges we faced to complete our study. Our findings will help developers at (i) making better decisions about which features to consider when improving the API and (ii) supporting stream-related IDEs features, such as refactoring.
Keywords
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
- 2.
It takes 28 h to process 7,700 Java source code files, and the 10k projects contain 317,032 source files.
- 3.
mvn dependency: copy-dependencies and gradle dependencies.
- 4.
References
Abelson, H., Sussman, G.J.: Structure and Interpretation of Computer Programs, 2nd edn. MIT Press, Cambridge (1996)
Basios, M., Li, L., Wu, F., Kanthan, L., Barr, E.T.: Darwinian data structure selection. In: Proceedings of the 2018 26th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering, pp. 118–128. ESEC/FSE 2018, Association for Computing Machinery, New York (2018)
Bergel, A., Infante, A., Maass, S., Sandoval Alcocer, J.P.: Reducing resource consumption of expandable collections: The pharo case. Sci. Comput. Program. 161, 34–56 (2018), advances in Dynamic Languages
Blog, I.I.: Intellij idea inspection settings for refactoring to java 8. Accessed 14 Jan 2020
Costa, D., Andrzejak, A.: Collectionswitch: a framework for efficient and dynamic collection selection. In: Proceedings of the 2018 International Symposium on Code Generation and Optimization, CGO 2018, pp. 16–26. Association for Computing Machinery, New York (2018)
Costa, D., Andrzejak, A., Seboek, J., Lo, D.: Empirical study of usage and performance of java collections. In: Proceedings of the 8th ACM/SPEC on International Conference on Performance Engineering, ICPE 2017, pp. 389–400. Association for Computing Machinery, New York (2017)
Costa, D., Mujahid, S., Abdalkareem, R., Shihab, E.: Breaking type-safety in go: an empirical study on the usage of the unsafe package. IEEE Trans. Softw. Eng. (01), 1 (2021)
Crasso, M., Mateos, C., Zunino, A., Misra, S., Polvorin, P.: Assessing cognitive complexity in java-based object-oriented systems: metrics and tool support. Comput. Inf. 35, 497–527 (2014)
Evans, A.N., Campbell, B., Soffa, M.L.: Is rust used safely by software developers? In: Proceedings of the ACM/IEEE 42nd International Conference on Software Engineering, ICSE 2020, pp. 246–257. Association for Computing Machinery, New York (2020)
Khatchadourian, R., Tang, Y., Bagherzadeh, M., Ahmed, S.: [engineering paper] a tool for optimizing java 8 stream software via automated refactoring. In: 2018 IEEE 18th International Working Conference on Source Code Analysis and Manipulation (SCAM), pp. 34–39 (September 2018)
Khatchadourian, R., Tang, Y., Bagherzadeh, M., Ahmed, S.: Safe automated refactoring for intelligent parallelization of java 8 streams. In: Proceedings of the 41st International Conference on Software Engineering, pp. 619–630. IEEE Press (2019)
Khatchadourian, R., Tang, Y., Bagherzadeh, M., Ray, B.: An empirical study on the use and misuse of java 8 streams. In: FASE 2020. LNCS, vol. 12076, pp. 97–118. Springer, Cham (2020). https://doi.org/10.1007/978-3-030-45234-6_5
Martins, P., Achar, R., V. Lopes, C.: 50k-c: a dataset of compilable, and compiled, java projects. In: 2018 IEEE/ACM 15th International Conference on Mining Software Repositories (MSR), pp. 1–5 (May 2018)
Mastrangelo, L., Hauswirth, M., Nystrom, N.: Casting about in the dark: an empirical study of cast operations in java programs. In: Proceedings of the ACM on Programming Languages 3 (OOPSLA) (October 2019)
Mastrangelo, L., Ponzanelli, L., Mocci, A., Lanza, M., Hauswirth, M., Nystrom, N.: Use at your own risk: the java unsafe api in the wild. SIGPLAN Not. 50(10), 695–710 (2015)
Mazinanian, D., Ketkar, A., Tsantalis, N., Dig, D.: Understanding the use of lambda expressions in java. Proc. ACM Program. Lang. 1(OOPSLA), 1–31 (2017)
Misra, S., Cafer, F., Akman, I., Fernandez-Sanz, L.: Multi-paradigm metric and its applicability on java projects. Acta Polytechnica Hungarica 10, 203–220 (2013)
Nagappan, M., et al.: An empirical study of goto in c code from github repositories. In: Proceedings of the 2015 10th Joint Meeting on Foundations of Software Engineering, pp. 404–414. ESEC/FSE 2015, Association for Computing Machinery, New York (2015)
Oliveira, W., Oliveira, R., Castor, F., Fernandes, B., Pinto, G.: Recommending energy-efficient java collections. In: 2019 IEEE/ACM 16th International Conference on Mining Software Repositories (MSR), pp. 160–170 (2019)
Sandoval Alcocer, J.P., Bergel, A.: Tracking down performance variation against source code evolution. In: Proceedings of the 11th Symposium on Dynamic Languages, pp. 129–139. DLS 2015, Association for Computing Machinery, New York (2015)
Sandoval Alcocer, J.P., Bergel, A., Valente, M.T.: Learning from source code history to identify performance failures. In: Proceedings of the 7th ACM/SPEC on International Conference on Performance Engineering, ICPE 2016, pp. 37–48. Association for Computing Machinery, New York (2016)
Sandoval Alcocer, J.P., Bergel, A., Valente, M.T.: Prioritizing versions for performance regression testing: the pharo case. Sci. Comput. Program. 191, 102415 (2020)
Acknowledgments
Bergel thanks ANID Fondecyt 1200067 for partially sponsoring this work.
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2021 Springer Nature Switzerland AG
About this paper
Cite this paper
Nostas, J., Alcocer, J.P.S., Costa, D.E., Bergel, A. (2021). How Do Developers Use the Java Stream API?. In: Gervasi, O., et al. Computational Science and Its Applications – ICCSA 2021. ICCSA 2021. Lecture Notes in Computer Science(), vol 12955. Springer, Cham. https://doi.org/10.1007/978-3-030-87007-2_23
Download citation
DOI: https://doi.org/10.1007/978-3-030-87007-2_23
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-87006-5
Online ISBN: 978-3-030-87007-2
eBook Packages: Computer ScienceComputer Science (R0)