.JAVA file extension

To open .JAVA files on Windows, to view or edit: right-click the .java file → Open with → choose a code editor/IDE installed on your PC (or choose Notepad as a basic fallback).

To open a .java file, use a text/code editor (for viewing and editing) or an IDE. To run it, compile the source with a Java compiler such as javac, which turns ClassName.java into ClassName.class.

Last updated: June 11, 2026 · Reviewed by Julian Stricker

What “reviewed” means on this page
  • Format fit: whether the “what is this file?” description matches common real-world use of the extension, including category, typical MIME types, and aliases.
  • Opening paths: whether Windows / macOS / Linux steps read plausibly for current OS dialogs and default apps; we remove fantasy menus and unsafe shortcuts.
  • Security framing: whether risk notes match the extension class (for example executables vs plain data) and whether affiliate wording does not contradict the security section.
  • Sources and further reading: whether external links point to vendors, standards bodies, or other primary references where possible; we avoid inventing details we cannot ground.
  • Limits: this is clarity and safety-messaging QA, not a guarantee that every statement is exhaustive or that every binary you download is harmless.

Full methodology in the Imprint The Imprint also states where AI is used and what that does—and does not—replace.

Open on your device

Choose your operating system for a dedicated step-by-step opening guide.

How to open .JAVA files

Use these platform-specific instructions to open .JAVA files safely.

Windows

  1. To view or edit: right-click the .java file → Open with → choose a code editor/IDE installed on your PC (or choose Notepad as a basic fallback).
  2. To compile: install a Java Development Kit (JDK), open a terminal in the file’s folder, and run: javac ClassName.java.
  3. If you only need to read it, open it in any text editor (a .java file is plain text source code).
Full Windows guide

Mac

  1. To view or edit: control-click the .java file → Open With → choose a code editor/IDE (or TextEdit configured for plain text).
  2. To compile: install a JDK, open Terminal in the file’s folder, and run: javac ClassName.java.
  3. If the file opens with the wrong app, change the default by using Get Info → Open with → Change All.
Full Mac guide

Linux

  1. To view or edit: open the .java file in a text editor or IDE from your desktop environment’s “Open With” menu (it is typically recognized via the shared MIME database for patterns like *.java).
  2. To compile: install a JDK and run in a terminal: javac ClassName.java.
  3. If double-click opens the wrong program, change the default app for the detected MIME type in your file manager’s properties/settings.
Full Linux guide

iOS

  1. iOS can usually display .java as plain text in the Files app; if it doesn’t preview well, share it to a code/text editor app, or transfer it to a desktop to compile with javac.
Full iOS guide

Android

  1. Open the .java file in a text/code editor app to view or edit it; for compiling/running, transfer it to a desktop environment with a JDK and use javac.
Full Android guide

Security notes

  • .java files are source code (plain text), but they can still be risky if you compile and run code you do not trust—treat unknown .java files like untrusted programs.
  • Be cautious with build scripts, compiler options, or project setups that may execute additional tools during compilation/testing; review what will run before executing any commands.
  • If you receive a .java file over the web, servers may label it with a non-standard x- prefixed MIME type; treat it as text and avoid executing anything automatically.

Before you run downloaded code

These files usually need a runtime (Python, Node, Java, …). They are not classic “file viruses,” but untrusted code can still do serious harm if you execute it. Prefer official packages, verify publishers, and scan archives or sketchy downloads when you are unsure.

We may earn a commission when you use affiliate links. This supports our free file extension guides.

Can't open this file?

These are the most common causes and fixes when .JAVA files fail to open.

Common reasons

  • The .java file opens in the wrong application
  • javac fails: file name and public class name do not match
  • Command not found: javac
  • MIME type or file association issues on Linux

Fix steps

  1. Use “Open with” and choose your preferred code editor/IDE.
  2. Set it as the default app for .java files (Windows: Properties → Opens with; macOS: Get Info → Open with → Change All; Linux: file manager defaults for the MIME type).

What is a .JAVA file?

A .java file contains Java source code written according to the Java Language Specification (a compilation unit). By convention, a public class named ClassName is stored in a source file named ClassName.java, and tools like javac read these source files and compile them into .class files (bytecode).

Background

The .java extension is most commonly associated with Java source files used in application development. These files are plain text and typically include package declarations, imports, class/interface/enum definitions, and other Java language constructs.

In day-to-day use, developers open .java files in an IDE or code editor for editing, then compile them into .class files. Oracle’s javac documentation describes this workflow explicitly: it reads ClassName.java and produces ClassName.class.

On many Linux desktops, file type detection is commonly driven by the freedesktop.org shared MIME-info database, which maps filename patterns like *.java to MIME types used by the desktop environment to choose default applications.

Common MIME types: text/x-java

Further reading

Authoritative resources for more details on the .JAVA format.

Common .JAVA issues

The .java file opens in the wrong application

Because .java is plain text, the OS may associate it with a generic text app or an unrelated program.

  1. Use “Open with” and choose your preferred code editor/IDE.
  2. Set it as the default app for .java files (Windows: Properties → Opens with; macOS: Get Info → Open with → Change All; Linux: file manager defaults for the MIME type).

javac fails: file name and public class name do not match

Java conventions (and common compiler expectations) require the source file name to match the public class name (for example, public class Hello should be in Hello.java).

  1. Open the file and check the public class name.
  2. Rename the file to match (ClassName.java), or change the public class to match the file name, then re-run javac.

Command not found: javac

The Java compiler (javac) is provided by a JDK; it won’t be available if only a runtime is installed or if your PATH isn’t set.

  1. Install a Java Development Kit (JDK) for your platform.
  2. Verify javac is available in your terminal (and ensure your environment PATH includes the JDK’s bin directory), then compile again.

MIME type or file association issues on Linux

Linux desktop environments typically rely on the shared MIME-info database and local overrides; outdated or incorrect MIME info can lead to wrong associations.

  1. Check what your desktop thinks the file type is and adjust the default app for that MIME type.
  2. Update/refresh your desktop’s MIME database and file associations if they are outdated or misconfigured.

FAQ

Is a .java file the same as a .class file?

No. A .java file is human-readable Java source code. A .class file is the compiled bytecode output produced by the Java compiler (javac).

How do I run a .java file?

You generally compile it first with javac (for example, javac ClassName.java) to produce a .class file, then run the compiled class with the Java runtime (java).

What MIME type should a .java file use?

In practice you may see non-standard x- prefixed types used for Java source; IANA’s registry is the authoritative place to confirm what is officially registered.

Can I rename another file to .java to convert it into Java code?

No. Renaming only changes the extension; it does not convert content into valid Java source code.

Similar file extensions

Compare related formats in the same category to find the right tool faster.