Setting Up Java Locally
Why work locally
You can write contest code in an online editor, and for your first contest that is fine. But local setup pays off quickly: you can test against sample input without retyping it, run a program repeatedly with different inputs, and use a debugger. During a four-hour contest, saved minutes accumulate.
If you cannot install software on the computer you use — a school machine with locked-down permissions is common — the online option is a genuine fallback, not a compromise. Skip to the end of this lesson.
Installing a JDK
You need a Java Development Kit, version 17 or newer. Most online judges run a recent long-term-support release, and anything from 17 up behaves the same for contest purposes.
Install steps
- Download a JDK build. Eclipse Temurin and Oracle’s JDK both work; Temurin has no license prompts.
- Run the installer. On Windows, accept the option to add Java to
PATHif offered. - Open a new terminal and confirm the install:
javac --version
java --versionBoth commands should print a version number of 17 or higher. If javac is missing but java works, you installed a runtime (JRE) instead of a development kit (JDK).
Compiling and running
A contest submission is a single file. Keep the class name and the file name matching.
// File: Main.java
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine().trim());
System.out.println(n * 2);
}
}
Compile and run:
javac Main.java
java Main
Newer JDKs also let you skip the compile step for single-file programs, which is convenient while iterating:
java Main.java
Testing against sample input
This is the part that saves real time. Put the sample input in a file instead of typing it every run.
Save the problem’s sample input as in.txt, then redirect it into your program:
java Main < in.txt
To compare your output against the expected output, save that as expected.txt and diff them:
java Main < in.txt > out.txt
Compare-Object (Get-Content out.txt) (Get-Content expected.txt)No output from Compare-Object means the files match.
java Main < in.txt > out.txt
diff out.txt expected.txtNo output from diff means the files match.
A workflow that holds up under time pressure
- Keep one folder per contest, one subfolder per problem.
- In each problem folder:
Main.java,in.txt,expected.txt. - Name the class
Mainevery time. You never have to think about it, and it matches what most judges expect. - Before submitting, run the sample once more. It catches the case where you fixed one thing and broke another.
Using an IDE
An IDE is optional but helpful, mainly for the debugger and for catching typos as you write. IntelliJ IDEA Community Edition and VS Code with the Java extension pack are both free and both let you configure sample input redirection in the run settings.
If you already use Android Studio for FTC, you already have IntelliJ’s editor — the same shortcuts apply.
One IDE setting worth changing
Configure your run action to read standard input from a file. In IntelliJ this is Run → Edit Configurations → Modify options → Redirect input from. Point it at in.txt. Now a single keystroke compiles, runs, and feeds in the sample.
If you cannot install anything
Online judges and editors let you compile and run Java in a browser. Paste the sample input into the input pane and run. It is slower than a local setup and you lose the debugger, but every problem in this curriculum can be solved this way.
Verify your setup
Confirm the whole loop works before you need it under time pressure:
- Create a folder with
Main.javacontaining the program above. - Create
in.txtcontaining a single line with the number21. - Run the program with input redirected. Confirm it prints
42. - Change
in.txtto-5and run again without editing the Java file. Confirm it prints-10.
Step 4 is the point of the exercise — you changed the test case without touching code or retyping input.