Is the .java file name empty?

I started learning Java a couple of days ago. And I have this burning question. Is empty .java filename a valid source file name?

 .java 
+7
java oop
source share
5 answers

Yes, save the java file in .java , then compile it javac .java and run java yourclassname

  class X { public static void main(String args[]) { System.out.println("Hello World"); } } 

for compilation - javac .java

to execute - java X

+4
source share

Yes, it works because the java compiler does not believe that it saves the file name or not, except that our class, which has public information, we can save any name or empty, but when we ever try to execute, we should use our class name because jvm creates the bytecode ourclassname.class , so we use

 java className 
+1
source share

Yes. You may have a .java file named nay. you must compile it using javac .java (it compiles successfully) and run it using java clasnname . (so you must specify the class name)

0
source share

Yes, but not often .

You cannot create classes in this public or private file, so any class that used any class defined here must be in the same package.

0
source share

at any time, you can have only one open class in a file, and if you use an open class, then this class name must be the name of the file.

0
source share

All Articles