Java hashcode without using the Object#hashCode method For an assignment I have to make a HashTable using double hashing, but for the hashing part I am not allowed to use Object#hashCode(), so I have to write my own. 

So far I have the following code and I am looking for feedback if I am on the right track or if I should go for a different approach (see hash and hash2 methods).

public class DoubleHashing&lt;Key, Value&gt; {

private int N;
private int M;
private Key[] keys;
private Value[] vals;

public DoubleHashing(final int capacity) {
    M = capacity;
    keys = (Key[]) new Object[M];
    vals = (Value[]) new Object[M];
}

public int hash(final Key key) {
    int hashKey = 0;
    if (key instanceof String) {
        final String k = (String) key;
        for (int i = 0; i &lt; k.length(); i++) {
            int charCode = k.charAt(i);
            hashKey = ((hashKey * 27) + charCode) % M;
        }
    }
    return hashKey;
}

public int hash2(final Key key) {
    int hashKey = 0;
    if (key instanceof String) {
        final String k = (String) key;
        for (int i = 0; i &lt; k.length(); i++) {
            int charCode = k.charAt(i);
            hashKey = 5 - ((hashKey * 27) + charCode) % 5;
        }
    }
    return hashKey;
}

public void put(final Key key, final Value val) {
    if (N == M) {
        System.err.println("Table is full");
        return;
    }
    int i;
    for (i = hash(key); keys[i] != null; i = (i + 1) % M)
        if (keys[i].equals(key)) { vals[i] = val; return; }
    keys[i] = key;
    vals[i] = val;
    N++;
}

public Value get(final Key key) {
    for (int i = hash(key); keys[i] != null; i = (i + 1) % M)
        if (keys[i].equals(key))
            return vals[i];
    return null;
}

public int size() {
    return N;
}
}
Use meaningful names for your fields:

private int N;
private int M;


What do those fields hold? What is the purpose of them?
Ask yourself those questions and use names that represent the meaning of your field:

private int size;
private int capacity;


Don't cast where you don't need to:

keys = (Key[]) new Object[M];
vals = (Value[]) new Object[M];


This makes no sense; why do you cast a generic Object[] array to a Key[]/Value[] array?
Simply create them without casting:

keys = new Key[M];
vals = new Value[M];


Your hashing methods don't return hashes

Your code is entirely broken in that regard. They only work for Strings and you use them for getting your index. This is not how hashing works!
I don't know if this is a restriction of your assignment, but no matter how large the capacity of your table is, your hashing method should always return the same value in order to be comparable to other objects.