Download the following class into your java program directory: CharStack.class. Then copy/paste the following program and compile and run it:

//the program demonstrates a stack used to store characters
public class ShowStack {
	public static void main(String [] args) {
	    // creating a new stack
		CharStack cs = new CharStack();
		// a variable to store stack characters
		char c;

		cs.push('!');
		cs.push('?');
		c = cs.pop();
		System.out.println("c = " + c);
		cs.push('y');
		cs.push('e');
		cs.push('h');
		boolean b;
		b = cs.isEmpty();
		System.out.println("b = " + b);

		c = cs.pop();
		System.out.print(c);
		c = cs.pop();
		System.out.print(c);
		c = cs.pop();
		System.out.print(c);
		c = cs.pop();
		System.out.print(c);
		//boolean b;
		b = cs.isEmpty();
		System.out.println("b = " + b);
		cs.pop();

		System.out.println("DONE!"); // new line
	}
}


This is an example from CSci 2101 course.