Java Program of Login From


Write a program to check whether the user is an authorized user or not. Create a class Login with the private attributes userName and password,write a method public boolean validate() in the Login class, this method should check whether the given userName is john and the password is 123abc in that case return true else return false. Print “Valid user” or “Invalid user” based on the value returned from validate method. 
Note: Write a constructor in the Login to set userName and password. Include appropriate getter method

Sample Input 1:
Enter the username:

Enter the password:


Sample Output 1:
Valid user


import java.util.*;
public class Login
    private String userName,password;
    public Login(String userName,String password)
    public String getUserName()
        return this.userName;
    public String getPassword()
        return this.password;
    public boolean validate()
        if((this.userName).equals("john") && (this.password).equals("123abc"))
            return true;
    return false;
    public static void main (String[] args) {
        Scanner sc=new Scanner(;
        System.out.println("Enter the username:");
        String name=sc.nextLine();
        System.out.println("Enter the password");
        String pass=sc.nextLine();
        Login obj=new Login(name, pass);
            System.out.println("Valid user");
            System.out.println("Invalid user");


  1. Array square
  2. Generate number using odd digits
  3. Alternate Number Difference
  4. Next Greatest number
  5. Mark Comparison
  6. Print the characters in descending order
  7. Vowels in a fishBowl
  8. Least offer
  9. Ascending and descending order
  10. Mail Domain
  11. Count repeating words
  12. Sentence – Convert to upper and lower
  13. Count consecutive repeating characters
  14. Zig zag Array
  15. Pass and Fail Count
  16. Search a Course
  17. Average and Grade Calculation
  18. String – Find and replace the character (first occurrence)
  19. Sort the first and second half of an array
  20. Retail Shop
  21. Palindrome
  22. Numerology
  23. InitCap
  24. Array Compatiblilty
  25. Sum of the maximum and the minimum element
  26. String Concatenation
  27. Find Average Age
  28. Login

7 thoughts on “Java Program of Login From”

  1. Hola Lucas. En mi país (el Reino Unido) está bien cosechar trufas siempre y cuando se obtenga el permiso del propietario… si estás en la tierra de otra persona, por supuesto. Ten en cuenta que a veces esta cosecha deja un poco de desorden – ¡limpia el suelo después de ti para estar seguro! Espero que esto ayude – ¡y feliz cosecha! 🙂

  2. Thank you for every other fantastic article. Where else may anybody get that type of info in such an ideal manner of writing? I’ve a presentation next week, and I am at the look for such information.

  3. Wonderful items from you, man. I have take into accout your stuff previous to and you are just extremely magnificent. I really like what you have bought here, really like what you are saying and the way in which you say it. You are making it entertaining and you continue to take care of to stay it sensible. I cant wait to learn far more from you. This is actually a terrific web site.

Leave a Comment

Your email address will not be published. Required fields are marked *