Basic

Compile

To compile a bunch of java files not organized in a package, for each file:

javac -classpath . filename.java

Launching Java Applications

To launch the main static function of a {Class} inside a {package}, using the jar libraries (lib1.jar, lib2.jar) and a native library in the same directory.

java -Djava.library.path="." -cp lib1.jar: lib2.jar: {package}.{Class}

  • java.library.path: Path to native libraries
  • cp: Class path

The separators for the -cp syntax are different between Windows and Linux.

  • Windows: ;
  • Linux: :

Heap Size

To set heap size:

  • -Xms<size>m specifies the initial Java heap size in MB
  • -Xmx<size>m specifies the maximum Java heap size in MB

Libraries Installation

  • jar libraries: jre/lib
  • native libraries: jre/lib/i386

In case of an error trying to load a native library, usually the problem lies with:

  • The shared library is not in the java library path.
  • The shared library is depending on another shared library not available in the system: (@see: ldd mylib.so)

JVM client & server mode

What's the difference between the -client and -server systems?

These two systems are different binaries. They are essentially two different compilers (JITs)interfacing to the same runtime system. The client system is optimal for applications which need fast startup times or small footprints, the server system is optimal for applications where the overall performance is most important. In general the client system is better suited for interactive applications such as GUIs. Some of the other differences include the compilation policy,heap defaults, and inlining policy.

Java HotSpot VM FAQ

List & Array

  • List to array:

List<Dummy> dummyList = new ArrayList<Dummy>();
Dummy[] dummyArray = (Dummy[]) dummyList.toArray(new Dummy[dummyList.size()]);

  • Array copy:

Dummy[] dummy_copy = new Dummy[dummy.length];
System.arraycopy(dummy, 0, dummy_copy, 0, dummy_copy.length);

java/basic.txt · Last modified: 2010/08/16 by emilmont
CC Attribution-Noncommercial-Share Alike 3.0 Unported
Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0