-3

I have an assignment that explicitly states that from the command prompt we are supposed to invoke

java GreeterTester John

and then print "Hello, John." when I do that (I've already navigated to the src folder) I get the error

could not find or load main class GreeterTester

Now I've seen a lot info about how we have to type the package name (we're using the default package) in our command prompt when invoking this command, but what could I put in my code that allows me to simply input

java GreeterTester John

in command prompt, and it works? Because we have to use that exact command.

Again, I don't need the package name

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Jesse Wiatrak
  • 73
  • 1
  • 1
  • 6
  • Make sure to include the package name when you run it. Please show us your code (including the package declaration) and the exact command line you used (cut and paste it to be sure). – markspace Jan 23 '17 at 03:20
  • No, what I'm saying is I need to be able to do this without including the package name in command line. – Jesse Wiatrak Jan 23 '17 at 03:21
  • try with `-cp` commad: `java -cp . GreeterTester` – Baby Jan 23 '17 at 03:23
  • 1
    You have no package, so don't use a package name. You have not compiled your class, supposedly, so read your instructions again – OneCricketeer Jan 23 '17 at 03:25
  • I don't know if you need a classpath like @Baby says, but try it http://stackoverflow.com/a/32134203/2308683 – OneCricketeer Jan 23 '17 at 03:25
  • When I attempt to compile using javac GreeterTester.java, I get "'javac' is not recognized as an internal or external command, operable program or batch file." – Jesse Wiatrak Jan 23 '17 at 03:29
  • @JesseWiatrak its because you haven't or incorrectly set the environment path variable. Refer [here](http://stackoverflow.com/questions/7709041/javac-is-not-recognized-as-an-internal-or-external-command-operable-program-or) – Baby Jan 23 '17 at 03:36
  • @Baby Try it why? That's the default. – user207421 Jan 23 '17 at 03:46
  • @EJP urmm. well, in case the default was changed? – Baby Jan 23 '17 at 03:49
  • The JDK wasn't in the variables. I added it and I fixed it. Thanks – Jesse Wiatrak Jan 23 '17 at 04:04

1 Answers1

1

Java is a compiled language. You must first compile your code with javac GreeterTester.java

See http://docs.oracle.com/javase/tutorial/getStarted/cupojava/unix.html#unix-2b

ZNix
  • 61
  • 1
  • 3