Java class name and file name are different

Java class name and file name are different

Can we run a Java program having class name and file name different?

View Answers

November 30, 2010 at 12:53 PM

Hi Friend,

No, you can't. It is necessary to save the java file with its class name otherwise it will give error.

Thanks


November 30, 2010 at 2:13 PM

File name : Sample_File.java

class Sample { public static void main(String args[]) { System.out.println("This is a program with class name and file name are different"); } }

when I run this program as javac Sample_File.java java Sample

I am getting the output without any error.


July 21, 2012 at 4:15 PM

no. its possible , we can run a program,Assume that my class name is A and file name is Afile.java. While running a program , 1st type in command prompt(cmd) as javac Afile.java To run the progran java A surely it will run.

July 26, 2012 at 9:19 AM

From Compiler point of view it is only the class name that matters rather than host specific source file name.

Normally, java compiler creates the .class file of any java file with its class name and .class extension. i.e., If we have a java source file with name 'Sample123.java' and the class name in that file is 'Sample' then the compiler would create a class file with name 'Sample.class'.

Java Specification:

NormalClassDeclaration: ClassModifiersopt class Identifier TypeParametersopt Superopt Interfacesopt ClassBody

The Identifier in a class declaration specifies the name of the class.









Related Tutorials/Questions & Answers:
Java class name and file name are different
Java class name and file name are different  Can we run a Java program having class name and file name different?   Hi Friend, No, you can't. It is necessary to save the java file with its class name otherwise
why java file save as its class name
why java file save as its class name  hi,this is subbareddy vajrala.my doubt is why java files save as its class names
Advertisements
class name
class name  what is the class name of circle.java   how do i complie my jdk file, what happen s if i put in the correct commands and it still does not complie, what do i do next
class name
class name  how to create a class named box thaT INCLUDES integer data fields for length,width,and height, include three contructors that require one,two,three arguments
How to read text file to two different name array
How to read text file to two different name array   I have those numbers:12,4,9,5 numbers:19,12,1,1 how to put it in two different name array in text file to java
How to read text file to two different name array
How to read text file to two different name array   I have those numbers:12,4,9,5 numbers:19,12,1,1 how to put it in two different name array in text file to java
Java Get File Name
Java Get File Name       In this section, you will study how to obtain the name of file..." to the constructor of class File. The method getName() returns the name
how to use StringTokenizer to retrieve the class name, attributes name and methods name from the Java Source Code
how to use StringTokenizer to retrieve the class name, attributes name and methods name from the Java Source Code  hi, I have done a program whereby it can read a Java file and then tokenize them into tokens. However, I am facing
I want to know the given class name exists in which jar file?
I want to know the given class name exists in which jar file?   I want to know the given class name exists in which jar file? C:\Program Files\IBM... the name of the jar file where 'com.rational.ft.util.debug' class exists
Java file get name
Java file get name In this section, you will learn how to get the name... class, you can get the name of any file. Output:ADS_TO_REPLACE_2... an object of File class and specified a file in the constructor. Then we have
Name
all the name of that character E.g User give character "B". The program shows all the human names which starts from B.   Java show all names... the user and show all the names that starts with that character. class
Java example to get Object class name at runtime
Java example to get Object class name at runtime       java get Object class name In java there is a way that makes us enabled to get the object class name at runtime. It can
Stoting file name in Map
Stoting file name in Map  how to store id and file name in map
Constructing a File Name path in Java
Constructing a File Name path    ... is helpful for mapping local  file name with the actual path of the file using... file name, using the static constant File.separator
Get Class Name
Get Class Name       In the example given below we will learn how to get name of the particular class with package name. getName() method returns fully qualified name
ModuleNotFoundError: No module named 'file-or-name'
ModuleNotFoundError: No module named 'file-or-name'  Hi, My Python... 'file-or-name' How to remove the ModuleNotFoundError: No module named 'file-or-name' error? Thanks   Hi, In your python
Get computer name in java
Get computer name in java       We can get the computer name by the java code program. For getting computer name we have used java.net.InetAddress class. We will use static
Constructing a File Name path
Constructing a File Name path   ... construct a file name path. By using the constructing filename path it is possible to set dynamic path, which is helpful for mapping local  file name
Java program to get class name without package
Java program to get class name without package ... example which describes you that how you can get the class name without package. For this purpose we have to fetch first the full class name with package
Name me Hibernate 5 H2 Dialect class
Name me Hibernate 5 H2 Dialect class  Hi, What is the name of Hibernate 5 H2 Dialect class file? Thanks   HI, Class name is: org.hibernate.dialect.H2 Following code should be added hibernate config file: <
Name me Hibernate 5 H2 Dialect class
Name me Hibernate 5 H2 Dialect class  Hi, What is the name of Hibernate 5 H2 Dialect class file? Thanks   HI, Class name is: org.hibernate.dialect.H2 Following code should be added hibernate config file: <
Name me Hibernate 5 H2 Dialect class
Name me Hibernate 5 H2 Dialect class  Hi, What is the name of Hibernate 5 H2 Dialect class file? Thanks   HI, Class name is: org.hibernate.dialect.H2 Following code should be added hibernate config file: <
Name me Hibernate 5 H2 Dialect class
Name me Hibernate 5 H2 Dialect class  Hi, What is the name of Hibernate 5 H2 Dialect class file? Thanks   HI, Class name is: org.hibernate.dialect.H2 Following code should be added hibernate config file: <
Hibernate 5 FrontBase Dialect class name
Hibernate 5 FrontBase Dialect class name  Hello, Tell me the Hibernate 5 FrontBase Dialect class name. Thanks   Class is: org.hibernate.dialect.FrontBase Hibernateconfiguration xml code: <property name
Hibernate 5 FrontBase Dialect class name
Hibernate 5 FrontBase Dialect class name  Hello, Tell me the Hibernate 5 FrontBase Dialect class name. Thanks   Class is: org.hibernate.dialect.FrontBase Hibernateconfiguration xml code: <property name
Hibernate 5 FrontBase Dialect class name
Hibernate 5 FrontBase Dialect class name  Hello, Tell me the Hibernate 5 FrontBase Dialect class name. Thanks   Class is: org.hibernate.dialect.FrontBase Hibernateconfiguration xml code: <property name
Hibernate 5 FrontBase Dialect class name
Hibernate 5 FrontBase Dialect class name  Hello, Tell me the Hibernate 5 FrontBase Dialect class name. Thanks   Class is: org.hibernate.dialect.FrontBase Hibernateconfiguration xml code: <property name
Java Program MY NAME
Java Program MY NAME   Write a class that displays your first name... with the following name (for example, for letter A, public displayLetterA() { }, Then, method main should create an object of your class, then call the methods
My name, java project
My name, java project  Write a class that displays your first name vertically down the screen â?? where each letter uses up to 5 rows by 5 columns... that letter in a method with the following name (for example, for letter A, public
My name, java project
My name, java project  Write a class that displays your first name vertically down the screen â?? where each letter uses up to 5 rows by 5 columns... that letter in a method with the following name (for example, for letter A, public
Find Month name using DateFormatSymbols class.
Find Month name using DateFormatSymbols class. In this tutorial, you will learn how to find the month name using DateFormatSymbols class. The class... DateFormat and SimpleDateFormar use DateFormatSymbols class to encapsulate
ModuleNotFoundError: No module named 'image-file-name-fixer'
ModuleNotFoundError: No module named 'image-file-name-fixer'  Hi...: No module named 'image-file-name-fixer' How to remove the ModuleNotFoundError: No module named 'image-file-name-fixer' error? Thanks   Hi
ModuleNotFoundError: No module named 'image-file-name-fixer'
ModuleNotFoundError: No module named 'image-file-name-fixer'  Hi...: No module named 'image-file-name-fixer' How to remove the ModuleNotFoundError: No module named 'image-file-name-fixer' error? Thanks   Hi
file upload and insert name into database - JSP-Servlet
file upload and insert name into database  Hi, I just joined as a fresher and was given task to upload a file and insert its name into database. The max size of the file can be 1mb. Along with the file name, there are other 2
Getting path name of uploading file in struts 2.1.8
Getting path name of uploading file in struts 2.1.8  In my question I used struts 2.8.1 instead of 2.1.8. Sorry
Getting path name of uploading file in struts 2.8.1
Getting path name of uploading file in struts 2.8.1  Hai! I am using struts 2.8.1. I want to upload file into database with the path name. How can I can get the original path name of the file in struts 2.8.1? It only display
CORE JAVA get middle name
CORE JAVA get middle name  hello sir...how to get middle name using string tokenizer....??? eg..like name ANKIT it will select only K...!!!!  ... character from the name. import java.util.*; class GetMiddleCharacter { public
Difference between class,name,id attributes in each JSP tag
Difference between class,name,id attributes in each JSP tag  Can i know the difference between class,name,id attributes in each JSP tags.................. These 3 are only used for reference ..... And what are the differernces
Retrieving the class name through Reflection API
Retrieving the class name through Reflection API   ... of the class (that is used in the program) that reflects the package name by using... the reference of the class java.util.Integer.class to it. Now retrieve the class name
How I Upload File and Store that file name in Database using JSP
How I Upload File and Store that file name in Database using JSP  Hi All, I m the beginner in JSP and I want to upload the file and store that file... form like Emp name, Emp id, city, address and one employee profile image(upload
NAME SORTING. . .anyone? - Java Beginners
NAME SORTING. . .anyone?  how can I sort names without using the 'name.sort' method? please help. . .anyone? the program should sort the first three(3) letters of the names tnx java masters out there!! (^_^) cVm  Hi
Reading xml file using dom parser in java with out using getelementby tag name
Reading xml file using dom parser in java with out using getelementby tag name  Hi, How to read the xml file using java with dom parser, but without using getelementbytag name, and also read the attribute values also. I had
find jar file name from multiple set of jar files
find jar file name from multiple set of jar files   I would like to find jar file name from multiple set of jar files where the given class nameââ?¬Â?com.rational.ft.util.debugââ?¬Â
Name unique
Name unique  I want to check whether the value which I give for the name textfield already exists in the database. In case if it exists , it should.... In other words, value for the name should be unique
search for a name
search for a name  Search for a name Write a program to accept an array of names and a name and check whether the name is present in the array. Return the count of occurrence. Use the following array as input {?Dave?, ?Ann
How to retrieve file name and path of an excel spreadsheet imported into Oracle Database
How to retrieve file name and path of an excel spreadsheet imported into Oracle... Oracle database and I want to know how to retrieve the path of the file... of the spreadsheets imported (so I would know the location of the original source file
Get Property by Name
to get Property by Name. For this we have a class name "Get Property By Name". Inside the main method  we have the list of method that help you... by Name      
Java Get Host Name
Java Get Host Name       In this Example you will learn how to get host name in Java... name of a computer or an IP address using Java application language. The given
Finding out the super class name of the class
Finding out the super class name of the class   ...:\roseindia>java Fsupercls class java.awt.Component Download... name by using the getSuperclass() method. The given example demonstrates the use
Class and interface in same file and accessing the class from a main class in different package
Class and interface in same file and accessing the class from a main class in different package  Hello everyone; I was going through some design... a class named CantFly in same file. A main method CheckAnimal.java. Below

Ads