I didn't write the login code yet.Mainstatic AccountLogin objAccountLogin = new AccountLogin();static AccountRemover objAccountRemover = new AccountRemover();static AccountCreator objAccountCreator = new AccountCreator();static Accounts objAccounts = new Accounts();public static void main(String[] args) {        startDiary();    }public static void mainMenu(){    System.out.println();    System.out.println(Welcome to Diary!);    System.out.println(1- New Account);    System.out.println(2- Login To Your Account);    System.out.println(3- Remove Account);    System.out.println(4- Exit);    System.out.println();    usersChoice();}public static void usersChoice(){    int choice = 0;    while(true){        try{            Scanner scan = new Scanner(System.in);            System.out.print(Choose an option: );            choice = scan.nextInt();            break;        }        catch(Exception e){            System.out.println(Invalid Input!\n);            }        }    switch (choice){        case 1:            choiceNewAccount();        case 2:            choiceLogin();        case 3:            choiceRemoveAccount();        case 4:            exit();            break;        default:            System.out.println(Invalid Input!\n);            usersChoice();   }}public static void startDiary(){    objAccounts.loadAccounts();    mainMenu();}public static void choiceNewAccount(){    objAccountCreator.createAccount();    mainMenu();}public static void choiceLogin(){    objAccountLogin.login();    mainMenu();}public static void choiceRemoveAccount(){    objAccountRemover.removeAccount();    mainMenu();} public static void exit(){    while(true){                try{                    Scanner exit = new Scanner(System.in);                    System.out.print(Are you sure you want to exit? (y/n): );                    char choice = exit.next().charAt(0);                    if(choice == 'y') System.exit(0);                    else if(choice == 'n') mainMenu();                                              else System.out.println(Invalid character!);                }                catch(Exception e){                    System.out.println(Invalid character!);                        }                     }                                       } Accountsprotected File usernamesFile = new File(D:Usernames.txt);protected File passwordsFile = new File(D:Passwords.txt);private static ArrayList<String> accounts_Usernames = new ArrayList<>();private static ArrayList<String> accounts_Passwords = new ArrayList<>();  protected void addToAccountsList(String username, String password){           addToAccounts(username,password);    loadAccounts();}private void addToAccounts(String username,String password){    addToUsernames(username);    addToPasswords(password);}private void addToUsernames(String username){    if(usernamesFile.exists()){        try (PrintWriter usernamesWriter = new PrintWriter(new BufferedWriter(new FileWriter(this.usernamesFile, true)))) {            usernamesWriter.println(username);            usernamesWriter.flush();        } catch (IOException ex) {            Logger.getLogger(Accounts.class.getName()).log(Level.SEVERE, null, ex);        }    } else System.err.println(File: Usernames Does Not Exist!);       }private void addToPasswords(String password){    if(passwordsFile.exists()){            try (PrintWriter passwordsWriter = new PrintWriter(new BufferedWriter(new FileWriter(this.passwordsFile, true)))) {                passwordsWriter.println(password);                passwordsWriter.flush();            } catch (IOException ex) {            Logger.getLogger(Accounts.class.getName()).log(Level.SEVERE, null, ex);        }    } else System.err.println(File: Usernames Does Not Exist!);  }protected void loadAccounts(){    loadUsernames();    loadPasswords();}private void loadUsernames(){           try (Scanner usernamesScanner = new Scanner(usernamesFile)) {        while(usernamesScanner.hasNext()){            String username = usernamesScanner.next();            if(!accounts_Usernames.contains(username))accounts_Usernames.add(username);        }    } catch (FileNotFoundException ex) {        Logger.getLogger(Accounts.class.getName()).log(Level.SEVERE, null, ex);    }}private void loadPasswords(){    try (Scanner passwordsScanner = new Scanner(passwordsFile)) {        while(passwordsScanner.hasNext()){            String password = passwordsScanner.next();            if(!accounts_Passwords.contains(password))accounts_Passwords.add(password);        }    } catch (FileNotFoundException ex) {        Logger.getLogger(Accounts.class.getName()).log(Level.SEVERE, null, ex);    }}protected ArrayList<String> getUsernamesList(){    return accounts_Usernames;}protected ArrayList<String> getPasswordsList(){    return accounts_Passwords;} AccountCreatorpublic void createAccount(){    Scanner scan = new Scanner(System.in);    System.out.print(Enter Your Username: );    String username = scan.next();           if(!isValidUsername(username)) System.out.println(Username Already Exists!);    else{         while(true){            System.out.print(Enter Your Password: );            String pass1 = scan.next();            System.out.print(Re-Enter Your Passowrd: );            String pass2 = scan.next();            if(!arePasswordsMatch(pass1,pass2)) System.out.println(Passowrds Don't Match!);            else {                addToAccountsList(username,pass1);                createTheUsersFile(username);                System.out.println(The Account Has Been Successfully Created!);                break;        }    }    }}private boolean isValidUsername(String username){              return getUsernamesList().stream().noneMatch((valid) -> (valid.equals(username)));}private boolean arePasswordsMatch(String pass1, String pass2){           return pass1.equals(pass2); }private boolean createTheUsersFile(String username){    File newUserFile = new File(D:+username+.txt);    try {        newUserFile.createNewFile();    } catch (IOException ex) {        Logger.getLogger(AccountCreator.class.getName()).log(Level.SEVERE, null, ex);    }    return newUserFile.exists();}AccountRemoverpublic void removeAccount(){        try{        remove();        refresh();         System.out.println(Account Has Been Successfully Removed!);    } catch(Exception e){        System.out.println(Could Not Remove Account!);    }   }public void remove(){    String accountName = canLogin();    removeFile(accountName);    removeFromList(accountName);         }public void removeFile(String accountName){    File deleteUsername = new File(D:+accountName+.txt);    deleteUsername.delete();           }public void removeFromList(String accountName){                   if(!accountName.equals(-1)) {         for(int i = 0; i < getUsernamesList().size();i++)                          if(getUsernamesList().get(i).equals(accountName)){                getUsernamesList().remove(i);                getPasswordsList().remove(i);                break;            }    }    else System.out.println(Can Not Erase Account!);}public void refresh(){    refreshUsernames();    refreshPasswords();}public void refreshUsernames(){    try (PrintWriter usernamesOverWriter = new PrintWriter(new BufferedWriter(new FileWriter(this.usernamesFile)))){        getUsernamesList().stream().forEach((b) -> {        usernamesOverWriter.println(b);                });    usernamesOverWriter.flush();    } catch (IOException ex) {        Logger.getLogger(AccountRemover.class.getName()).log(Level.SEVERE, null, ex);    }}public void refreshPasswords(){    try (PrintWriter passwordsOverWriter = new PrintWriter(new BufferedWriter(new FileWriter(this.passwordsFile)))){        getPasswordsList().stream().forEach((b) -> {        passwordsOverWriter.println(b);                });    passwordsOverWriter.flush();    } catch (IOException ex) {        Logger.getLogger(AccountRemover.class.getName()).log(Level.SEVERE, null, ex);    }}  Follow up: diary-application-with-accounts-v-2
Diary applications with accounts
java
Let's start at the beginning...usersChoice() tends to call itself again and again and again, leaving stuff on the stack. I would suggest putting the whole choice thing inside a...while(true) {... do your stuff here}...as the System.exit() in exit() will end the program anyway. Also you are not closing your scanner. In one piece of code you used the try-catch-with-resources...try (Scanner usernamesScanner = new Scanner(usernamesFile)) {...stick with that.You are creating at least 3 scanners, might be a good idea to see if you can move that read something from file or console code into its own method. loadUsernames() and loadPasswords() are the same code, and they only differ in where the text is stored, so you can merge that into one method. Same with the addToUsernames() and addToPasswords() - you even forget to change the error message when copy and pasting. Copy and paste, especially your own code, is not a good idea: If you need to change the code, you will very likely need to remember two places to change it. Merge them into one method by identifying which parts change.You are using a method canLogin(), but never declare it. Also, the name implies that the answer is true or false, but it seems to return the loginName. Method names should intuitively make clear what they will do, this one absolutely doesn't. Your methods tend to be a bit long. For example, the exit-method effectively does three things:Read from consoleCheck if the text is somethingExit, if yesYou could write that clearer by removing at least one of this things into its own method, for example...public void tryExit() {    String userConfirmedExit = askFromConsole(Are you sure you want to exit? (y/n)); // implement that method    if (y.equals(userConfirmedExit)) {       System.exit(0);    } else if (!n.equals(userConfirmedExit)) {       System.out.println(Invalid character!)    }     // in all other cases, simply return and the loop (see above) will bring back the menu}The whole code is still very static-based. I would try to remove every static method besides the main one.