Detect first time user in Java application [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am creating a sign-in and sign-up form just for practice. When the application runs for the first time, I would like the sign-up form to show first. How can I detect that the application is running for the first time?

One thing you could do is to check for the existence of a file. If it exists, then you know the application has been run before, otherwise you know that it has not run before, and so you create it.
File file = new File("some/path/filename.txt");
boolean firstRun = false;
if(!file.exists()){
firstRun = true;
file.createNewFile();
}
if(firstRun){
// Code to run if it is the first time running the app
}else{
// Code to run if it is not the first time running the app
}
In the future, this file could potentially be used for user configuration and such.

A sign up changes the state of your application. After it, there is a signed up user. So, what you might want is to check if there is a signed user. If you check for the first start, the user might exit the program without sign up and will never be asked for sign up on subsequent starts.

Related

How to keep user input even after rerunning the program (JAVA) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
This post was edited and submitted for review 9 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I only started coding about a month ago and I am trying to add a code or program to my work in order to make it store user input and even after rerunning the program, the input will still be kept. Confused? For example, when you make an account on Facebook, they will keep your email and password so next time you just have to login without making the account again. Something like a database to store value I am guessing?
When a program terminates, it looses all the values stored in variables.
This is because we have a GC (Garbage Collection) mechanism which helps to clear up data which are not used.
In your case, to persist data post restart, we need to store to some external store (persistent storage) rather than keeping in the memory.
Your external store can be a database or can be a simple file.
Create a file and store your values in it. Once you restart the program, read the values again from it.
You would require a storage to store the data, as rerunning will erase all previous data. Any filesystem/db can be used to resolve your issue.

how to implement a variable whose value is not lost after every run? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I wish to implement a variable (in Java) whose value is either stored somewhere or is not reset every time I run the program.
It's related to a "Booking reference Number" for a flight program. I know database connectivity but make a new data base for one variable is pretty pointless. Any ideas as to what I should/can do?
Also I don't want the numbers to be random I want them in order like if the first booking ID is 100 then the next one should be 101 and so on.
Organize your data in a structure and then serialize it.When you re-run your program, look for that serialized version in the file system, if there is any, read it. Viola.!
You should write the variable to a file and then read it from the file the next time you run the program.

basic user account lockout system [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I've currently got a system with a user account and login system. I'm trying to implement a "lockout" function, so that after 3 incorrect password attempts, the user is locked out. Currently this only involves a popup window, and simply warns the user instead of locking them out. I'm trying to find a good way to do this, based around a timeout so after a set amount of time the user can try to access their account again.
One idea I have is to write the time of lockout to a text file, and then have the system check for the previous lockout time from this text file and allow login if enough time has elapsed, however this seems to be an inelegant way to solve this.
Is there any other ways that this could be done? thanks
Usually, you'll use a database with fields like
id
username
password
failedAttempts (int)
lastFailed (date)
lastLogin (date)
When they fail to login, you increment failedAttempts and save the time in lastFailed.
Then on login, you check if (failedAttempts < threshold) or ((now - lastFailed) > timeThreshold).
On login you reset failedAttempts = 0, and lastFailed = null

How to: When application updates, automatically clear previous application' s data [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have code which is running with preference data. I have very simple boolean control store in preference. When I update my application, I'm seeing that it doesn't clear data and is running with previous data. I have to fix that problem tonight, what is your suggestion about this? Thank you
Make your application read a "version" value from the preferences. If that version is not there, or is not the same as the current version, then you can clear/update/migrate the preferences to the new version.
I'm writing from iPad, so I can't write more code. I did something that U want to do a longtime ago )))To clear all data use this. And then in loading activity use something like this:
if (BuildConfig.VERSION_CODE < #version code from preferences#) {
// clear data
// save new version code to preferences
}
Always when user updates his app, this code will clear data if the application's preferences have no >= version code.

Set one active screen from two? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I run background service within this application and gui part.
I have two screens in my application, one is registration screen the other one is updatestatus screen, after my registration is complete i have to view only one screen no matter when the user is want's to get into application.
I would really appreciate a small piece of code that does that.
Thank you in advance.
public GuiApplicationUI() {
if (!isOk) //if registered then enter the updatescreen
pushScreen(new RegisterScreen());
else
pushScreen(new UpdateScreen());
}
}
In my applications, I use Persistence Store to store any state of the app. Once user has successfully registered, update state in persistence store to "registered". Now whenever you want to push screen, check state of registration from persistence store before taking action.

Categories

Resources