I have two seperate classes. Both classes contain a main method. Id like to remove the main method from my SaveData Class and accees the code from my DynamicTest Class. My main method is now located in DynamicTest class.
Every class can have a main method. There is really nothing special about it - a class can even have several main methods if you follow overloading rules. You can call the various main methods like you'd call any other method.
The ONLY time main is special is when you start up java, and pass the JVM a class name. The JVM will then look for the one main method with the signature equivalent to
So if you want to run the main in your DynamicTest class, just pass that to the jvm:
>java DynamicTest
instead of
>java SaveData
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Thanks for the info fred rosenberger. Can you help me understand a couple other things im confused about?
I have a main method public static void main(String [] args)
in both classes. I want my main method in DynamicTest to run my program. Do I need to remove the main from SaveData? If so how do I properly do so and call that method from my DynamicTest class?
I don't think this does what you think it does
read() is not guaranteed to read the full buffer's worth. Why would you want to break out of the loop if you aren't done reading the data?
Papi Escobar wrote:Thanks for the info fred rosenberger. Can you help me understand a couple other things im confused about?
I have a main method public static void main(String [] args) in both classes. I want my main method in DynamicTest to run my program.
I think Fred was very clear on that.
Papi Escobar wrote:Do I need to remove the main from SaveData? If so how do I properly do so and call that method from my DynamicTest class?
You don't need to remove main() from SaveData. You can call
Carey Brown wrote: . . . So, what happens if you remove it? Is there some functionality you'll lose? Does it compile? Does it run?
When I remove it the program doesnt run correctly. I needed to package SavedData and then import the SaveData class in DynamicTest, I then replaced main() with method and called this method from DynamicTest class.
Papi Escobar wrote:When I remove it the program doesnt run correctly. I needed to package SavedData and then import the SaveData class in DynamicTest, I then replaced main() with method and called this method from DynamicTest class.
Good work. So, am I to assume that your question has now been answered?