You can only call the main method. Create your main method so that it calls the method you want.
When I say the call method to main , you are not explicitly calling it. This is the only entry point to the java program when it is called.
If your class looks like this:
package com.foo; public class Test { public static void main(String[] args) { System.out.println("Hello World!"); } }
You can use the following command line to call main from a directory where you can find com/foo/Test.class (if you are in the classes directory in the structure shown below):
java com.foo.Test
If you want to do this from another (see the directory below), then you will need to set the class path.
java -cp /path/to/classes com.foo.Test
For clarity, suppose the directory structure is lower.
-path -to -classes -com -foo >Test.class
adarshr
source share