Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


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


Advertisement
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
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
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
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
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 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
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...;java RoseIndia Constructor Called Object's Class name =>
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 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 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
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
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
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
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
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
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
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
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
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
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
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
Advertisements
 

 

 

DMCA.com