Get the current time in various places and print it out. long time = System.currentTimeMillis()
Where milliseconds is since January 1, 1970, 00:00:00 GMT.
If you want to see this as a proper date, use a java.util.Date object new Date(long milliseconds)
Methods to find if a date is before or after a Date, or set the date in it.
Checking memory
Computers store most of the information they need to do processing in a memory chip.
If the space available is exceeded by the data, most write to 'Virtual Memory' - this is part of the harddrive and acts as if it's 'real' memory.
Using Virtual Memory is slow, because it uses magnetic media that are slow to write to.
If the Virtual Memory is exceeded, processing will become very slow, and the system unstable.
Finding out about the computer
Remember, the environment the program is running in is encapsulated by a java.lang.Runtime object.
The current Runtime can be got with a static method. Runtime rt = Runtime.getRuntime();
Runtime has methods to
Deal with the computer memory.
Interact with the JVM interpreter.
Computer memory
Java copes with memory well, but occasionally we may want to check it.
For example, if a file is much larger than the real memory, we may want to only read in small chunks at a time.
These return the free and total memory available in the computer.
Garbage Collection
'Garbage Collection' is a general computing term for clearing up objects we no longer need from memory.
Objects will stay in memory until collected, even if not used.
Java does automatic Garbage Collection, when memory gets low, but you may want to force it.
runtimeObject.gc();
Unit Testing
A way to ensure that methods have the desired 'behaviour'
Decide on behaviour
Write tests
Write code to satisfy tests
Time consuming
Produces robust code
Future maintenance is easier
Other tests
Stress testing
Alpha/Beta releases
Usability
Regression testing
Software testing
Summary
Good code structure centres on building to interfaces: are the inputs and outputs to methods and classes reliable, and do they respond well if things go wrong.
Get this right, and you'll minimise bugs.
Unit testing formalises this.
However, also test usability and go through alpha and beta test releases.