.class File Extension
.class file contains, how to inspect Java bytecode safely, how Poly supports it, and when to keep source or use a JAR instead. File extension details for .class
Storage Only| File type | Java Virtual Machine class file |
|---|---|
| MIME type | |
| Encoding | Binary JVM class-file format, big-endian |
| Operating systems | Windows, macOS, Linux |
| Opens with | javap, IntelliJ IDEA, Java Virtual Machine |
| Poly support | Yes. Poly stores, syncs, shares, and versions class files. |
| Indexed by Poly | Partial. Poly indexes the filename and basic file properties, not bytecode or symbols. |
| Preview in Poly | No. Class files do not have an in-app content preview. |
| Poly agent | No. The Poly agent cannot read compiled class contents. |
What kind of file is a .class?
A .class file contains compiled instructions for the Java Virtual Machine (JVM). It is binary bytecode, not the human-readable Java source found in a .java file. A class file usually represents one class or interface and can include a constant pool, fields, methods, and attributes.1
The usual de facto media types are application/java and application/java-vm. Neither is registered by IANA for class files.2 The first four bytes should be CA FE BA BE, followed by minor and major class-file version numbers. That signature is useful, but it is not conclusive by itself because a big-endian universal Mach-O binary can begin with the same four bytes. A parser must validate the remaining structure.1
.class does not compile or convert it. Use javac to compile source and inspect the resulting file's contents before trusting its suffix.How do I open a .class on my computer?
Install a Java Development Kit on Windows, macOS, or Linux, then inspect the file without executing it:
- Run
javap -verbose Example.classto see version information, the constant pool, fields, methods, and attributes. Add-cfor bytecode instructions.3 - Open it in IntelliJ IDEA for a decompiled, Java-like view.4
- Use a bytecode analysis tool when you need programmatic inspection or comparison.
Decompiler output is an approximation. Compilation removes comments and formatting, while obfuscation or generated code can make recovered source hard to read. To run a class, use the java launcher with the correct class name and class path. Double-clicking an arbitrary file is neither a reliable nor a safe test.
Poly support for .class
Poly stores, syncs, shares, versions, and finds .class files by name and basic properties. It does not currently extract class names, methods, annotations, constant-pool strings, or bytecode. There is no content preview, and the Poly agent cannot interpret the compiled contents.
Keep the corresponding .java source or a trusted javap report beside the binary when you want full-text search or agent-readable context.
History of .class
The extension arrived with the original Java platform and its portable JVM format. Instead of compiling separately for every processor, Java compilers emit a hardware-independent class representation for a compatible JVM to load.1
The version fields evolved with the platform:
| Java release | Class-file major version |
|---|---|
| Java 8 | 52 |
| Java 17 | 61 |
| Java 25 | 69 |
An older JVM generally cannot load a class produced for a newer release. The compiler's --release option can target an older supported Java API and class-file version when compatibility matters.5
Working with .class and alternatives
Choose the artifact that matches your goal:
- Keep
.javasource, build files, and dependency information for maintenance and review. - Package multiple class files and resources in a JAR for distribution. A JAR uses
application/java-archiveand is ZIP-based, so changing the suffix does not create one. - Use
javapor a decompiler for inspection, not as a lossless route back to the original source. - Recompile with an appropriate target release when an older JVM reports an unsupported class-file version.
Footnotes
- Oracle. The Java Virtual Machine Specification: The class File Format. ↩ ↩2 ↩3
- Internet Assigned Numbers Authority. Media Types Registry. The registry includes
application/java-archive, but not a class-file media type. ↩ - Oracle. The javap Command. ↩
- JetBrains. Bytecode Decompiler. ↩
- Oracle. The javac Command. ↩
- Oracle. Verification of class Files. ↩