Machine Learning Approaches for Predicting Defective Java Code Using Software Metrics
DOI:
https://doi.org/10.20508/9j0jxz49Abstract
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.