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 #1 : Program Analysis

Identify a user error that could occur in this program


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

int s = (Integer)ui;


Possible Answers:

The user input could not be an integer

The parseInt statement is incorrect

There is nothing wrong

The user can never do anything wrong

Correct answer:

The user input could not be an integer


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