public
:everyone can use it.private
:only the code in the class can use it.
protected
: only inheriting code can use it.
static
- meaning we can use the methods without making an object.
extends
: you get everything.implements
: you promise everything.
/uk/ac/leeds/mass/
/uk/ac/leeds/mass/aevans/
/uk/ac/leeds/mass/
uk.ac.leeds.mass
package uk.ac.leeds.mass;
public class MyClass {
}
package uk.ac.leeds.mass;
import java.awt.Point;
class MyClass {
public static void main (String args[]) {
Point p = new Point();
}
}
import java.awt.*;
java.awt.Point a = new java.awt.Point();
But this only really worthwhile if two imported packages have the same class name in them.
import java.awt.*;
Doesn't import:
import java.awt.events.*;
java.lang
invisibly available (e.g. java.lang.System
).
[Fullscreen] |
If we want to compile a class in presidents we have to run the compiler from the src directory, with the command...
or
to compile everything.
If we use a
|
javac -classpath path;path; File.java
(in UNIX: path:path)
javac unpackaged/lazyCode/*.java
java -classpath unpackaged/lazyCode/;. MyClass
java unpackaged/lazyCode/MyClass
The JVM will just assume you're trying to run from a package.
java.util.Vector
java.util.ArrayList
java.util.Stack
java.util.Hashtable
java.util.Properties
java.util.Bitset
java.util.Enumeration (interface)
java.lang.Object
.
Vector()
Vector(int size)
Vector(int size, int increment)
addElement(Object ob)
insertElementAt(Object ob, int index)
// Add elements in at the top or index position.
elementAt(int index)
// Gets an element at the index position.
contains(Object ob)
// Checks the object is in the Vector.
import java.util.*;
public class GIS {
Vector store = new Vector(5,5);
public GIS () {
Point pOne = new Point();
store.add(p, 10);
// some time later
for (int i = 0; i < store.size(); i++) {
Point p1 = (Point) store.elementAt(10);
}
}
}