Peter_Browning
Peter_Browning

Reputation: 259

Java compiler command concept is eluding my grasp

OK, so the problem that I am having is that whenever I type javac into the cmd prompt, it doesn't compile the file I specified. I have a couple if question to help my understanding of what it actually does.

-can you compile jar files? If so, what will it do.

-if you type a basic hello world program in a text editor, such as vim, what do you save it as? Hello world . class, hello world.java, hello world.txt?

-if you have a text file, class file, or Java file correctly formatted, how do you compile it CORRECTLY?

-do you have to specify a class or file in your program? (public class example{})

-how is vim really that different than cmd prompt?

Some help would be greatly appreciated.

Upvotes: 0

Views: 46

Answers (1)

deezy
deezy

Reputation: 1480

I will be going through your questions one at a time:

  1. It doesn't make sense to compile .jar files... You can only run them.

  2. Save it as HelloWorld.java, and HelloWorld.class will be created once you compile it. Avoid using spaces in file names as much as possible, it will make things easier.

  3. First navigate to the source folder which contains the file using cd commands, then type javac ExampleProject.java. Obviously you would replace "ExampleProject" with the correct name.

  4. If you want to do something meaningful, then you have to declare a class. I don't think a file with only import statements would do much good :P

  5. VIM is a text editor for writing your code; Command Prompt is used for the computer's administrative functions and executing batch files.

Let me know if you need additional clarification.

Upvotes: 1

Related Questions