$ mkdir src $ mv src.zip src/ $ cd src/ $ unzip src.zip $ mkdir api $ javadoc -J-Xmx1000m -d api -subpackages com:java:javax:org:sunw
Showing posts with label utility. Show all posts
Showing posts with label utility. Show all posts
01 October 2010
Generating a javadoc into a target folder
For the whole set of java libraries, into folder 'api':
Count the number of CPUs in your system
import java.io.*;
class Test {
static private boolean isWindows = System.getProperty("os.name").startsWith("Windows");
static private int n_CPUs = 0;
static public int getCPUCount() {
if (n_CPUs > 0) return n_CPUs;
if (isWindows) return 1; // no clue
// POSIX systems, attempt to count CPUs from /proc/stat
try {
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("cat /proc/stat");
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
n_CPUs = 0;
// valid cores will print as cpu0, cpu1. cpu2 ...
while ((line = br.readLine()) != null) {
if (0 == line.indexOf("cpu") && line.length() > 3
&& Character.isDigit(line.charAt(3))) {
n_CPUs++;
}
}
// fix possible errors
if (0 == n_CPUs) n_CPUs = 1;
return n_CPUs;
} catch (Exception e) {
//Utils.log(e.toString()); // just one line
return 1;
}
}
public static void main(String args[]) {
System.out.println("No of CPU = "+getCPUCount());
}
}
Useful Java Utilities and Frameworks
- Joda Time Java Date/Time replacement
- XStream “A simple library to serialize objects to XML and back again.”
- Rome Java tools for parsing, generating and publishing RSS and Atom feeds.
- Google Collections “a suite of new collections and collection-related goodness for Java 5.0, brought to you by Google. This library is a natural extension of the Java Collections Framework you already know and love. “
- Google Guice (DI Framework) “Put simply, Guice alleviates the need for factories and the use of new in your Java code. Think of Guice’s @Inject as the new new. You will still need to write factories in some cases, but your code will not depend directly on them. Your code will be easier to change, unit test and reuse in other contexts.”
- EasyMock “EasyMock provides Mock Objects for interfaces in JUnit tests by generating them on the fly using Java’s proxy mechanism.”
- Apache Commons Tons of useful utilities for Java that I can’t pick just one.
- GWT Java-Ajax web framework – very cool
- JFreeChart “JFreeChart is a free 100% Java chart library that makes it easy for developers to display professional quality charts in their applications.”
- Java Mozilla HTML Parser a wrapper around Mozilla’s HTML Parser.
- Lucene “High-performance, full-featured text search engine library written entirely in Java.”
- Squirrel SQL “Graphical Java program that will allow you to view the structure of a JDBC compliant database, browse the data in tables, issue SQL commands etc,”
- NIO.2 Ok, technically not an open source framework. This is the new version of NIO that will be included in Java 7. This is what we’ll be using in place of File and many of the other classes in the java.io package. Pretty cool.
Subscribe to:
Posts (Atom)