answersLogoWhite

0

It is not compulsory that the java file name and name of the public class should be same. if u will give java file name and public class name different then u have to compile and run the program with another names.

for example:

u have named class sample i.e. (public class sample) and main function is also defined in this class.

and u have saved the file as abc.java

then u will first comple the file as:

javac abc.java

now run the file (type java class name(in which main function is defined) i.e.

java sample

try it.

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

Is it possible to have more than one public class in the same file?

No. There can be multiple java classes in the same .java file, but the name of the file must match the name of the public class in the file.


Java program file must match the name of class with extension true or false?

The name of the .java file should exactly match with the name of the public class in the file. Ex: public class Test { ..... } this file should be saved as Test.java


The name of a Java program file must match the name of the class with the extension java?

not exactly..... only If your class is public then the java program name should be the public class name with extension Sample.java >> public class Sample { public static void main(String[] args) { ..... } } NonPublicClass.java class SomeOtherName { ......... }


Can a .java file contain more than one java classes?

Yes, it can. However, there can only be one public class per .java file, as public classes must have the same name as the source file.


What does the java program error expected public class MathPow.java mean?

The error "expected public class MathPow.java" typically indicates that the Java compiler is expecting a public class declaration in the file named MathPow.java. In Java, the filename must match the public class name defined within the file. If the class is not declared as public or if the filename does not correspond to the class name, the compiler will throw this error. To fix it, ensure that the class is declared as public and that the filename matches the class name exactly.


Is it possible to have file name as java eg javajava?

Yes you can name a file (class if you use eclipse) java or even have java in the name.


What are the rules in naming a source file in JAVA program?

The basic rule is that the file name should match the name of the topmost public class in the .java file. The names are usually camel case and can contains alphabets and numbers. It should begin only with an alphabet.


How many classes should be included in each java file?

You can only have one non-inner public classes per java file and that class name must match the filename. The java file can also have any number of inner classes and anonymous classes.


What are the sun coding standards for naming a class in java?

Some naming conventions/standards for Java classes are: a. A java file must be saved with the name of the public class in the file b. A Java file can have only one public class but can have any number of other classes c. The class names must be in Camel Case. Ex: AnExampleClassForWikiAnswers is how class names should be coded d. Even methods must be in camel case with one difference that the first alphabet must be in lower case. Ex: getSampleDataFrWiki()


Why you same name in class and file in java?

For run the program


The name of a Java program file must match the name of the class with the extension java A True B False?

True


What is the command to compile a java program named Greetingsjava?

The command to compile a Java program is "javac", followed by the class name (file name).