It is necessary to activate your gmail account to be accessed from less secure app. For this purpose You should have to be login to your gmail account which you want to for sending/receiving email using java and then just visit following link whose screenshot is given below.
Now you have to click the toggle button to ON the allow less secure apps.
It will allow your java program to access your gmail.
If you need video instruction regarding program just follow these two videos:
How to fetch email from Gmail using javamail API
How to send email from your gmail using Java