Java- Data Storage and Running the Program Automatically? - java

So I want to do a program in Java that does the following:
1. Opens each day when the user accesses his computer after a certain time (e.g. 5pm)
2. Asks the user for string input (the highlight of his day)
3. logs it and Saves it then closes
4. Opens the next day on the first time the user accesses his computer and shares a random entry from previous entries with the time and date of the input (e.g. ice cream with the kids Monday 8/4/2013)
5. repeats
I am not certain what topics or domains I need to look for tutorials on to cover numbers 1,3,4. In other words, what topics should I check to do the following:
make the program run by itself after a certain time (5pm) + when it is run for the first time the next day (I am operating on a mac do I need to look into cocoa os for this?
Storage; something like persistent storage in swift - do I just look into that or do I need to get into databases?
I am looking primarily for the main topics that I need to look further into to get this done (guidance for resources, not the code). Thanks!

To have a program run at a scheduled time, you would use a program like crontab. This is available on most Unix based operating systems including OSX. Basically you enter the scheduled time, and give it an executable to run at that time. You might have it run something like java -jar /path/to/your/java/program.jar
As for storage, you can store things in many ways. The simplest way is to read to/write from a file. Java has library classes that can handle this i.e. FileReader, FileWriter.
Another way is to use a database (SQL, SQLite, MongoDB). To do this you will need to install a database, and use a database driver in your java program. A good search term is JDBC.

Related

Java software: disable after a specific date

I'm developing a simple software for a professor of mine. Nothing special, it just takes some data from some sites and merge them into a text file that will be analyzed from an R program.
Anyway, he asked me a "particularity": this software will be used by his students but he wants for it to be useless after this weeks of lessons. How can I achieve that? They are not computer science students, so something "simple" should be fine, but anyway I need some suggestions. I was thinking to create a web service, but I'm hoping for something else. I've searched and I could not find something useful for me.
I had done this for one of my projects.
Created a file on S3 with restricted access.
Every time the app is executed, i request for this file.
If it exists, i allow them to use the app else System.exit(1).
In your case, you can use this strategy with one file containing the end date, being the date of last class.
Fetch current date time from some public API.
Everytime the app is launched, fetch this file from S3, parse the end date and check for expiry.
Drawback: In case of No internet, the app will not be usable.

How can the java application user modify/update application files on the web?

I am developing a java application(although, I am unsure if it should be developed as a desktop application, applet, or JWS).
The application is basically a database of homeworks and tasks in physics.
It uses .txt files in which it keeps records of these tasks, and the user has to have the ability to modify theese .txt files(through the API I will provide to the user - basically, the user can add tasks, or remove tasks, and, upon adding or removing a task the changes should be modified in the .txt files).
For example, if 'tasks.txt' contains the following lines:
0
1
2
These numbers(0,1,2) are interpreted as TaskId, meaning the database 'tasks.txt' represents contains 3 tasks, and their ID's are: 0, 1, and 2.
If a user is to add a task, the database('tasks.txt') would change into:
0
1
2
3
The task with ID 3 is the newly added task.
Now, I have already developed a GUI using Swing, which allows the user to add tasks, and remove tasks using add/remove buttons, and these actions update the 'task.txt' file. In order not to be misunderstood, let me say that I already have this functionality for a desktop(stand-alone) java application.
What I don't know how to do(or how to even approach it/which java technollogy to use, or how this is usually done) is the following:
I would like all the users, when they download and start my application, to be able to read from the same task database('tasks.txt')
All the changes one user makes to the database from a remote computer, should somehow be updated for all users, for example:
If a user from a home computer in China adds a new task, the user from a home computer in France should be able to see this change(this new task)
So, how can I accomplish this. Should I keep this .txt file on some webpage, and then access it and modify it(could you refer me to some articles explaining how is this done).
Should I develop my app as an applet, and then somehow modify the 'tasks.txt' file on webpage(and how can applets modify files on webpages)?
I am quite new to web development, so any articles explaining communication between users through webpages are more than welcome.
Thanks for your help.
Should I develop my app as an applet,
No! See Why CS teachers should stop teaching Java applets for lots of reasons not to code applets.
..and then somehow modify the 'tasks.txt' file on webpage(and how can applets modify files on webpages)?
The 'somehow' is with the help of the server. Add a JSP/servlet that the client side app. uses to perform the change.

Implementing a Trial

I have made an application in which I want that the application should expire after say 180 Days but the problem is that if I take the system date, anyone could just change it and get going and I cannot also take the internet date because many times the user will be working offline. So how do I make it trial after which it self destructs itself? I cannot put any other DRM as I have read that checking MAC address is a very bad DRM and after going through Making commercial Java software (DRM) I realised I have to make it somewhat simple. So the idea I have in mind is that I put a count that how many times has the application being started, but where do I store the value in registry? (I have already read: read/write to Windows Registry using Java)
I have also read Create a trial version of a Java application, with limited functionality and How to create a trial version of a Java program but the answers given there were not satisfactory. Because:
1. In one answer it is given that use "Rampart" but that is a paid application and I do not want to use it.
2. In another answer they checked with system date but as I told earlier I do not want to use that either.
3. One Question and Answer was related to functionality which is not what I want to reduce
4. and further many of them require internet but my customers may not be using it all the time
I know that there is no perfect DRM and everyone of them can be cracked. What I am asking here is what is my best shot? (Note: I have limited number of users, I will not sell this application online)
Update: This question I believe is not off topic because what I really am asking is just how do I make my software go trial... I am just asking how? I know it can be cracked easily but just tell me what is the best way to set up a trial in java
Ship a data file with the package containing:
The name of the customer in full.
The date it was shipped.
The date it should expire.
A checksum of the whole file so it cannot be edited.
Every time you run:
Check that the checksum is still valid.
Check that the file mod date does not suggest that the file has been tampered with.
Display the customer name in a splash screen.
Make sure the mod date on the file is not later than the expiry date.
"Touch" the file to make sure it's mod-date changes to current date.
Make sure the "Touch" worked.
This way:
It is difficult to make a copy as the mod date will change.
It is difficult to distribute copies to others as the source is easily available.
It should be possible to detect most inexpert tampering.
Obviously - without adding hardware - it is impossible to cover all bases but I have found this scheme works well.
If internet connection is not available, there is one method left behind if end-users are in a company network and using windows with active directory (most companies have active directory if clients are windows), use active directory server as a time server. Most users may change clock time on their client windows, but they don't want to change time on their servers due to other affecting software (mail server etc). License4J can find and check date/time on a local active directory server.
(Disclosure: I work for License4J)

Storing Data in Java

I'm currently trying to write a simple journal-like program in Java that allows me to add "entries" and be able to browse all the "entries" I have added since the very beginning. The problem is, if I run the program, add two entries, exit the program, and then run the program again, I want to be able to have access to the two entries I previously added. I guess my questions is then, how am I able to "save" (if that's the right word) the entries that I add so that they won't be wiped out every time the program terminates?
I did some looking around, and it appears there's a tool I can use called the Java Cache System, but I'm not entirely sure if that's what I need for my situation. I'd appreciate if somebody could point me in the right direction.
When you run the program and create the entries your storing them in primary storage aka RAM. As you have discovered these entries will not persist across different executions of your program.
You need to store the entries in secondary storage aka the hard drive. This can be done by writing the entries to a file saved on disk and then reading those entries upon startup of the program. Java provides several mechanisms to read and write files to the file system on a machine.
Some applications use a database to store information in a relational manner so that it is available via a SQL request, however I would recommend using a simple file to store your entries.
The simplest way would be to store this data somehow in a file, and then read it from the file when the application starts, a few simple examples on how to write/read from file:
http://www2.cs.uic.edu/~sloan/CLASSES/java/MyFileReader.java
http://www2.cs.uic.edu/~sloan/CLASSES/java/MyFileReader.txt
http://www2.cs.uic.edu/~sloan/CLASSES/java/MyFileWriter.java
http://www2.cs.uic.edu/~sloan/CLASSES/java/MyFileWriter.txt
Now, you store your objects in memory instead of this you can try to serialize them to some format like xml. And then in next run load them from xml. Or you can try to use dataBase for storing objects.
I faced same problem in past but little bit different.I clearly understood your problem , My solution is whatever the journal you are entering and getting saved should be saved in a particular location in your Location such as "C:\Your_Directory\Journal_folder\"
so it will be easier when you initially enter the journal it stores in above location ,again if u exit and reopen the application just try to retrieve the data from the above Mentioned target Location.
therefore every time when ever you enter the application it retrieves the data from that location if not it displays empty

