Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

2011/06/17

Order of ClassPath

You can define multiple ClassPath, like

CLASSPATH=$CLASSPATH:/usr/local/apache/lucene/lucene-core-2.0.0.jar:/usr/local/apache/lucene/src/:/usr/local/apache/lucene/src/lucene-classes.jar:.
export CLASSPATH


But the order of ClassPath is important. Basically it is first come first server, if Java Interpreter find the class in the first class path, then it will ignore the the one in the later class path. See the detail from Oracle java doc

The order in which you specify multiple class path entries is important. The Java interpreter will look for classes in the directories in the order they appear in the class path variable. In the example above, the Java interpreter will first look for a needed class in the directory C:\java\MyClasses. Only if it doesn't find a class with the proper name in that directory will the interpreter look in the C:\java\OtherClasses directory.

2009/05/27

initial array in java

1. static one:

int[] a;           // Declare a to be an array of ints
a = new int[100];  // Allocate an array of 100 ints
//or in a line
int [] a = new int[100];
//string type
String [] b = new String[100];

2. dynamic one:

Note: ‘Java does not offer arrays that can be extended at run time, for primitives or Objects, so it is common to use a Vector for a set of elements that needs to be able to grow.’ from javalobby

Vector v = new Vector();
int count = v.size();
String[] dynArray = new String[count];
v.copyInto(dynArray);