What Is a JAVA File?

Use any text editor to edit a Java source code file

What to Know

  • A JAVA file is a Java source code file.
  • Open one with any text editor.
  • Convert to Kotlin with IntelliJ IDEA.

This article explains what a JAVA file is and how to open one on your computer, or convert one to a KT, JAVA, or EXE file.

What Is a JAVA File?

A file with the JAVA file extension (or less commonly, the .JAV suffix) is a Java source code file written in the Java programming language. It's a plain text file format that's completely readable in a text editor and essential to the entire process of building Java applications.

A JAVA file is used by a Java compiler to create a Java class files (.CLASS), which is usually a binary file and not human-readable. If the source code file contains multiple classes, each one is compiled into its own CLASS file.

It's the CLASS file that's then turned into an executable app with the JAR file extension. These Java archives make it easier to store and distribute CLASS files and other application resources like images and sounds.

JAVA files that open with Notepad in Windows

How to Open JAVA Files

The text within a JAVA file can be read by any text editor, like Notepad in Windows, TextEdit in macOS, etc. However, chances are slim that a compatible program on your computer is already set up to open a JAVA file when it's double-clicked.

Instead, open one of those programs first, and then use its File or Import menu to browse for the file.

Still, JAVA files are only actually useful when they're compiled into a bytecode CLASS file, which a Java SDK can do. Data within the CLASS file is used by Oracle's Java Virtual Machine (JVM) once the JAR file has been created.

Use the following command in Command Prompt to open the JAVA file in the Java SDK, which will make a CLASS file. Be sure to, of course, change the text within the quotes to be the path to your file.

javac "path-to-file.java"

This command only works if you have the javac.exe file on your computer, which comes with the Java SDK installation. This file is stored in the bin folder of the C:\Program Files\jdk(version)\ directory. The easiest way to use the command is to set this location as a PATH environment variable.

To edit JAVA files, use a program intended for application development, like Eclipse or JCreator LE. Text editors like NetBeans and those in the link above can also be useful.

How to Convert a JAVA File

Since a JAVA file contains the source code for a Java application, it's easily transferable to other applications or programming languages that can understand the code or translate it to something else.

For example, you can convert a JAVA file to a Kotlin file using IntelliJ IDEA. Either use the Code menu item to find the Convert Java file to Kotlin File option or access the Help > Find Action menu and then type the action you want to complete, like convert java file. It should save the JAVA file to a KT file.

Use the javac command mentioned above to convert JAVA to CLASS. If you can't seem to invoke the tool from Command Prompt, one CMD trick you can do is access the EXE file's location as described above, and then drag and drop the javac.exe file directly into Command Prompt to complete the command.

Once the file is in the CLASS format, you can essentially convert JAVA to JAR using the jar command, as described in this Java tutorial from Oracle. It will make a JAR file using the CLASS file.

JSmooth and JexePack are two tools that can be used to make the JAVA file an EXE file so that the app can run like a normal Windows executable file.

Still Can't Open It?

The first thing you should do if the file isn't opening or converting with the tools described above is double-check the extension. It's possible you're not actually dealing with a JAVA file, but instead a file that ​uses a similarly spelled file extension.

For example, the AVA suffix looks a bit like JAVA, but it's used for eBook with Persian AvaaPlayer. JA files are similar; these are Jet Archive files that store compressed game files. Another is JavaScript Proxy Autoconfig files (.JVS) that web browsers use to configure a proxy server.

FAQ
  • How do I read a file in Java?

    You can read a file, such as a CSV file, in Java using the BufferedReader class method. Visit Oracle's documentation to learn more about the BufferedReader class and other methods for reading files, such as FileReader, InputStreamReader, and Files.newBufferedReader( ).

  • How do I create a file in Java?

    There are several options for creating files in Java. One method is the createNewFile( ) method to open a blank file. Dive deeper with Oracle's tutorial about creating files in Java.

Was this page helpful?