my dog learned polymorphism*
The moose likes Beginning Java and the fly likes How to run a program with multiple classes in command prompt. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to run a program with multiple classes in command prompt." Watch "How to run a program with multiple classes in command prompt." New topic
Author

How to run a program with multiple classes in command prompt.

Saumya Purkayastha
Greenhorn

Joined: Mar 27, 2010
Posts: 23
I have compiled and successfully ran 5 programs as of now. The common thing in all the programs were that the entire program was inside a single class. But now as I have moved to the further chapters I am finding programs with more than 1 class. What do I do in this case? Should I write all the programs in a single .java file or should I save them as different .java files? How do I actually compile these in Command Prompt?

Can anyone explain this to me?

Thanks and Regards, Saumya Purkayastha - Sam
Specialist - Internet Marketing
Christiaan Lombard
Greenhorn

Joined: Nov 22, 2009
Posts: 26
You can either put each class in in a separate file or, though this is not considered good programming practice, you can put them all in one file.

When you compile the class containing the main method all other classes the main class needs will also automatically be compiled.

SCJP 6
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You compile them the same way you compile now--you already know how to specify classpaths. You run them the same way.
 
Consider Paul's rocket mass heater.
 
subject: How to run a program with multiple classes in command prompt.
 
Similar Threads
How to run a java program
Running My First Java Application
Down loading software
Interacting with Windows command prompt
Setting up Eclipse