Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7559059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:32:17+00:00 2026-05-30T12:32:17+00:00

Here is my code: public static String currentStudent = ; public void login() {

  • 0

Here is my code:

public static String currentStudent = "";


public void login() {
  boolean studentLoggedOn = false;
  Student student = new Student();
  PC_Dialog dialog = new PC_Dialog("Enter Login Information", "Student ID, Password-", "OK");
  dialog.choice();

  String studentID = dialog.getField(1);
  String password = dialog.getField(2);

  student = (Student) projectSystem.studentFile.retrieve(studentID);

  if (studentID != null) {
     if (password.equals(student.password)) {
        currentStudent = studentID;
        studentLoggedOn = true;
        studentRun();
     }
  }

  if (!studentLoggedOn) {
     JOptionPane.showMessageDialog(null, "Either the user name or the password were incorrect");
     login();

}
   }

After all of that, the “currentStudent = studentID;” doesn’t seem to have any effect on the currentStudent String?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:32:19+00:00Added an answer on May 30, 2026 at 12:32 pm

    Your question is incomplete, but if I had to guess, I’d say you have a reference to currentStudent somewhere else in your code. Since strings are not mutable and the assignment operator also does not mutate objects, this reference would not change.

    For example:

    String one = "some string";
    String two = one;
    one = "another";
    System.out.println(one);
    System.out.println(two);
    

    Will output

    another
    some string
    

    Try reading up on Java references and string assignment.

    Per the question author’s request here’s an example that accomplishes what I think he wants.

    public class Session {
        private String currentUserId = null;
        public void setCurrentUserId( String id ) {
            currentUserId = id;
        }
        public String getCurrentUserId() {
            return currentUserId;
        }
        // Other session related information
        //... 
    }
    

    And use the Session class as follows.

    public class MyApp  {
        private Session currentSession;
        public MyApp() {
            currentSession = new Session();
        }
        public void login() {
            //...
            if ( studentID != null ) {
                if ( password.equals(student.password) ) {
                    currentSession.setCurrentUserId(studentID);
                    //...
                }
            }
            //...
        }
        public void someOtherMethod() {
            System.out.println(currentSession.getCurrentUserId());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code : public static void main(String[] args) { // System.setProperty( //
Here's the code snippet: public static void main (String[]arg) { char ca = 'a'
Here is a sample code: public class TestIO{ public static void main(String[] str){ TestIO
Here's the relevant code: public static String[] runTeams (String CPUcolor) { boolean z =
Here is the code: public static void main(String[] args) { SocketWorker worker = null;
Here is my code: public class Main { public static void main(String[] args) {
Here is my code: public class Main { public static void main(String[] args) {
Here's the relevant code snippet. public static Territory[] assignTerri (Territory[] board, String[] colors) {
Here's the sample code: public static void col (int n) { if (n %
Here's the relevant code: public static void printBoarders (Territory x) { int t =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.