Skip to content

Java bytecode file (.class)

.class file signature | application/java-vm

Java bytecode class files are compiled program files defined by Sun Microsystems and maintained by Oracle as part of the Java platform. They are used to distribute Java application and library code for execution by the Java Virtual Machine on desktop, server, embedded, and mobile systems. Because they contain executable instructions, class files should be treated as code from untrusted sources and inspected before loading into tools or runtime environments.

Safe

Magic Bytes

Offset 0
CA FE BA BE

Sources: Apache Tika, Wikipedia, Gary Kessler

Extension

.class

MIME Type

application/java-vm

Byte Offset

0

Risk Level

Safe

Validation Code

How to validate .class files in Python

Python
def is_class(file_path: str) -> bool:
    """Check if file is a valid CLASS by magic bytes."""
    signature = bytes([0xCA, 0xFE, 0xBA, 0xBE])
    with open(file_path, "rb") as f:
        return f.read(4) == signature

How to validate .class files in Node.js

Node.js
function isCLASS(buffer: Buffer): boolean {
  const signature = Buffer.from([0xCA, 0xFE, 0xBA, 0xBE]);
  return buffer.subarray(0, 4).equals(signature);
}

How to validate .class files in Go

Go
func IsCLASS(data []byte) bool {
    signature := []byte{0xCA, 0xFE, 0xBA, 0xBE}
    if len(data) < 4 {
        return false
    }
    return bytes.Equal(data[:4], signature)
}

API Endpoint

GET /api/v1/class
curl https://filesignature.org/api/v1/class

See the full API documentation for all endpoints and parameters.

Related Formats

Frequently Asked Questions

What is a .class file?

A .class file is a Java bytecode file file. Java bytecode class files are compiled program files defined by Sun Microsystems and maintained by Oracle as part of the Java platform. They are used to distribute Java application and library code for execution by the Java Virtual Machine on desktop, server, embedded, and mobile systems. Because they contain executable instructions, class files should be treated as code from untrusted sources and inspected before loading into tools or runtime environments.

What are the magic bytes for .class files?

The magic bytes for Java bytecode file files are CA FE BA BE at byte offset 0. These bytes uniquely identify the file format regardless of the file extension.

How do I validate a .class file?

To validate a .class file, read the first bytes of the file and compare them against the known magic bytes (CA FE BA BE) at offset 0. This is more reliable than checking the file extension alone, as extensions can be renamed.

What is the MIME type for .class files?

The primary MIME type for .class files is application/java-vm.

Is it safe to open .class files?

Java bytecode file (.class) files are generally safe to open. They are classified as low risk because they primarily contain data rather than executable code. However, always ensure files come from a trusted source.