Message freshness & validity JAVA PHP mysql

NOTE: program in java, server uses php, and mysql...file is .log or .txt file
I have a program which takes the last line from a txt file and sends it via HTTP request to a server. The file is written by an external program, but the user is be able to open it an modify it.
The lines are in this format, and the time will be in the local computer time.
[hh:mm:ss] Message
If I consider that the time in the (real) message IS the time in the computer can I use it to verify the freshness and validity by comparing with a time in a fix location? (server time, gtm time, etc)
The users could be anywhere around the world, and I cannot guarantee that the time in the local machine is exact. My idea would be to start the program and check for time on machine, and compare it to my external time. then somehow manage to make sure that the message was not done by the user....for example message should have to be 20s~ computer time and time in computer should be synchronized with external time.
Never done something like this, but really interested.
(I know there will never be a hacker proof program, but would like to make it as hard as possible)
Thanks, I will add details in the afternoon if needed.
Two options for Time Issue:
If you can modify the program that creates the file, always use a fixed timezone to write the time. This will ensure the time is accurate across all timezones.
OR you can write the timezone along with the time and compute accordingly at server side.
Regarding User Tampering the data:
I suggest you generate a MD5 hash of the message and send it along. Then compute the MD5 from message contents again at server side. If the hash does not match the MD5 passed to server, it means the user has tampered the data.

Categories

Resources