.java File Extension
.java file contains, how to open and compile Java source code, how Poly supports it, and how it differs from class and JAR files. File extension details for .java
Full Support| File type | Java source code |
|---|---|
| MIME type | |
| Encoding | Unicode plain text, commonly UTF-8 |
| Operating systems | Windows, macOS, Linux |
| Opens with | IntelliJ IDEA, Visual Studio Code, Eclipse IDE, Any text editor |
| Poly support | Yes. Poly recognizes .java as readable Java source code. |
| Indexed by Poly | Yes. Poly indexes readable source for exact and semantic search. |
| Preview in Poly | Yes. Java source opens in Poly's code editor with syntax highlighting. |
| Poly agent | Yes. The Poly agent can read and reason about the source text. |
What kind of file is a .java?
A .java file contains source code written in the Java programming language. It is editable text, not the bytecode executed by a Java Virtual Machine. A source file is a compilation unit and can contain package and import declarations plus top-level class or interface declarations.1
The Java language processes source as Unicode, but the file's byte encoding is a separate choice. Current JDKs use UTF-8 as their default charset, and javac -encoding can select another supported encoding.2 A Java source file has no fixed magic bytes, so tools identify it from its suffix, project context, and syntax.
There is no registered Java-source media type in IANA's registry. text/x-java-source is a common unregistered label, while Poly treats readable .java files as text/plain.3
.java does not translate it into Java. Renaming a compiled file does not recover its original source either.How do I open a .java on my computer?
Any text editor can open .java files on Windows, macOS, or Linux. IntelliJ IDEA, Eclipse, and Visual Studio Code with Java extensions add completion, navigation, formatting, testing, and debugging.
Install a JDK when you need to compile or run the code. For a simple class named Hello, use:
javac Hello.java
java Hello
javac reads Java source and normally produces one or more .class bytecode files. Source filenames must use the .java suffix, and a public top-level type is normally kept in a matching file such as Hello.java.4 Opening source as text does not execute it. Building or running an unfamiliar project can execute application code, build plugins, or annotation processors, so inspect its instructions and dependencies first.
Poly support for .java
Poly opens .java files in a code-friendly viewer with Java syntax highlighting, word wrap, and in-file search. It indexes readable source for exact and semantic search, so you can find a class by name or search for code by its purpose. The Poly agent can summarize a class, explain a method, and help trace likely behavior.
Poly does not compile or execute source, resolve dependencies, or reproduce an IDE's full project model. Keep related source, tests, build files such as pom.xml or build.gradle, and documentation together when project-wide context matters.
History of .java
Sun Microsystems introduced Java publicly in 1995. James Gosling and Henry McGilton's May 1996 white paper described the language and its goals, including portability across different hardware and operating systems.5 The .java suffix became the standard filename convention for its human-readable source, paired with .class for compiled JVM bytecode.
The suffix does not identify a Java language release. A project's compiler options and build configuration determine whether newer syntax or APIs are accepted.
Working with .java and related files
Java projects use several related file types:
| Extension | Typical role |
|---|---|
.java | Human-readable Java source |
.class | Compiled JVM bytecode |
.jar | ZIP-based archive of classes, resources, and metadata |
.jmod | JDK module packaging format |
Keep .java source and build configuration in version control. Treat .class files and most JARs as generated or dependency artifacts unless a project explicitly vendors them. A decompiler can produce Java-like text from bytecode, but comments, formatting, some names, and exact source constructs may be lost. Changing .class or .jar to .java does not perform that conversion.
Footnotes
- Oracle. Java Language Specification: Packages and Modules. Defines ordinary Java compilation units and their declarations. ↩
- Oracle. Supported Encodings. Explains the default source charset and the
javac -encodingoption. ↩ - Internet Assigned Numbers Authority. Media Types Registry. The registry contains no Java-source media type. ↩
- Oracle. The javac Command. Documents
.javasource filenames, compilation, output class files, and source-tree layout. ↩ - Gosling, James, and Henry McGilton. The Java Language Environment. Sun Microsystems, May 1996. ↩