0

So, this is most probably a stupid question... but I am a beginner in Java!

I've managed to run the basic "Hello World" in cmd, but I've noticed that when my code was complied using javac, the class name is completely different to my notepad file. I saved my notepad file with the code in as FirstProgram.java but I've notice my compiled version (class file) has been named as HelloWorldApp.class

How do I get the class version to match the notepad name??

Andy Turner
  • 137,514
  • 11
  • 162
  • 243
itsTed
  • 9
  • 7
  • How did you compile it with `javac`? What command line did you use? What code did you compile? I'd guess you called the class `class HelloWorldApp`. – Andy Turner May 21 '18 at 14:02
  • The `.class` filename will be determined by the name of the class in your code. Usually people use the same name for the class and the `.java` file. – khelwood May 21 '18 at 14:04
  • By getting your notepad name to match the name of the class inside the source file – Erwin Bolwidt May 21 '18 at 14:04
  • A better place for a java beginner is ... like the Oracle beginners tutorial. Whatever you can dream of asking at this point ... is explained already in many many places. – GhostCat May 21 '18 at 14:06

1 Answers1

0

If your code looked like this:

class HelloWorldApp {
  // Something here.
}

then when you compile it, a class file HelloWorldApp.class will be produced.

Call the class FirstProgram instead:

class FirstProgram {
  // Something here.
}
Andy Turner
  • 137,514
  • 11
  • 162
  • 243