Skip to content
DSA getting started 7 min read

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

LanguageInstallRun a file
C++GCC (g++) or Clangg++ main.cpp -o main && ./main
JavaJDK 17+ (Temurin/OpenJDK)java Main.java (single-file mode)
JavaScriptNode.js 20+node main.js
PythonCPython 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;
}

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";
}

Going deeper: For large inputs, the default readers can be slow. In C++ add ios::sync_with_stdio(false); cin.tie(nullptr);. In Java prefer BufferedReader over Scanner. In Python, reading all of stdin once (as above) beats calling input() in a loop. These don’t change Big-O, but they can be the difference between passing and a time-limit error.

  • 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.

Last updated June 25, 2026
Was this helpful?