Posts Tagged ‘java’

Creating temporary files in Java

Posted: 9th July 2015 by Tim in Java
Tags: , , , , ,

Sometimes it is necessary to use temporary files in your program. One concern when creating these files is thread safety; two processes creating a temporary file with the same name. This concern can be largely ignored using Java’s File.createTempFile, which guarantees the file path is unique amongst all java processes running on that JVM. For […]

If you have a JAR file and want to print the details from MANIFEST.MF, this can be done with one command in linux, using the unzip utility. For example: $ unzip -p /usr/share/java/hsqldb.jar META-INF/MANIFEST.MF Manifest-Version: 1.0 Created-By: 1.7.0_03-b147 (Oracle Corporation) Specification-Title: HSQLDB Implementation-Title: Standard runtime Class-Path: /usr/share/java/servlet-api-3.0.jar Main-Class: org.hsqldb.util.SqlTool Ant-Version: Apache Ant 1.8.2 Implementation-Vendor: buildd […]

If you need to randomize or shuffle a List in Java (ArrayList, LinkedList, etc) you can do this with the Collections.shuffle(<list>) function. This is a static function which works on all List types. For example: import java.util.ArrayList; import java.util.Collections; … ArrayList<Integer> myList = new ArrayList<Integer>(); for (int x = 0; x < 10; ++x) { […]