Setting Up C++, Java, JavaScript & Python for DSA
Setting up your tooling means installing a compiler or runtime for your chosen language, picking an editor, and knowing how to read input and print output — the two things every DSA problem needs. This page gives you a working setup for C++, Java, JavaScript, and Python, plus a minimal “say hello and read a number” program in each so you can confirm everything runs.
You only need one language to follow this course — pick the one you think in and use the language switcher on every page. The setups below are independent; jump to yours.
Quick install per language
| Language | Install | Run a file |
|---|---|---|
| C++ | GCC (g++) or Clang | g++ main.cpp -o main && ./main |
| Java | JDK 17+ (Temurin/OpenJDK) | java Main.java (single-file mode) |
| JavaScript | Node.js 20+ | node main.js |
| Python | CPython 3.10+ | python3 main.py |
For beginners: If you don’t want to install anything yet, use an online judge (next section). You can return and install a local toolchain once you’re hooked.
Online judges (zero install)
Online judges compile and run your code on their servers and check it against hidden test cases — perfect for practice and interviews:
- LeetCode — interview-style problems, all four languages, great for this course.
- Codeforces — competitive contests; strong for complexity intuition.
- HackerRank / AtCoder — graded problem sets and beginner tracks.
Most also include a browser editor, so you can solve every exercise on this site without installing a thing.
Hello + read input, in every language
The one skill every judge requires: read input from stdin, compute, print to stdout. Here is the same program — read an integer n, then print a greeting and n * 2 — in all four languages. Use the switcher to see yours.
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n; // read one integer from stdin
cout << "Hello, DSA\n";
cout << n * 2 << "\n"; // print the result
return 0;
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(); // read one integer from stdin
System.out.println("Hello, DSA");
System.out.println(n * 2); // print the result
}
}
// Node.js: read all of stdin, then process.
const data = require('fs').readFileSync(0, 'utf8').trim().split(/\s+/);
const n = parseInt(data[0], 10); // first whitespace-separated token
console.log('Hello, DSA');
console.log(n * 2);
import sys
data = sys.stdin.read().split() # all whitespace-separated tokens
n = int(data[0])
print("Hello, DSA")
print(n * 2)
To test it, save the file and pipe input in:
echo "21" | ./main # C++
echo "21" | java Main.java
echo "21" | node main.js
echo "21" | python3 main.py
Each prints Hello, DSA then 42.
Reading multiple values
Most problems give you several numbers — often a count n followed by n values. The pattern is the same: read all the tokens, then index into them.
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
long long sum = 0;
for (int x : a) sum += x;
cout << sum << "\n";
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long sum = 0;
for (int i = 0; i < n; i++) sum += sc.nextInt();
System.out.println(sum);
}
}
const data = require('fs').readFileSync(0, 'utf8').trim().split(/\s+/);
const n = parseInt(data[0], 10);
let sum = 0;
for (let i = 1; i <= n; i++) sum += parseInt(data[i], 10);
console.log(sum);
import sys
data = sys.stdin.read().split()
n = int(data[0])
nums = list(map(int, data[1:1 + n]))
print(sum(nums))
Going deeper: For large inputs, the default readers can be slow. In C++ add
ios::sync_with_stdio(false); cin.tie(nullptr);. In Java preferBufferedReaderoverScanner. In Python, reading all of stdin once (as above) beats callinginput()in a loop. These don’t change Big-O, but they can be the difference between passing and a time-limit error.
Recommended setup per language
- C++ —
g++with-O2 -std=c++17, plus an editor with a debugger (VS Code + C/C++ extension). Fast and the default in competitive programming. - Java — a recent JDK and IntelliJ IDEA or VS Code. Verbose but extremely readable; the default language for this course’s examples.
- JavaScript — Node.js and VS Code. Great if you already do web work; watch out for floating-point integers beyond 2^53 (use
BigInt). - Python — CPython and VS Code or PyCharm. Shortest code, ideal for prototyping an idea before optimizing; slower constant factors.
Where to go next
With a working setup, you’re ready to actually solve problems. Learn the repeatable method on the problem-solving framework page, then revisit Big-O notation so you can reason about whether your solution is fast enough. When you’re ready to code data structures, start with arrays.