What is the extension of Java code files for creating a new file in Java?

202    Asked by ChloeBurgess in Java , Asked on Dec 20, 2023

I was developing a Java program and during the process, I needed to create a new file containing a class. What is the extension of Java code files for creating a new file and how does this extension help me in the compilation and organization of my Java project? 

Answered by Chloe Burgess

In the context ofJava programming language, the class files which contain the source code are traditionally saved with the extension of “java”. For instance, suppose you have created a class named “My class” then it would be saved as “My class. Java”.

Here is the example given

// MyClass.java
Public class MyClass {
    Public static void main(String[] args) {
        System. out.println(“Hello, Java!”);
    }
}

When you compile the Java code, the Java compiler “ javac” recognizes the file by using the “java” extension as source files and then compiles it into the bytecodes. Then after the bytecodes as executed by the Java virtual machine (JVM).



Your Answer

Interviews

Parent Categories