I have big trouble understanding why my code does not work
I have created a simple login/register in javabut when i click login button it always states that account is incorrect, when i click register it registers a new account with the same username(while i have placed many restrictions to avoid it)
Can you guys maybe spot the bad logic in my code?
Here is my code
The 2 actionlisteners
and is the class var i am using to store things
the method user has a String, a char and a boolean with getters and setters.
Also I am passing var variable from main(initialization and declaration) to every class and I plan to load/save it as a file when i succeed making it work.
God did not knew that == and equals() can produce different results.
I am a junior college programmer and I have never seen any of my instructors using equals.
posted 1 year ago
Couldn't edit my first post, by changing the == to .equals() it fixed the problem on my Registration ( when i logout and try to create a new user with the same username the error is displayed).
I also forget to post that method which is used in Login actionlistener (where the problem still persist)
and after your very nice comment on return condition;
Arrays.equals() seems to fix the password problem and now login/register fully works. Thanks for the comments guys, I am going to rename my classes and variables accordingly and keep doing it this way from now.
Well done sorting it out Another thing I noticed is that you have a method with Boolean return type, which is an object. You probably wanted to get a boolean, which is a primitive. Because of boxing conversion, you won't notice any difference in functionality, but under some circumstances that B might cause performance problems.
If you look here in the Java® Language Specification and here about the Object class, you can, I hope, work out that
array1.equals(array2) only tests whether the two are the same object, using ==. What if we didn't call == the equality operator? Maybe it would be better to call it the same object operator. Just maybe.
If you look in those links, and in Arrays#equals(), you don't find anything about equals() using == on arrays. I think they presume we know that about un‑overridden equals() methods.
By the way: If you go through the documentation for a class, like this one, and you find it says equals in the section headed