This week's book giveaway is in the Design forum.
We're giving away four copies of Experimentation for Engineers: From A/B testing to Bayesian optimization and have David Sweet on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

java Zoo.java doesn't work

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Studying for the Java SE 8 OCA and then OCP certs next.  It asks me to enter the below code and execute.  However, $ javac Zoo.java &  $ java Zoo highlight red and this doesn't run.  It states if I receive any error to verify I have a JDK and not a JRE installed.  I've confirmed that I have the latest JDK installed and no pending updates for Netbeans.  Any feedback/suggestions would be much appreciated, thanks!

}
 
lowercase baba
Posts: 13086
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that is not valid java code.  are you SURE that's what your Zoo.java file is supposed to look like?
 
Marshal
Posts: 77564
372
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and welcome to the Ranch
The two lines beginning dollar are what you are supposed to write at the command line
 
Sheriff
Posts: 17490
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... and the $ is supposed to be the command prompt; you'd only type whatever comes after the $
 
Chris Poston
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quick responses!  Sorry, my work has kept me busy and I was unable to respond sooner.

Fred, Zoo.java previously just listed the main method.  I was told to type the main method into a file called Zoo.java and the to execute the two lines with $.  I couldn't figure out where to place those so I just posted my most recent attempt.

Ritchie, thanks!  

