Java FAQ
60 answers to the questions Java developers β and future Java developers β actually ask. Installation, updates, uninstall, the basics of the language, and the everyday how-to that trips everyone up on day one.
Getting started with Java
What is Java?
Java is a general-purpose, class-based, object-oriented programming language created by Sun Microsystems in 1995 and now maintained by Oracle. Code compiles to bytecode that runs on the Java Virtual Machine (JVM), so the same program runs unchanged on Windows, macOS, Linux, Android and most servers. It powers enterprise back-ends, Android apps, Minecraft, Big Data tools and much more.
Full answer βWhat is Java used for?
Java is used for enterprise web applications (Spring Boot, Jakarta EE), Android mobile apps, large-scale data systems (Hadoop, Kafka, Cassandra), financial and trading platforms, scientific computing, and desktop tools including the original Minecraft client. Its portability and mature ecosystem make it a default choice whenever a system must run reliably for years across different hardware.
Full answer βIs Java free?
Yes. OpenJDK is the free, open-source reference implementation of Java, distributed under the GPL v2 with Classpath Exception, covering both personal and commercial use. Builds like Eclipse Temurin, Amazon Corretto, Azul Zulu and Microsoft Build of OpenJDK are free and production-ready. Oracle's own "Oracle JDK" requires a paid subscription for commercial production use past a certain version window; most teams simply use one of the free builds.
Full answer βIs Java free for commercial use?
OpenJDK distributions (Temurin, Corretto, Zulu, Microsoft, Liberica) are free for commercial use with no license fee, even in production. Oracle JDK requires an Oracle Java SE Universal Subscription for production use. For zero-cost commercial use, install any non-Oracle OpenJDK build.
Full answer βWhen was Java created?
Java was initiated in 1991 by James Gosling and a team at Sun Microsystems (codename "Oak"), and released publicly as Java 1.0 in January 1996. Oracle acquired Sun, along with Java, in 2010.
Full answer βIs Java still used / still relevant in 2026?
Yes. Java consistently ranks in the top 4 most-used languages (TIOBE, Stack Overflow, GitHub) and is the backbone of millions of enterprise systems, Android apps and data platforms. Recent versions (17, 21, 25 LTS) added records, pattern matching, virtual threads and sealed classes, keeping the language modern.
Full answer βInstall Java on Windows
How do I install Java on Windows?
Download an OpenJDK installer (Eclipse Temurin or Microsoft Build of OpenJDK are recommended), run the .msi, and tick the option "Set JAVA_HOME variable". Open a new Command Prompt and run java -version. If it prints a version number, you are done. For a runtime-only install (e.g. to play Minecraft), a JRE build is enough; for development, install a full JDK.
How do I install Java on Windows 11?
Windows 11 installs Java exactly like Windows 10: download a Temurin or Microsoft OpenJDK .msi, run it as administrator, keep "Add to PATH" and "Set JAVA_HOME" checked, then verify with java -version in a new PowerShell window. You can also install via winget install Microsoft.OpenJDK.21.
Where do I download Java?
For a free OpenJDK build: adoptium.net (Temurin), learn.microsoft.com/java/openjdk, aws.amazon.com/corretto, or azul.com/downloads. Oracle's own download page is oracle.com/java/technologies/downloads but requires a subscription for commercial production use past short windows.
Full answer βHow do I install Java 17?
Pick a Java 17 LTS build from Adoptium (Temurin 17), Microsoft (winget install Microsoft.OpenJDK.17), or Amazon Corretto 17, and run the installer. On macOS, brew install openjdk@17; on Ubuntu, sudo apt install openjdk-17-jdk. Check with java -version. It should print 17.x.
How do I install Java for Minecraft?
Modern Minecraft Java Edition ships with its own JRE, so you usually do not need to install Java separately. For older versions or mods that require system Java, install a Java 17 or 21 runtime from Adoptium Temurin (JRE build is fine) and restart the launcher. Minecraft 1.17+ requires at least Java 16; 1.21+ requires Java 21.
Full answer βInstall Java on Mac
How do I install Java on Mac?
The fastest path is Homebrew: brew install openjdk (latest) or brew install openjdk@21 for a specific LTS. Follow the brew hint to symlink the JDK into /Library/Java/JavaVirtualMachines so macOS detects it. Alternatively, download an Adoptium Temurin .pkg installer and run it.
How do I download Java on Mac?
Visit adoptium.net, choose the macOS .pkg matching your chip (Apple Silicon aarch64 or Intel x64), and double-click to install. Verify in Terminal with java -version. Apple Silicon Macs should pick the aarch64 build for best performance.
How do I install Java 17 on Mac?
Run brew install openjdk@17, then follow the brew output to symlink it: sudo ln -sfn $(brew --prefix)/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk. Switch to it anytime with export JAVA_HOME=$(/usr/libexec/java_home -v 17).
Install Java on Linux
How do I install Java on Linux?
Use your distribution's package manager. Debian/Ubuntu: sudo apt install default-jdk. Fedora/RHEL: sudo dnf install java-latest-openjdk-devel. Arch: sudo pacman -S jdk-openjdk. Then verify with java -version.
How do I install Java on Ubuntu?
Run sudo apt update && sudo apt install openjdk-21-jdk (or openjdk-17-jdk for LTS 17). Confirm with java -version. Ubuntu 24.04 and later ship OpenJDK 21 as default.
How do I install Java in Linux via apt or yum?
apt: sudo apt install openjdk-21-jdk (or any version available in your repo). yum/dnf: sudo dnf install java-21-openjdk-devel. For a specific vendor build, add their repo first, for example Adoptium's: wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo apt-key add -, then sudo apt install temurin-21-jdk.
Why does java -version say "command not found" on Linux?
The JDK is not installed or not on the $PATH. Install it with your package manager (see above), or if already installed manually, add export PATH=/path/to/jdk/bin:$PATH to your ~/.bashrc or ~/.zshrc and reload the shell.
Check Java version & update
How do I check my Java version?
Open a terminal and run java -version (note: a single dash). It prints something like openjdk version "21.0.2" 2024-01-16. For the compiler version, run javac -version.
How do I check Java version in cmd?
Open Command Prompt (Win+R, type cmd) and type java -version. If nothing prints, Java is not on your PATH. Reinstall it with the "Add to PATH" option checked, or add %JAVA_HOME%\bin to your system Path manually.
How do I check Java version on Linux?
Run java -version in any terminal. To see every installed JDK, run update-alternatives --display java (Debian/Ubuntu) or archlinux-java status (Arch). Installs are typically found under /usr/lib/jvm/.
What version of Java do I have?
Run java -version in a terminal. Output starting with 1.8.x means Java 8; 11.x, 17.x, 21.x or 25.x means that major version. If you see "not recognized", Java is not installed or not on your PATH.
What is the latest version of Java?
As of 2026, the latest Long-Term Support release is Java 25 (LTS), released September 2025. A new major version ships every six months; the current non-LTS release is Java 26 (spring 2026). Most production teams stick to LTS releases: 8, 11, 17, 21, 25.
Full answer βHow do I update Java?
On Windows, re-run the installer from your vendor (Adoptium, Oracle, Microsoft), which upgrades in place. macOS: brew upgrade openjdk@21. Linux: sudo apt upgrade openjdk-21-jdk or sudo dnf update java-21-openjdk. For a major-version jump, install the new JDK side by side and switch via JAVA_HOME.
How do I update Java on Mac?
With Homebrew: brew upgrade openjdk. For a specific LTS: brew upgrade openjdk@21. If you installed via a .pkg, download the newer .pkg from adoptium.net and run it; it will replace the old install.
How do I update Java on Windows 11?
Re-run the installer from your vendor (Adoptium, Microsoft), or use winget: winget upgrade Microsoft.OpenJDK.21. Close all Java apps first so files are not locked. Verify with java -version in a new terminal.
Switch or change Java version
How do I change Java version?
Install the versions you need side by side, then point JAVA_HOME at the one you want. Windows: set JAVA_HOME=C:\Program Files\Eclipse Adoptium\jdk-21 and put %JAVA_HOME%\bin first on PATH. macOS/Linux: export JAVA_HOME=$(/usr/libexec/java_home -v 21) (Mac) or sudo update-alternatives --config java (Linux).
How do I switch Java version on Mac?
macOS ships /usr/libexec/java_home, which locates any installed JDK. Running export JAVA_HOME=$(/usr/libexec/java_home -v 17) switches the current shell to Java 17; add it to ~/.zshrc to persist. Tools like jenv and sdkman automate the switch per directory.
How do I change Java version in IntelliJ IDEA?
Two settings matter: File > Project Structure > Project sets the SDK for the whole project, and File > Project Structure > Modules > Dependencies can override per module. For Maven/Gradle, the build file's <source>/<target> or languageVersion ultimately wins, so change it there and reimport.
Uninstall Java
How do I uninstall Java?
Windows: Settings > Apps > Installed apps, search "Java" or your JDK name (Temurin, Oracle, OpenJDK), click Uninstall. Mac: brew uninstall openjdk@21 or delete the .jdk folder under /Library/Java/JavaVirtualMachines/. Linux: sudo apt remove openjdk-* or sudo dnf remove java-*-openjdk*.
How do I uninstall Java on Mac?
For Homebrew installs: brew uninstall openjdk@21. For .pkg installs: sudo rm -rf /Library/Java/JavaVirtualMachines/<jdk-name>.jdk, then delete the preference pane if present: sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane and sudo rm -rf ~/Library/Application\ Support/Oracle/Java.
How do I uninstall Java on Windows?
Go to Settings > Apps > Installed apps, find each Java/JDK entry, click the three-dot menu and choose Uninstall. Repeat for every version; Windows keeps each one independent. Reboot after, then check with java -version in a new Command Prompt: it should say "not recognized".
How do I check if Java is installed?
Run java -version in a terminal. If it prints a version string, Java is installed and on your PATH. If it says "command not found" or "not recognized", Java is either not installed or not on the PATH. Check C:\Program Files\Java (Windows), /Library/Java/JavaVirtualMachines/ (Mac) or /usr/lib/jvm/ (Linux) to be sure.
Security & licensing
Is Java safe?
Yes. Modern Java (11, 17, 21, 25) is a sandboxed, memory-safe, actively patched platform used in banks, space agencies and most of the Fortune 500. The old security fears stem from the now-defunct Java Browser Plug-in, which was deprecated in Java 9 and removed in Java 11. Keep your JDK up to date and you are fine.
Full answer βDo I need Java?
Only if a specific application asks for it. Minecraft Java Edition, many enterprise desktop tools (Eclipse, IntelliJ, DBeaver), Android development, and anything server-side in Spring/Tomcat all require a JDK or JRE. If nothing you use asks for Java, you can safely uninstall it.
Full answer βWhat is the difference between JDK, JRE and OpenJDK?
The JRE (Java Runtime Environment) is what you need to run Java programs. The JDK (Java Development Kit) includes the JRE plus the compiler (javac), debugger and other dev tools, needed to build Java apps. OpenJDK is the free, open-source reference implementation that both Oracle JDK and most other vendor builds (Temurin, Corretto, Zulu) are based on.
Why does Java keep asking me to update?
Older Oracle JRE installs on Windows/Mac shipped the Java Auto-Updater, which pings Oracle monthly for a patched build. Modern OpenJDK distributions do not do this. If yours nags you and you do not need it, uninstall it or switch to a quieter build like Temurin. Otherwise, just apply the update: patches fix real security issues.
Full answer βJava basics: language concepts
What is a class in Java?
A class is a blueprint for creating objects: it declares the fields (data) and methods (behaviour) that every object of that type will have. Instantiate it with new ClassName(). Classes are the basic unit of code organisation in Java; almost everything lives inside one.
What is a method in Java?
A method is a named block of code that performs a task, optionally taking parameters and returning a value. Methods belong to classes; they are how you expose behaviour. Example: public int add(int a, int b) { return a + b; }.
What is a constructor in Java?
A constructor is a special method that runs when you new an object, initialising its fields. It has the same name as the class and no return type: public Person(String name) { this.name = name; }. Java generates a no-arg default constructor for you if you do not declare any.
What is an object in Java?
An object is a concrete instance of a class: a chunk of memory holding the fields declared by that class, with access to its methods. You create one with new: Person p = new Person("Ada");. Every object in Java ultimately extends java.lang.Object.
What is an interface in Java?
An interface is a contract: a named set of method signatures (and, since Java 8, default and static methods) that implementing classes must fulfil. Interfaces let unrelated classes share a common API and enable polymorphism without single inheritance. Example: interface Drawable { void draw(); }.
What is an instance in Java?
"Instance" is another word for object: a concrete realisation of a class in memory. "An instance of ArrayList" means a specific ArrayList you created with new ArrayList<>(). "Instance field" and "instance method" mean non-static; they belong to one object, not to the class.
What does static mean in Java?
static marks a field or method as belonging to the class itself, not to any one instance. You call Math.max(a, b) without creating a Math object because max is static. Static fields are shared by every instance of the class.
What is polymorphism in Java?
Polymorphism lets you use one reference type to work with many concrete types. For example, a variable typed List<String> can hold an ArrayList or a LinkedList, and calling list.add(x) dispatches to the right implementation at runtime. It is the mechanism behind interfaces and subclass overriding.
What is encapsulation in Java?
Encapsulation is hiding an object's internal state behind a controlled interface, typically by making fields private and exposing public getter/setter methods or, better, behaviour-focused methods. It lets you change the internal implementation later without breaking callers.
What is Spring Boot in Java?
Spring Boot is an opinionated framework built on top of Spring that starts a production-ready Java web application in minutes, with embedded Tomcat, sensible defaults and auto-configured beans. You write a single main method, annotate your classes (@RestController, @Service, @Entity) and Spring wires the rest.
Java keywords
What are keywords in Java?
Keywords are reserved words with a built-in meaning in the language: you cannot use them as identifiers. Examples: class, public, static, void, if, for, return, new. A few are contextual keywords only reserved in specific positions (yield, record, sealed, permits).
How many keywords are in Java?
Java has 51 reserved keywords plus a few contextual keywords added in recent versions. Two of those 51 (goto and const) are reserved but unused: they exist so the compiler can give a clearer error if you type them. Literals true, false and null are reserved values but not keywords in the strict sense.
Which of these are Java keywords: class, main, int, String?
class and int are Java keywords. main and String are not; main is just a conventional method name and String is the class java.lang.String. You could rename them (though nobody should).
Everyday how-to
How do I compare strings in Java?
Use a.equals(b) for content equality, or a.equalsIgnoreCase(b) to ignore case. Never use == to compare strings: it compares references, not characters, and breaks silently when strings come from different sources. For ordering, use a.compareTo(b).
How do I convert an int to a String in Java?
Three good options: String.valueOf(n), Integer.toString(n), or concatenation "" + n. All are fine; String.valueOf() is the most idiomatic and also works for other primitives.
How do I convert a String to an int in Java?
Use Integer.parseInt(s) for a primitive int, or Integer.valueOf(s) for a boxed Integer. Both throw NumberFormatException if the string is not a valid number, so wrap the call in a try/catch or validate the input first.
How do I print in Java?
System.out.println(x) prints x followed by a newline. System.out.print(x) omits the newline. System.out.printf("%s: %d%n", name, count) uses format specifiers.
How do I print an array in Java?
Use Arrays.toString(arr) from java.util.Arrays for a flat array, or Arrays.deepToString(arr) for a nested or 2D array. Plain System.out.println(arr) only prints the array's internal identifier (e.g. [I@1540e19d), which is almost never what you want.
How do I declare and initialize an array in Java?
Two forms: int[] a = new int[5]; creates an array of 5 zeroes, and int[] a = {1, 2, 3}; creates and fills it in one line. For objects: String[] names = new String[]{"Ada", "Grace"};.
How do I initialize an ArrayList in Java?
Empty: List<String> list = new ArrayList<>();. With values: List<String> list = new ArrayList<>(List.of("a", "b", "c"));. If you never need to modify it, use List.of(...) directly, which is immutable and cheaper.
How do I use Scanner in Java?
Import java.util.Scanner, create a scanner on System.in, and call one of the next* methods: Scanner sc = new Scanner(System.in); String name = sc.nextLine(); int age = sc.nextInt();. Call sc.close() when done.
How do I round a number in Java?
Math.round(x) returns the nearest long (half-up). For a specific number of decimals, use Math.round(x * 100) / 100.0 or, better, BigDecimal: new BigDecimal(x).setScale(2, RoundingMode.HALF_UP).
How do I reverse a String in Java?
new StringBuilder(s).reverse().toString() is the one-liner. It correctly handles surrogate pairs, unlike a manual char-by-char loop.