A program affects people beyond its job: it can help or harm, in ways its writers intended or never expected. Responsible programming in AP® Computer Science A means testing that code works, respecting who owns code, protecting the personal data a program collects and checking that its data treats every group fairly.
Quick check
Can a program with no bugs still harm people?Show answerHide answer
Yes. Code can do exactly what it was written to do and still treat some users unfairly, because of its design or the data it uses.
Is code you find on a public website free to copy into your own program?Show answerHide answer
Not automatically. Being public is not the same as having permission; you need a license that allows reuse.
Know these already? Jump to the practice questions
What you'll be able to do
- Explain intended and unintended effects of a program.
- Determine how integer overflow makes code unreliable.
- Identify what a license lets you do with code.
- Choose designs that collect less personal data.
- Explain how biased data reaches a program's results.
Key terms
Intellectual property
Creations of the mind, such as code, that the law lets their owner control.
- In plain English
- Code belongs to its copyright owner, not its finder.
- Don't write
- "Public code belongs to everyone."
License
Permission from a copyright owner stating how others may use, change and share the work.
- In plain English
- The rules for reusing someone's code.
- Don't write
- "A license means you can do anything."
Personal data
Information that identifies a person or can be linked to one, such as an address or location history.
- In plain English
- Data about a real person.
- Don't write
- "Only names count as personal data."
Bias (in data)
A skew in a data set, often from missing or under-represented groups, that makes results less accurate or fair for them.
- In plain English
- Lopsided data gives lopsided results.
- Don't write
- "If the code is correct, the results can't be biased."
What effects can a program have that nobody intended?
Every program has intended effects, the goals it was written for, and can have unintended effects that nobody planned. Either kind can be beneficial or harmful. A navigation app that sends every driver the fastest way saves time, yet it can also send heavy traffic down quiet side streets.
Unintended effects often come from a design assumption, such as a name rule that allows only the letters A to Z (Worked example 2). So before you write a class, ask who will use it, who it affects, and what inputs real people will give it.
Key idea
A program can be free of bugs and still cause harm through its design or its data.
Check yourself
Show answerHide answer
Intended: users find videos they enjoy. Unintended: some users spend far more time on the app than they meant to.
Why does reliability matter?
A reliable program gives correct results for every valid input. Bugs that slip past testing can cost money, data or safety: on 4 June 1996, the first Ariane 5 rocket began to break up about 40 seconds into its flight sequence, roughly half a minute after lift-off. Its guidance software, largely reused from Ariane 4, converted a 64-bit floating-point value into a 16-bit signed integer; the value was much larger than expected, the conversion failed and both inertial reference systems failed with it.
Java has a related trap: a value too big for its type. An int holds values up to Integer.MAX_VALUE, 2,147,483,647, and int arithmetic that goes past it doesn't stop or warn: the result wraps around. So test the largest values a program must handle, not only typical ones.
Check yourself
Show answerHide answer
No. The result wraps around silently, so the program carries on with a wrong value.
Who owns code, and when may you reuse it?
In the United States, code is protected by copyright as soon as it is written down, with no registration needed. Others may reuse it only with the owner's permission, usually given by a license.
| License | What it lets you do | What it requires |
|---|---|---|
| MIT (permissive) | use, copy, change and sell the code | include the copyright notice and license text |
| GNU GPL (copyleft) | use, change and share the code | if you distribute a program built on it, share its source under the same license |
| none | nothing without permission | ask the owner, or use licensed code instead |
MIT and GPL are both open-source licenses: anyone may use, study, change and share the source code. Whatever the license, credit the source in a comment.
Check yourself
Show answerHide answer
No. The MIT license requires only that the copyright notice and license text go with the copies.
How should a program treat personal data?
Stored data has real benefits, such as remembering a user's settings, but once it leaks it can't be recalled. Three habits reduce the risk.
- Collect only what the program needs. Data you never collect can't be stolen.
- Tell users and ask them. Say what is collected and why, and get consent.
- Protect what you keep. Limit who can read it, and never store passwords as plain text: guidance from the U.S. National Institute of Standards and Technology (NIST) says stored passwords must be salted and hashed, scrambled one way so the stored value is not the password.
Check yourself
Show answerHide answer
The phone number and home address, and the name too unless the app displays it. Only data the program uses should be collected.
How does bias in a data set reach the results?
A program that learns rules or sets values from data inherits that data's gaps. If one group is missing or rare in the data, averages, thresholds and predictions fit the well-represented group, even when every line of code is correct.
A single overall figure can hide a poor result for a small group. So check results group by group, and gather data that represents everyone the program will serve.
Check yourself
Show answerHide answer
Children were missing from the test data, so nothing showed how the program performs for them.
Worked example 1: Trace an overflow bug
Question: A fitness app stores time in milliseconds. What is printed when this code segment runs?
int days = 25;
int ms = days * 24 * 60 * 60 * 1000;
System.out.println(ms);
What tells you the method
A product of int values that grows large: trace each multiplication against Integer.MAX_VALUE.
Step 1: Multiply left to right.
After multiplying by True value Fits in an int?24 600 yes 60 36,000 yes 60 2,160,000 yes 1000 2,160,000,000 no Why*works left to right, and every operand is anint, so each result is anint.Step 2: Wrap the value that doesn't fit.
An
inthas 2³² possible values, so the stored result is 2,160,000,000 − 4,294,967,296 = −2,134,967,296.WhyJava keeps only the low 32 bits of an int result, which wraps the value round to a negative number.
Check it
With days = 24 the product is 2,073,600,000, which fits, so a test using only a few days would never find this bug.
Answer
-2134967296
Worked example 2: Find who a validation rule shuts out
Question: A sign-up form uses this method. How many of the names "Maya", "O'Neil", "Ana Lucia" and "Zoë" does it accept?
public static boolean validName(String name)
{
String letters = "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int i = 0; i < name.length(); i++)
{
String c = name.substring(i, i + 1);
if (letters.indexOf(c) == -1)
{
return false;
}
}
return true;
}
What tells you the method
A loop that returns false at the first character not found in letters: trace each name until a character fails.
Step 1: Trace each name.
Name First character not in lettersReturns "Maya" none true"O'Neil" "'" at index 1 false"Ana Lucia" " " at index 3 false"Zoë" "ë" at index 2 falseWhyindexOfreturns −1 for any character that isn't one of the 52 letters A to Z and a to z.Step 2: Count the accepted names.
Only "Maya" returns
true.WhyThe rule assumes names use only unaccented letters, so real names with an apostrophe, space or accent are turned away.
Check it
The method does exactly what its rule says, so the fix is a wider rule, tested on names from a wide range of users.
Answer
1
Your turn
Question: A step-counting app sets its default daily goal to the average of five test users, all members of a running club. What is printed?
int total = 14000 + 16000 + 12000 + 15000 + 13000;
int goal = total / 5;
System.out.println("Daily goal: " + goal);
Step 1: Add the step counts.
totalis 70000.Step 2: Your go: work out
goal, write the printed line, and say whether the goal suits most users.
Show the full solutionHide the solution
Step 2. 70000 / 5 is 14000 exactly, so the line printed is "Daily goal: 14000". The code is correct, but all five test users are runners, so the goal is set by a group that walks far more than typical users. The data is biased, and so is the result.
Answer: Daily goal: 14000
Traps
Trap
If a program has no bugs, it can't harm anyone.
It seems right because most reported harm comes from errors. But correct code can still shut people out through a narrow rule, or give unfair results from biased data.
The step-goal code computes its average with no error. Can its goal still be unfair?
Yes. The data came from one unrepresentative group, so a correct calculation gives a skewed goal.
Trap
Code posted publicly is free for anyone to copy.
It seems right because anyone can read it. But copyright applies as soon as code is written, so without a license you have no permission to reuse it.
Code on a public page has no license. Does being public give you permission to reuse it?
No. You need the owner's permission, so ask, or use code with a license that allows reuse.
What's examined
On the AP® Computer Science A exam, the impact of programs is part of Unit 3 (Class Creation). It can appear in multiple-choice questions: a scenario or code segment, then a question about its effects, reliability, licensing, privacy or bias. The four free-response questions ask you to write code rather than discuss these issues.
Practice questions
- Recall You find useful code on a public website with no license. What should you do?
- A) Copy it, because it is public
- B) Copy it, but rename the variables
- C) Ask the author's permission, or use licensed code
- D) Copy it, as long as your app is free
Show answer
Answer: C. Without a license you have no permission to reuse the code.
Why the others are wrong:
- A treats public as free to use; copyright still applies.
- B assumes cosmetic changes make the code yours; it is still copied.
- D assumes giving an app away removes the need for permission; it doesn't.
- Apply You use MIT-licensed code in an app you sell. Which does the license require?
- A) Release your app's source code
- B) Include the original copyright notice and license text
- C) Pay the author a fee for each copy sold
- D) Nothing, because MIT-licensed code has no conditions
Show answer
Answer: B. The MIT license's one condition is that its notice and license text go with copies.
Why the others are wrong:
- A describes a copyleft license such as the GPL, not the MIT license.
- C invents a fee; the MIT license lets you sell copies without paying the author.
- D overlooks the notice condition.
- Exam-style The method should return the average of
countratings totalingtotal, soaverageRating(9, 2)should return 4.5. Give the number of the line that stops it working.
1: public static double averageRating(int total, int count)
2: {
3: double avg = total / count;
4: return avg;
5: }
Show answer
Answer: Line 3.
Marking points:
total / countdivides twointvalues, so 9 / 2 gives 4, andavgbecomes 4.0, not 4.5.- Changing line 3 to
double avg = (double) total / count;makes it return 4.5.
- Apply A club's app collects each member's name, email, home address, birth date and phone number, but only ever emails reminders. Which change best protects members' privacy?
- A) Collect only the email address and name
- B) Collect everything, but add a privacy notice
- C) Collect everything, but store it in another file
- D) Collect everything, but delete phone numbers yearly
Show answer
Answer: A. Data the app never collects can't be leaked or misused.
Why the others are wrong:
- B tells members about the risk but leaves all of it in place.
- C moves the data without reducing it or protecting it.
- D still collects data the app never uses and keeps it for up to a year.
The table is for questions 5 and 6. A hypothetical voice app was tested on 200 recordings.
| Speakers | Recordings | Understood |
|---|---|---|
| Adults | 180 | 171 |
| Children | 20 | 12 |
- Apply What percent of the children's recordings did the app understand?
Show answer
Answer: 60 percent.
Marking points:
- 12 / 20 = 0.6, which is 60 percent.
- For adults it is 171 / 180 = 95 percent, and overall 183 / 200 = 91.5 percent, which hides the gap.
- Exam-style Which action best reduces bias against children in the app's results?
- A) Report only the overall accuracy, 91.5 percent
- B) Remove the children's recordings
- C) Rerun the same tests on the same recordings
- D) Add more children's recordings and report accuracy per group
Show answer
Answer: D. More data from the under-represented group, checked group by group, shows and reduces the gap.
Why the others are wrong:
- A hides the 60 percent result for children inside a high overall figure.
- B hides the problem instead of fixing it.
- C repeats the same lopsided data, so the results don't change.
Key points
Recall, then reveal
Say the main points from memory first, then check them.
Show key pointsHide key points
- One program can have intended and unintended effects, and each can help or harm.
- Correct code can still cause harm through a narrow design rule or biased data.
- Test the largest and smallest valid inputs: Java's int arithmetic wraps silently past
Integer.MAX_VALUE. - Code is copyrighted when written; reuse needs a license, such as permissive MIT or copyleft GPL, and credit.
- Collect only the personal data a program needs, say why, and protect it.
- Check results for each group, not just overall, and gather data that represents everyone.