Stack Array implementation of Java This is my array implementation on stack in Java. It involves push, pop, get and growth when limit of array size is reached.

I am a self-taught programmer starting to learn data structures and algorithms.

I am looking for


any recommendation on conventions
an honest opinion on how bad this piece of code if this is an interview.
anything wrong and room for improvement.


I wrote this code myself, not looking at any other similar questions on Code Review.

public class stackAlist{
    int[] data;
    int size;
    static int growthmultipler = 1;

    public stackAlist(){
        data = new int[2*growthmultipler];
        size = 0;
    }

    public void push(int value){
        if(this.size == 0){
            this.data[0] = value;
            this.size += 1;
            this.growthmultipler = 1;
            }
        else if(this.size == 2*growthmultipler){
            growthmultipler += 1;
            stackAlist newlist = new stackAlist();
            newlist.data = new int[2*growthmultipler];
            System.arraycopy(this.data, 0, newlist.data, 0, this.size);
            this.data = newlist.data;
            this.data[size] = value;
            this.size += 1;
        }
        else{
        this.data[size] = value;
        this.size += 1;
        }
    }

    public void pop(){
        this.data[size-1] = 0;
        this.size = this.size-1;
    }

    public void get(){
        int i;
        for(i =0; i &lt; this.size; i++){
            System.out.println(data[i]);
        }
    }

    public static void main(String[] args){
        stackAlist a = new stackAlist();
        a.push(1);
        a.push(2);
        a.get();
        a.pop();
        a.get();
        a.push(3);
        a.push(4);
        a.get();
    }
}
First of all, you are using a static variable (growthmultipler) inside the instance of a class. This is fatal if you have more than one instance of this class. Because you always use 2*growthmultipler, you don't need it. Use +=2  instead.

You don't need to prealloc data in the constructor. It will be done if it's needed.

You don't need to handle "size == 0" separately. You only have to handle "size >= length".

You don't have to create a new class if you want to grow data.

In pop() you should test to not get negative (and throw an exception). And normally a pop function returns the value.

In summary it might look like this:

public class stackAlist{
    int[] data;
    int size;

    public stackAlist(){
        size = 0;
        data = new int[size];
    }

    public void push(int value){
        if(size&gt;=data.length) {
            int [] ndata = new int[data.length+2];
            System.arraycopy(data, 0, ndata, 0, size);
            data = ndata;
        }
        data[size] = value;
        size += 1;
    }

    public int pop() {
        int ret=0;
        if(size&gt;0) {
            size -= 1;
            ret = data[size];
            data[size] = 0;
        }
        return ret;
    }
    .....