I use the free Netbeans IDE for programming. Eclipse is the other good option.
The CERN Colt routines are good for lists (vectors, variable length arrays) linear algebra and data analysis. I have yet to find a readable introduction to this package or simple examples but they must be out there.
The JUNG java graph library looks very good for networks but I have yet to break into it. There are good example routine provided but the manual lags well behind the implementation. I have also found it to be very slow on some occasions. I suspect I do not know how to use it efficiently and that my Java needs to be improved to get the most out of this. The JUNG wiki might provide the answers to my problems.
David Eck's Java Notes are an excellent and free introduction. I even bought the printed version as I liked them so much. I also use the input routines described in his book which are also provided free, such as textreader.java.
Outputting graphics to bitmap files is easy. For instance look at the GraphEditorDemo.java in the JUNG package. Postscript or other vector file output is less trivial. The VectorGraphics library of FreeHEP Java Libraries looks very useful and claims to contain PostScript, PDF, EMF, SVF, and Flash SWF, along with the image formats GIF, PNG, JPG and PPM. I have also seen recommended jlibeps which is a fork of the no longer free (if cheap) EpsGraphics2D.
Options parsing looks easy using the ritopt package but I have yet to try it.
java -Xmx2000m -classpath "%PRGDIR%\JAVA\TheProject\dist\project.jar";. project.MakeNetworks %1 %2 %3 %4 %5 %6 %7 %8 %9here this show the use of an environment variable PRGDIR which is set using the set command in Windows batch files. The -Xmx2000m sets the virtual memory to be 2GB. This is the amount of memory you give your code. Note that I found that 1.4Gb was about the most I could get under 32bit versions. I found I could expand it to 3Gb on a 4Gb machine only if I used the 64bit version of java.
Unfortunately it appears it is easy to have several versions of java of different ages and types (32 or 64 bit) so be careful. It is not always obvious which one plain java calls when entered from the command line. The Program Files holds the java files in a java directory however it is possible that other programmes have their own versions and that these are being run. I found QuickTime on my system was messing things about. Some commands I find useful to work out what is going on, all run in a command window are as follows
"FULLPATH\java" -version "FULLPATH\java" -XshowSettings:allThe version should display 64bit in its message if its a 64 bit version. If you do not see this then you are running a 32bit version. I uninstalled the older versions I could see version and found the explicit path to the latest one and copied this into the command window to be sure I was running a 64 bit version e.g.
C:\>"C:\Program Files\Java\jre7\bin\java" -version java version "1.7.0_10" Java(TM) SE Runtime Environment (build 1.7.0_10-b18) Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)This was how I found typing just java was running something else.
String outString = String.format("%6.3f",doubleValue);gives a string representation of the doubleValue which fills 6 spaces, and keeps 3 digits after the decimal point. Remember that this means the sign, decimal point and the integer part must all fit in 6-3=3 characters.
System.out.printf("%9.3e",doubleValue);gives the scientific notation. Again the 3 is the number of digits after the decimal point but now there is always just one integer between 1 and 9 in front of the decimal point. The power of ten is then given after an e character. So you need to leave room for up to two signs, the e and the decimal place. The g flag will choose between f and e flags as needed.
For integers don't use i, the flag is d
String outString = String.format("%6d",intValue);For hexadecimal the flag is x.
Character.isLetter(line.charAt(0)) Character.isDigit(line.charAt(0)) Character.isWhiteSpace(line.charAt(0))
String[] word = line.split("\\s+");
String[] word = line.split("[\\.\\s]+");
line.replaceAll("[\\x00-\\x20]", "_");
line.replaceAll("\\s","")
line.trim()
try{ double d=Double.parseDouble(line.trim()); int i=Integer.parseInt(line.trim()); } catch (RuntimeException e){ System.err.println("Failed to convert a number"}; }No white space seems to be tolerated by these methods hence the use of the trim() method on the strings first.
@see package.Class @see package.Class#field @see package.Class#Constructor(Type, Type...) @see package.Class#Constructor(Type id, Type id) @see package.Class#method(Type, Type,...) @see package.Class#method(Type id, Type, id)If you want a link to code in the main text then use
{@link package.class#member label}
For URL, in the main text of a javadoc you can use the URL and any text you like (e.g. the full URL)
<a href="http://netplexity.org">http://netplexity.org</a>Alternatively at the end you can add a
@see <a href="http://netplexity.org">http://netplexity.org</a>
For constants it is useful to use the value tag
{@value package.class#field}
If you want to have text in the font used for code without the text being interpreted as HTML markup, e.g. for equations, then try
{@code text}
System.getProperty("file.separator");. However java seems to be tolerant and at least on windows paths can contain a mixture of both forward and backwards slashes and they still work.
System.getProperty("path.separator");
System.getenv(env);where String env contains the name of the environment variable. null is returned if it does not exist.
final String fs = java.lang.System.getProperty("file.separator"); if (!directoryName.endsWith(fs)) directoryName=directoryName+fs;though the file separator is available as constants discussed above. Perhaps more useful are items which could vary on one machine. In particular
Key | Description of Associated Value |
---|---|
java.version |
Java Runtime Environment version |
java.vendor |
Java Runtime Environment vendor | java.vendor.url |
Java vendor URL |
java.home |
Java installation directory |
java.vm.specification.version |
Java Virtual Machine specification version |
java.vm.specification.vendor |
Java Virtual Machine specification vendor |
java.vm.specification.name |
Java Virtual Machine specification name |
java.vm.version |
Java Virtual Machine implementation version |
java.vm.vendor |
Java Virtual Machine implementation vendor |
java.vm.name |
Java Virtual Machine implementation name |
java.specification.version |
Java Runtime Environment specification version |
java.specification.vendor |
Java Runtime Environment specification vendor |
java.specification.name |
Java Runtime Environment specification name |
java.class.version |
Java class format version number |
java.class.path |
Java class path |
java.library.path |
List of paths to search when loading libraries |
java.io.tmpdir |
Default temp file path |
java.compiler |
Name of JIT compiler to use |
java.ext.dirs |
Path of extension directory or directories |
os.name |
Operating system name |
os.arch |
Operating system architecture |
os.version |
Operating system version |
file.separator |
File separator ("/" on UNIX) |
path.separator |
Path separator (":" on UNIX) |
line.separator |
Line separator ("\n" on UNIX) |
user.name |
User's account name |
user.home |
User's home directory |
user.dir |
User's current working directory |
for (int i=0; iby System.arraycopy(inputFriction, 0, friction, 0, friction.length);.