Hi @Afzal Ghani,
Since our forum focus on C#, I am not familar with java. After doing some research, there seems no such function to connect sharepoint with rest api using username/password. You will need to register sharepoint app only. Here is a similar issue with yours, the answer need to use clientId and secret.
If you could use C#, I would recommend you to use CSOM. By using CSOM, we could connect sharepoint with username/password directly. You could refer to following article
https://www.c-sharpcorner.com/blogs/office365-how-to-connect-sharepoint-online-site-using-csom
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.