Home Answers Viewqa Java-Interview-Questions Java class name and file name are different

 
 


Ashwath
Java class name and file name are different
4 Answer(s)      2 years and 6 months ago
Posted in : Java Interview Questions

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 Pages:
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
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
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
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
Java file get name
Java file get name In this section, you will learn how to get the name... the name of the file. Here is the code: import java.io.*; public class... name is: " + st); } } Through the method getName() of File class, you can
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
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
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
Programming - Transform Name - Answer
Java: Programming - Transform Name - Answer Solution to: Write a program to redisplay a name, possibly transformed. This Java program will reformat...) { } } It compiles, and does exactly nothing! But now you are sure your file name
Use of name() function in XPath
This xml file contains various nodes and we have used name() function in our XPathName class to retrieve name of different nodes according to queries: Here... Use of name() function in XPath   
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
Programming: Kingdom - Name
Java NotesProgramming: Kingdom - Name Name ______________________________ The Kingdom class should be extended to know its name. There needs to be a way to set the name, get the name, and somewhere to store the name. Indicate your
Combine Name
Java: Example - CombineName The following program has two text fields, one for a first name and one for a last name. When the button is pressed, it formats them in the result field in the standard last name comma first name style
name of year in chinese
name of year in chinese   hello my name kiemtheng i'm come from Cambodia, i would to write java programming to calculate a name of year for each...*; import java.text.*; public class FormatDate{ public static void main(String
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
Duplicate name in Manifest - Struts
Duplicate name in Manifest   Hello I'm facing the following error... java.util.jar.Attributes read WARNING: Duplicate name in Manifest: Depends-On. Ensure... file. how can I solve it? Please help me.. Thanks.  Hi friend
name of year in chinese
name of year in chinese   hello my name kiemtheng i'm come from Cambodia, i would to write java programming to calculate a name of year for each...*; import java.text.*; public class FormatDate{ public static void main(String
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
Set the mapping name
and the same Action class name can be used.  What are the disadvantages... to have the method name different from the actual method called, at the same time...;  3. Set the mapping name to the action attribute of html
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...;java RoseIndia Constructor Called Object's Class name =>
Find Name of Excel Sheet
This is basically stores the sheet name and tells where the beginning of file record is within the HSSF file.  getSheetname(): This method is used to find the name... Find Name of Excel Sheet     
Stoting file name in Map
Stoting file name in Map  how to store id and file name in map
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
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      
Set the mapping name
;  2. Set the action name to the action attribute... the method name to call as a query string parameter, or use an alias. ... the method name to the actual method to call.  Actual method
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
Duplicate name in Manifest - JSP-Servlet
Duplicate name in Manifest   Hello, I don't have the classpath... just put the current JDK that I'm using now. C:\Program Files\Java\jdk1.6.0_12... WARNING: Duplicate name in Manifest: Depends-On. Ensure that the manifest does
Java program to get class name without package
Java program to get class name without package ...:\javaexamples>java GetClassWithoutPackage Full class name =java.lang.String... example which describes you that how you can get the class name without package
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
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
Remote System OS name in JAVA - JSP-Servlet
Remote System OS name in JAVA  I need to print the different os names of the all computers in my local network. I know that with System.getProperty("os.name"), I get the os name of my computer but for the other computers, I have
need solution to get file name from path which should give by user
need solution to get file name from path which should give by user  how do i write a program in java that i should get file path from arguments.currently this code creates the file at d:\ but i need to get this file name
Finding out the super class name of the class
Finding out the super class name of the class   ... name by using the getSuperclass() method. The given example demonstrates the use of getSuperclass() method in more detail. Create a class "Fsupercls"
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ââ?¬Â
upload image and fields.....fields is id name.....
upload image and fields.....fields is id name.....  Get Data using Java Servlet The frame takes following input.. Id: Name: browse:Image are file
Class
and rectangle class are calling with different - different arguments two times...; class_name object_name = new class_name(); Output of the program : .... Constructor is the method which name is same to the class. But there are many difference
Passing classid or name in request using Jquery
some divs with class name & id's.I want to pass this div name or id with parameter so that I save my file with that name. Can some body help me as I am...Passing classid or name in request using Jquery  Hi, I am new
Find Your Host Name
Find Your Host Name   ... the host name of the local system in a very simple example. Here we are just call the InetAddress class and after made a object of that class we call a getLocalHost
different type input in java
); } }   Java read input through Scanner: import java.util.*; class...); } }   Java read input through BufferedReader import java.io.*; public class...different type input in java  hiiiii... get input different different
SQL Alter Column Name
(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10... | Stu_Name | Stu_Class | +--------+----------+-----------+ | 1 | Komal... SQL Alter Column Name     
personal name aliases
personal name aliases  enter the name search result in internet connection using java code   Please visit the following links: http://www.roseindia.net/servlets/search.shtml http://www.roseindia.net/answers/viewqa/JSP
Java program to get domain name by URL
Java program to get domain name by URL       We can also get the domain name by the java...:\javaexamples>java GetDomainName Domain name by URL "http://www.roseindia.net
SQL Alter Column Name
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class... | Stu_Name | Stu_Class | +--------+----------+-----------+ | 1 | Komal | 10... +--------+----------+-----------+ | Id | Stu_Name | Stu_Class | +--------+----------+-----------+ | 1
JDOM Attribute Example, Different method of Attribute class.
JDOM Attribute Example, Different method of Attribute class...(java.lang.String name) method of Element class returns the child element.The.... The getQualifiedName() method of Attribute class returns name of attribute. We
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.