• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Head first into Java

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I hope everyone is doing well. I am writing today because I am having issues with executing code found in the Headfirst into java book. I've gone to Oracle's Java page and downloaded JDK 11. I thought I had everything set up right, but when I try to execute compiled code, I get the error in the screenshot attached.

Here is a copy of the code I am working with:




Please excuse the silliness of the phrases. If anyone can help me with this, I would appreciate it. Thanks to all that apply.

Mike
p1.png
[Thumbnail for p1.png]
Error
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you post an error message please cut and paste the text into your post, screen shots are not the easiest to deal with.

Did you look on your computer to see if there is a jvm.dll at the path indicated in the error message?

When you run your Java program do not add the ".class" to the end of the Program name. Also, the java command is case sensitive so you have run it with the exact same upper/lower case as in your original source code file.
 
Marshal
Posts: 79177
377
  • 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
 
MikeL Robinson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Thank you for your reply, from now on I will post error messages in text, and thank you for the welcome . I checked the java folder, and the jvm.dll is there. Not sure where to go from here.

Mike
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try to re-run it with the proper case and without the ".class" ?
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You say you downloaded the JDK 11 but your error message says JRE 1.8.  I don't think your PATH variable is correct.  To find out where the java program is launching from, type this at the command line:

   where java

and

   where javac

Post what both commands print.  Then type:

   path

and post that too.
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Starting with Java-11, the JDK install no longer updates the location of the JRE in the path and any previous install of Java is listed first in the path so that is what it finds. I think Oracle cop'd out on this one.

What I ended up doing, though I'm not thrilled about it (open to suggestions folks) is:
Make a new environment variable "JAVA_HOME" set to "C:\Program Files\java\jdk-11"
then I added to the very beginning of the Path environment variable
%JAVA_HOME%\bin

This works but now JAVA_HOME will have to be kept up to date.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's pretty much what I do, except that I don't put %JAVA_HOME%\bin at the beginning of my PATH variable.  If you type where java at the command line, you can learn what the path to your Java exec is.  Then, either place the %JAVA_HOME%\bin before that, or uninstall the old Java.
 
MikeL Robinson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

After setting up the environment variables as suggested, and not running the code with .class at the end, I was able to get it working . Thanks to all that replied, I will have to remember to change home variable with every release. I appreciate the help.

Regards,

Mike
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:That's pretty much what I do, except that I don't put %JAVA_HOME%\bin at the beginning of my PATH variable.  If you type where java at the command line, you can learn what the path to your Java exec is.  Then, either place the %JAVA_HOME%\bin before that, or uninstall the old Java.

That's what I did and I found that Oracle had installed the previous version at the head of the line.
 
Let nothing stop you! Not even this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic