This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

.class file does not retain the name of original .java file

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally, .class files retain the name of the original .java file (i.e. foo.java creates a foo.class). When I compile my AbstractSyntax.java file, it changes in to a Assignment.class file. Why might this be happening?
 
Marshal
Posts: 6670
177
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's probably not, it just appears that way.  Please post the exact commands you executed and what directories you are in.
 
Darien Springer
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am compiling the .java files on a Ubuntu shell running on my Windows 10 operating system. Here is the filepath I am compiling in: /mnt/c/fall_2019/project/softwarestudents/ch02-08 (Clite)/programs

Command I used:


 
Knute Snortum
Marshal
Posts: 6670
177
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And there's no AbstractSyntax.class in that folder when you're done?  Try typing the command ls in that folder and posting the result.
 
Darien Springer
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AbstractSyntax.java  IntValue.class   Token.java           clone.cpp          hello.output
Assignment.class     Lexer.class      TokenType.class      clone.output       interpreter1.tar.gz
Binary.class         Lexer.java       TokenType.java       convert.cpp        lab3
Block.class          Loop.class       Type.class           convert.output     miniProg.cpp
BoolValue.class      Operator.class   Unary.class          dyn-fact.cpp       nested.cpp
CharValue.class      Parser.class     Value.class          dyn-fact.output    nested.output
Conditional.class    Parser.java      Variable.class       factorial.cpp      newton.cpp
Declaration.class    Program.class    cast.cpp             factorial.output   newton.output
Declarations.class   Skip.class       cast.output          float-fact.cpp     orig.txt
Expression.class     Statement.class  castimplicit.cpp     float-fact.output  single.txt
FloatValue.class     Token.class      castimplicit.output  hello.cpp
 
Bartender
Posts: 2483
108
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The .class name generated matches the name of the class present in the .java file
e.g.
Although I named the file as Test.java, you should be able to see A.class and B.class after compiling it.

However if you have a public class, it should be in the same file as the class name: "Here:Desktop" is just my bash prompt ;)
 
Darien Springer
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah. The class file in question has a bunch of different separate classes in it. One of the classes is which inherits the code from . The Assignment class is nowhere near the top of the file. Why do you think the interpreter chose that as the name of the class file?
 
Marshal
Posts: 67533
257
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

The javac tool isn't an interpreter. The rules are that the file name must match the name of all public top‑level classes in it, which means all the public classes would have to have the same name, so you can only fit one public top‑level class into an XYZ.java file. Same name as the file. Whether it is good design or not, you are allowed multiple non‑public top‑level classes, but the javac tool produces one XXX.class file for each declared class. And those files have the same names as the classes they are compiled from (plus .class). The files have those names because they match the names of the classes you wrote.
 
Rancher
Posts: 3419
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your AbstractSyntax.java file contained a class called AbstractSyntax, then there should be an AbstractSyntax.class file generated.  However, it looks like that's not the case.  Your AbstractSyntax.java file has many other classes in it, but none are actually called AbstractSyntax.  That is, your file does not contain a declaration like this, right?
 
Darien Springer
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct, there is no AbstractSyntax class in the AbstractSyntax.java file.

Also, there are like twenty classes in that file and I didn't see a .class file created for any of them except Assignment.
 
Sheriff
Posts: 14767
245
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might help if you posted the source for your AbstractSyntax.java here so people can look at it instead. Without seeing the source, people are either going to guess or assume. Neither is optimal for figuring out what the real problem is.  And please UseCodeTags when you post code.
 
Darien Springer
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize. It looks like compiling AbstractSyntax.java DID create a class file for each class contained within AbstractSyntax.java. I must have been really tired because I didn't notice that. Thank you all for the help!
 
snakes are really good at eating slugs. And you wouldn't think it, but so are tiny ads:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!