.java

What is a .java file?

Java Source File · Code and data · Sun Microsystems / Oracle · 1995

A .java file is Java source code, a widely used language that compiles to bytecode and runs on the Java Virtual Machine. It powers Android apps, enterprise back ends and large-scale systems.

Category
Code and data
Type
Plain text
Is a .java file safe to open? Caution. A .java file is program source. Compiling and running it executes its code; review untrusted files first.

What is a .java file used for?

Java source is compiled by javac into .class files of bytecode, which the JVM runs on any platform. This write-once, run-anywhere design made Java a mainstay of enterprise software.

Android apps were traditionally written in Java, and much server software still is. The files are plain text; IntelliJ IDEA, Eclipse and VS Code are common editors.

How to open a .java file

The .java format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list. For a step-by-step walkthrough, see how to open a .java file.

Windows

  • IntelliJ IDEA
  • Eclipse
  • VS Code

macOS

  • IntelliJ IDEA
  • Eclipse
  • VS Code

Linux

  • IntelliJ IDEA
  • Eclipse
  • VS Code

How to convert a .java file

You can convert a .java file to class (bytecode), jar using a conversion tool or the export menu of an app that opens it.

.java file signature (magic bytes)

Programs recognise a .java file by the bytes at the start of the file, not by its name. These are the signatures for Java.

Hex signatureOffsetNote
(no fixed signature)0plain text; no fixed magic bytes

See the full magic-numbers reference for every format.

Frequently asked questions

What is a .java file?

A .java file is Java source code, a widely used language that compiles to bytecode and runs on the Java Virtual Machine. It powers Android apps, enterprise back ends and large-scale systems.

How do I compile and run a .java file?

Compile with javac File.java to make File.class, then run java File. Modern JDKs can also run a single file directly with java File.java.

What is the difference between .java and .class?

A .java file is human-readable source. javac compiles it into a .class file of bytecode that the Java Virtual Machine executes.

How do I open a .java file?

Any text editor works. IntelliJ IDEA, Eclipse or VS Code add highlighting, building and debugging.

Related formats

Sources

Details on this page were checked against authoritative references: