AP Computer Science A
Java for AP Computer Science A, in the browser
Students can write and run Java below with no sign-up, no install and no ads, on a Chromebook or any school computer. This page covers what a class can do with it, how it fits the course framework that took effect in fall 2025, and what it can't do.
By the OnlineCompiler.io team. Updated .
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
int[][] scores = {
{82, 91, 77},
{65, 70, 88},
{95, 89, 92}
};
System.out.println("Rows averaging above 80: " + rowsAbove(scores, 80));
}
/** Returns the indexes of the rows of grid whose average is greater than limit. */
public static ArrayList<Integer> rowsAbove(int[][] grid, double limit) {
ArrayList<Integer> result = new ArrayList<Integer>();
for (int r = 0; r < grid.length; r++) {
int sum = 0;
for (int c = 0; c < grid[r].length; c++) {
sum += grid[r][c];
}
if ((double) sum / grid[r].length > limit) {
result.add(r);
}
}
return result;
}
}The example is a 2D array traversal that builds an ArrayList, the shape of free-response
questions 3 and 4. Press Run, then change the limit or the scores. Starting the JVM and compiling take most
of the time: a short program like this takes about 2.25 seconds to run on our servers.
What a class can do with it
- Run Java with no sign-up. Students open this page or the Java online compiler and start typing. The code compiles and
runs on our servers, so there is no JDK to install and it works the same on Chromebooks and school
laptops. If your web filter blocks it, ask IT to allow
onlinecompiler.ioandapi.onlinecompiler.io. - Turn work in with a link. Share gives a link to the code that anyone can open and run, with no account. Students paste it into Google Classroom, Canvas, Schoology or an email. Links made without an account last 90 days; Save keeps code in an account for as long as the student wants it.
- Put the editor in your own pages. Sign in, create a widget key on the Widgets page of your dashboard, and the embed builder turns your starter code into an iframe. In Google Sites, use Insert, Embed, Embed code and paste it; in an LMS, paste it into any page that accepts an iframe. The embeddable code editor page shows the script version, with hidden starter code and answer checking.
- Check methods against expected output. The online compiler with test cases runs a
program against up to 8 inputs at once and marks each one passed or failed. For
free-response practice, have
maincall the method with the question's examples and print the results, then compare them with the expected values. - Grade labs automatically. If you run your own course site or grading scripts, the autograder API runs each submission against your tests, including hidden ones, and returns a score per test.
What the course expects
The Course and Exam Description that took effect in fall 2025 groups the course into four units. Their weightings in the multiple-choice section, from the course page:
| Unit | Multiple-choice weighting |
|---|---|
| Unit 1: Using Objects and Methods | 15–25% |
| Unit 2: Selection and Iteration | 25–35% |
| Unit 3: Class Creation | 10–18% |
| Unit 4: Data Collections | 30–40% |
The exam has 42 multiple-choice questions (55%, 90 minutes) and 4 free-response questions (45%, 90 minutes). Each free-response question has a fixed shape:
| Question | Points | What students write |
|---|---|---|
| 1. Methods and Control Structures | 7 | Two methods, or a constructor and a method, using loops, conditionals and String methods |
| 2. Class Design | 7 | A whole class: header, instance variables, constructor and a method |
| 3. Data Analysis with ArrayList | 5 | One method that analyzes or changes data in an ArrayList |
| 4. 2D Array | 6 | One method that traverses and works with a 2D array |
Changes that matter when students write and run code:
- Text files are in. Topic 4.6 reads data from a text file with
FileandScanner, usingthrows IOExceptionand imports fromjava.io. The Java Quick Reference now listsScanner(File f),nextInt,nextDouble,nextBoolean,nextLine,next,hasNext,closeandString.split. - Keyboard input is out. The framework says accepting input from the keyboard is outside
the course and exam.
Scanner(System.in)still works here, reading the Input tab, if your labs use it. - Inheritance is out. Designing and implementing inheritance relationships are outside the course and exam. Java still allows them here, for students who go further.
- Labs are required. The course must include at least 20 hours of hands-on, structured labs. Short labs fit in this editor; anything with a GUI or several files needs a full IDE.
The editor has no way to attach a file, so to practice topic 4.6, let the program write its data file first and then read it back. This runs as it is:
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
// The editor can't attach a file, so the program writes one first.
PrintWriter out = new PrintWriter("roster.txt");
out.println("Ada 91");
out.println("Grace 78");
out.close();
Scanner input = new Scanner(new File("roster.txt"));
while (input.hasNext()) {
String name = input.next();
int score = input.nextInt();
System.out.println(name + ": " + score);
}
input.close();
}
}The file only lasts for that run. If you build exercises on the API instead, send the data file with the
request's files field (up to 8 files and
1 MB) and the program reads it from its working folder.
Java details worth knowing
- One file, with
mainfirst. Everything goes in one file, and the class withmainhas to come first. Other classes, such as the one students design for free-response question 2, go after it and can bepublic:
public class Main {
public static void main(String[] args) {
Book b = new Book("Dune", 412);
System.out.println(b.getTitle() + " has " + b.getPages() + " pages");
}
}
public class Book {
private String title;
private int pages;
public Book(String title, int pages) {
this.title = title;
this.pages = pages;
}
public String getTitle() { return title; }
public int getPages() { return pages; }
}- Standard library only. Every class on the Java Quick Reference is there; jar files and Maven or Gradle aren't, and programs have no internet access.
- No graphics. There is no screen, so Swing and JavaFX stop with a
HeadlessException. - Input is typed before the program runs. Put every value a program reads in the Input tab before pressing Run. The program can't wait for more while it runs.
- Limits per run: 30 seconds, 512 MB of memory and no internet access. Output appears when the program ends.
- No classes or tracking. There are no rosters, assignments or teacher view of students' work, and no grade passback to an LMS. Students turn work in by sharing a link.
- Your own embeds share your account's limits. On the free plan, a widget key takes 30 runs a minute and 8 waiting at once across all your students. A class pressing Run in the same moment can go over that; those students see a message and can press Run again a few seconds later. The pricing page lists the paid plans' limits.
- A Google Sites embed needs its own key. Google Sites shows embedded code in a frame of its own rather than on your site's address, so a key restricted to your school's domain is refused there. Make a separate key with no domain for Google Sites. You can turn any key off on the Widgets page.
What is stored
Students don't sign up and the editor asks for no names. Each run is kept in execution history with its code, input, output and the IP address it came from, as for every run on this site, and a shared link keeps its code and input until it expires. The site uses Google Analytics to count visits. The privacy policy and security page say exactly what is kept and for how long. If your school or district reviews online tools before students use them, send it those two pages.
AP is a trademark registered by the College Board, which is not affiliated with, and does not endorse, OnlineCompiler.io.
Frequently asked questions
Is it free for schools?
Yes. Students run Java on this page and on the Java online compiler with no sign-up and no ads. If you embed the editor in your own pages, your free account covers 100,000 runs a month across all of them, with no credit card.
Do students need to sign up?
No. They only need an account to keep code with Save. Share works without one and gives a link that lasts 90 days.
Does it work on Chromebooks?
Yes. The code compiles and runs on our servers, so there is no JDK to install and any up-to-date browser will do. If your district filters websites, ask IT to allow onlinecompiler.io and api.onlinecompiler.io.
Which version of Java is it?
OpenJDK 25. The AP course uses a small part of Java, and all of it, including every class on the Java Quick Reference, works the same in this version.
Can students use Scanner with System.in?
Yes. Type the input in the Input tab before pressing Run, and Scanner reads it as if typed at the keyboard. The course framework leaves keyboard input out of the course and exam, but it is still handy in labs.
Why does my program say it can't find a main method?
The class with main has to come first in the file. Put any other classes after it; they can be public.
Can students build GUIs or add libraries?
No. There is no screen, so Swing and JavaFX stop with a HeadlessException, and only the Java standard library is available: there is no way to add jar files.
Is this site part of the College Board or AP?
No. AP is a trademark registered by the College Board, which is not affiliated with, and does not endorse, OnlineCompiler.io.