Am sorry I may not be of full help now cause am also new i JAVA but let me give you the algorithm that came to my mind on this
import java.util.Stack; read all the mathimatical equation into a String variable say

convert the String to array of character using
mathStString.toCharArray(); assign this to a variable say

create a Stack object eg
Stack stack= new Stack(); use a for loop to scan through mathCharArray
if there is an occurrence of character

, it will be pushed onto the stack object using
stack.push(new Character('(')); if the char is ')' checkk
if the stack is not empty,
throw an Exception that there is a closing parenthesis with out a corresponding opening parenthesis.
otherwise
remove the character from the stack
after completing the loop cheek if stack is empty
if stack is not empty
throw an exception that there is an unclosed parenthesis