AP Computer Science A : Identifying Boundary Cases

Study concepts, example questions & explanations for AP Computer Science A

varsity tutors app store varsity tutors android store

Example Questions

Example Question #2 : Testing

Identify a user error that could occur in this program

 

UserInput ui = new UserInput(); // input from the user

int s = (Integer)ui;

System.out.println(s);

Possible Answers:

The user input could not be an integer

The parseInt statement is incorrect

The user can never do anything wrong

There is nothing wrong

Correct answer:

The user input could not be an integer

Explanation:

The user could input a string and the cast to an (Integer) would cause a runtime exception. If there is a runtime exception, the program will stop and open up vulnerabilities to hackers. Once a hacker knows how to halt a program, they can start input bad data to see a database schema to collect data. One way to fix this would be using a utility method such as parseInt(ui). 

Learning Tools by Varsity Tutors