Ritchie/Junilu, i tried entering these in the DOS Command Prompt (I assumed that's what you meant).  I didn't have any luck running the $ lines of code with/without the $ here either.  Google searches said to change the directory to where the zoo.java file would be but I didn't have any luck with this either.  I appreciate the help and I'll try to reply quicker this time.  Being Friday, I should be free to respond quicker later today!
 
Campbell Ritchie
Marshal
Posts: 77564
372
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chris Poston wrote:. . .  Google searches said to change the directory to where the zoo.java file would be . . .

That sounds correct. Assuming you have opened a Windows/DOS command prompt, try the following two instructions:-

mkdir java
cd java

You can use a name different from java. Whenever you open the command prompt, use the second line to take you to your folder. When you have hundreds of classes in it, you can always create more folders and move things. Now use the dir command to find what is in that folder. Move your Zoo.java file into that location and use the following two commands:-

javac Zoo.java
java Zoo

Note only one command requires an extension. Tell us what happens.

PS: You would use the same instructions on a Linux/Unix/OS X terminal.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chris Poston wrote:Ritchie/Junilu, i tried entering these in the DOS Command Prompt (I assumed that's what you meant).  I didn't have any luck running the $ lines of code with/without the $ here either.  Google searches said to change the directory to where the zoo.java file would be but I didn't have any luck with this either.  I appreciate the help and I'll try to reply quicker this time.  Being Friday, I should be free to respond quicker later today!


It's much easier to help you with this if, instead of only saying "no luck", you explain exactly what you did in the command prompt (what commands did you type in?) and what exactly happened that you didn't expect (did you get an error message? what was the error message?).

If you've never used the command prompt before and you don't know about basic concepts such as the current directory, and basic commands of the command prompt, then lookup a tutorial for the command prompt first and make sure you understand the basics. It will be very useful, because you'll be using the command prompt regularly as a programmer.
 
Chris Poston
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Chris Poston wrote:. . .  Google searches said to change the directory to where the zoo.java file would be . . .

That sounds correct. Assuming you have opened a Windows/DOS command prompt, try the following two instructions:-

mkdir java
cd java

You can use a name different from java. Whenever you open the command prompt, use the second line to take you to your folder. When you have hundreds of classes in it, you can always create more folders and move things. Now use the dir command to find what is in that folder. Move your Zoo.java file into that location and use the following two commands:-

javac Zoo.java
java Zoo

Note only one command requires an extension. Tell us what happens.

PS: You would use the same instructions on a Linux/Unix/OS X terminal.



When I move to the directory in which Zoo.java is located and type java Zoo.java i get the following message: 'javac' is not recognized as an internal or external command, operable program or batch file.
when typing java Zoo, it states Error:  Could not find or load main class Zoo.

i'm in the directory where my Zoo.java file is located and used the command dir to confirm it's there.

The above was done going to the directory it was originally created in.  I also made a new directory listed as Java and and moved the file there but still received the same messages.

 
Ranch Hand
Posts: 146
4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

javac' is not recognized as an internal or external command, operable program or batch file.  


Take a look at the Common Problems page: http://docs.oracle.com/javase/tutorial/getStarted/problems/index.html

That message is from the OS.  You need to tell the OS where the javac.exe file is located.

Another solution is to use the full path to the javac.exe file:
C:\Program Files\Java\jdk1.8.0_60\bin\javac.exe -cp . -Xlint -Xdiags:verbose TestCode23.java

 
Chris Poston
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norman Radder wrote:

javac' is not recognized as an internal or external command, operable program or batch file.  


Take a look at the Common Problems page: http://docs.oracle.com/javase/tutorial/getStarted/problems/index.html

That message is from the OS.  You need to tell the OS where the javac.exe file is located.

Another solution is to use the full path to the javac.exe file:
C:\Program Files\Java\jdk1.8.0_60\bin\javac.exe -cp . -Xlint -Xdiags:verbose TestCode23.java



I now receive the message C:\Program' is not recognized as an internal or external command, operable program or batch file when trying this.  
C:\Program Files\Java\jdk1.8.0_73\bin\javac (tried with and without the .exe).  This is the path to my javac file.  I've tried the solution listed on the link you provided but the results are the same.  I tried using the solution to the full path as well after having it match my files.  This is what i used just to verify i did this correctly:
C:\Program Files\Java\jdk1.8.0_73\bin\javac.exe -cp . -Xlint -Xdiags:verbose Zoo.java    i tried this with and without the .exe listed on \javac.
 
Marshal
Posts: 4176
555
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try wrapping the path in quotes:

"C:\Program Files\Java\jdk1.8.0_73\bin\javac" -cp . -Xlint -Xdiags:verbose Zoo.java

(or use the equivalent DOS path: C:\PROGRA~1\Java\jdk1.8.0_73\bin\javac )
 
Chris Poston
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:Try wrapping the path in quotes:

"C:\Program Files\Java\jdk1.8.0_73\bin\javac" -cp . -Xlint -Xdiags:verbose Zoo.java

(or use the equivalent DOS path: C:\PROGRA~1\Java\jdk1.8.0_73\bin\javac )



So given everybody's help, I was able to figure this out.  I created the same file "Zoo.java" in notepad and was able to run it successfully.  I guess the latest problem was however I setup the original "Zoo.java" using NetBeans IDE.  Placing the below code in notepad instead returned "Hello World!" through the command prompt.  Still looking into what I did wrong when using the Netbeans file.  However, the main issue is resolved.  Thanks again for all the help!

 
Chris Poston
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just as a side note when running the NetBeans created Zoo.java file it gives and Error: Could not find or load main class Zoo.  
 
Junilu Lacar
Sheriff
Posts: 17490
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's easier if you set your JAVA_HOME environment variable to "C:\Program Files\Java\jdk1.8.0_73\" then add "%JAVA_HOME%\bin" to your Path variable. This article linked below shows the steps, you just have to make sure you're using the appropriate values for your own installation.

https://kaanmutlu.wordpress.com/2013/04/26/setting-the-java_home-in-windows-7-64-bit/

Once you do this, you can just type the "javac" and "java" commands directly at the command prompt, the Path variable will take care of helping Windows figure out what the full path to the executable is.
 
Junilu Lacar
Sheriff
Posts: 17490
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chris Poston wrote:Just as a side note when running the NetBeans created Zoo.java file it gives and Error: Could not find or load main class Zoo.  



See if the advice here helps: http://stackoverflow.com/questions/20034377/netbeans-error-could-not-find-or-load-main-class
 
Junilu Lacar
Sheriff
Posts: 17490
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whenever you get an error like that, a good first step to take to show some effort is to open up a browser and copy/paste the error message to your browser address bar. Most modern browsers' address bar doubles as a search, so when you hit enter and the browser see that you didn't type a valid URL, it will assume you want to search for those words.  The browser will use whatever default search engine it is configure to use and then display a list of matches. If your issue is common enough, you'll usually find someone already has a solution for it.
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic