Is Empty .java file name a valid source file name in Java?

Yes, Java allows to save our java file by .java only, we need to compile it by javac .java and run by java classname Let’s take a simple example:

  1. //save by .java only
  2. class A{
  3. public static void main(String args[]){
  4. System.out.println(“Hello java”);
  5. }
  6. }
  7. //compile by javac .java
  8. //run by     java A

compile it by javac .java

run it by java A