Machine Learning Approaches for Predicting Defective Java Code Using Software Metrics

2026

Closed access Metadata (CSL-JSON)
DOI 10.20508/9j0jxz49
Data confidence 85 high
How this score is calculated

It is built from checkable properties of the record itself: whether the article has a DOI, how many independent sources confirmed its data, whether the required fields are filled in, and how recent the latest confirmation is. Disagreement between sources and a missing identifier lower it. A value of 80 or above means the record was published without further checking; 60 to 79 means it is published at reduced confidence, with a manual check advisable. A record verified by an editor by hand is never pushed below 90 by a recalculation. This scores our data about the article, not the article itself.

Abstract

In modern software engineering, ensuring software quality and dependability is still a major task, especially for large-scale Java projects where human source code inspection is impracticable. Early identification of defect-prone code segments is essential to reduce maintenance costs, prevent functional failures, and improve development efficiency. This study uses static code metrics collected from Java classes to examine the efficacy of machine learning models for software defect prediction. Publicly available datasets from Defects4J were collected, preprocessed, and analyzed using Chidamber–Kemerer metrics, including Coupling Between Objects, Weighted Methods per Class, and Lack of Cohesion in Methods. Three machine learning algorithms—Logistic Regression, Random Forest, and XGBoost—were evaluated in terms of Accuracy, Precision, Recall, F1-Score, and ROC-AUC. Random Forest achieved the highest overall accuracy (93.56%) and F1-score (93.45%), indicating robust classification performance, while XGBoost attained the highest recall (96.43%) and ROC-AUC (97.56%), demonstrating superior capability in detecting nearly all defect-prone instances. A trustworthy baseline with acceptable interpretability was given by logistic regression. These results align with prior studies highlighting the superiority of ensemble learning methods over traditional classifiers. To bridge the gap between research and practical application, the best-performing model was implemented in a web-based prototype, allowing users to upload Java source files and receive real-time defect predictions. The system operationalizes software defect prediction, supporting early intervention and improved code quality management. Future research may extend this work by exploring deep learning or hybrid ensemble approaches, evaluating cross-project generalization, and incorporating additional programming languages to enhance predictive accuracy and real-world applicability. All things considered, this study shows that metric-based machine learning may successfully predict software flaws while giving developers useful information.