Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Can't Setup Java

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having trouble getting Java to run on my cp. I'm using the HeadFirst Java book, but I've checked multiple sites for directions. Just wanna get started.

I've followed the forum directions on "Running your First Program in Java". I checked that I downloaded the correct one. My cp runs Windows 10 64-bit and it matches the download. I triple-checked my PATH and made sure both variables are system variables.
I've tried running "java, javac, java -version, and javac -version" in the command prompt. Nothing has worked.
I've attached screenshots so you can see exactly what I'm seeing.

Any help is greatly appreciated!
Java-Issues.png
[Thumbnail for Java-Issues.png]
Java-Issues2.png
[Thumbnail for Java-Issues2.png]
 
Marshal
Posts: 74632
335
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Thank you for providing good information, which, I hope, makes the problem easier to solve. Edit the JAVA_HOME variable to remove \bin. Otherwise your PATH will be C:\Program Files\Java\jdk-14.0.1\bin\bin. You only want one \bin. Open a new command prompt and then see what happens.
 
Ranch Hand
Posts: 327
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope it's okay to share this.  Pluralsight is giving a free month for April and I recently JUST checked this out so I thought I would share.

https://app.pluralsight.com/library/courses/setting-up-java-development-environment/table-of-contents
 
Saloon Keeper
Posts: 8920
76
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your PATH don't enclose your %JAVA_HOME% stuff in double quotes.
 
Saloon Keeper
Posts: 24822
172
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:In your PATH don't enclose your %JAVA_HOME% stuff in double quotes.



I'm not so sure about that, but that trailing semi-colon within the quotes is a problem.

The tl;dr about Java installations:

1. All JVMs are ultimately installable from ZIP files. Java does not require any files in directories external to the ZIP tree to run. However, OS-specific installers may add a few decorations such as registry entries and/or installation in a set location (such as the Red Hat Linux "/usr/java" directory or Windows "Program Files").

2. It is advisable, although not essential, to set the environment variable JAVA_HOME. Point it at the root of the installed (unzipped) JVM directory. JAVA_HOME is a convention, and not - as far as I know - required by the Java specification (which originally didn't even consider environment variables, since not all potential target OS's might have such a thing).

3. Set your PATH to point to the "bin" directory within the JVM root directory. If you're using JAVA_HOME, then "%JAVA_HOME%\bin" should go in your PATH. In the Unix/Unix-like OS's, it would be $JAVA_HOME/bin. Thanks, Knute for the correction on the Windows syntax!

4. And finally, Java is not Internet (There Can Be Only One) Explorer. It is fully allowable - and sometimes very useful - to have multiple JVMs (both JDKs and JREs) of multiple versions installed on your machine. You can select which JVM will be used for a given Java application by simply invoking it by the path of the "java" executable. Just make sure that if the app uses JAVA_HOME, that you have a local setting of JAVA_HOME such that JAVA_HOME/bin would be pointing to that same executable. Also, the same rules apply to other products in the package, such as the javac compiler.
 
Sheriff
Posts: 7113
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

Tim Holloway wrote:2. It is advisable, although not essential, to set the environment variable JAVA_HOME. Point it at the root of the installed (unzipped) JVM directory. JAVA_HOME is a convention, and not - as far as I know - required by the Java specification (which originally didn't even consider environment variables, since not all potential target OS's might have such a thing).


I believe Maven uses JAVE_HOME, and maybe other external apps.

3. Set your PATH to point to the "bin" directory within the JVM root directory. If you're using JAVA_HOME, then "%JAVA_HOME\bin" should go in your PATH. In the Unix/Unix-like OS's, it would be $JAVA_HOME/bin.


"%JAVA_HOME\bin" should be "%JAVA_HOME%\bin".
 
Tim Holloway
Saloon Keeper
Posts: 24822
172
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whoops. Lost the second "%". Sorry. In Windows, you need to bracket environment variable names with "%" on both sides. In Unix, a single "$" is considered a sufficient hint. Kind of like Unix only needs 1 end-of-line character.

JAVA_HOME is used by Maven, Ant, Tomcat and doubtless many other applications. As I said, it's not part of the Java standard, but it is a very common convention, because it allows one to easily select an alternative JVM.

In Tomcat, at least, JAVA_HOME's value will be assumed (if not set) based on whichever JVM Tomcat can find (if any!) by default. But I always set JAVA_HOME and the default Java PATH (along with ANT_HOME and MAVEN_HOME) as part of my login script. It's a good practice.
 
Alexander Aull
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much everyone!
I deleted the \bin in the JAVA_HOME variable. Didn't solve it yet.
Then I deleted the ""s around JAVA_HOME in the Path variable and the extra ';'.
Then it worked!
 
Sheriff
Posts: 26948
83
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good work!

(Originally when Microsoft's operating system DOS was born, spaces were meant to separate parameters when you were typing at the command line. Which was the only way you could communicate with Windows. And then Microsoft decided that restricting file names to 8 characters with a 3-character extension was a pain. Which it was. So they allowed file names to be as long as you wanted, and they allowed you to have spaces in your file names. Which was great except they broke the rule about what spaces meant in the command line. But no problem, they just made up another rule that you could put quotes around a string and the spaces inside those quotes didn't count as spaces separating parameters. This made everything cool except that you had to be very careful to put the quotes in exactly the right place. And when you had a whole lot of very long parameters which had to be wrapped in quotes it was easy to get it wrong, but you could get used to it. Then the operating system got a GUI interface named Windows and people stopped using the command line, except for old-timers who hated GUI interfaces. Which means that the command line is now used mostly by people who aren't familiar with its rules and find themselves in quote-wrapping hell.)
 
Tim Holloway
Saloon Keeper
Posts: 24822
172
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:...And then Microsoft decided that restricting file names to 8 characters with a 3-character extension was a pain. Which it was. So they allowed file names to be as long as you wanted, and they allowed you to have spaces in your file names.



I think that the fact that the Macintosh (which didn't even have a command-line interface) had just recently come out supporting such things was probably more than co-incidental.

Incidentally, the 8.3 convention, like much of MS-DOS and its predecessor CP/M was lifted from the DEC minicomputer OS's of the time. Directory entries for the original CP/M and DOS FAT systems actually had an 8-byte slot for name and a 3-byte slot for extension rather than a single 11- or 12-byte area for the full name (and dot).

Could be worse. On the Prime Computer mini I worked with in school, file names were only 6 characters max. If you compiled a file named "mprg", the compiler would produce a "mprg_o" object file, where, on a Teletype terminal, the underscore actually rendered as a backwards-pointing arrow. It had a neat hierarchical file structure, though. Volume names were like so:<vol1> with ">" used as directory separator, so you could have <vol1>users>tim>myprg_o.

With only 6 characters for primary name and 2 for "extension", you had to be really creative in what you called things. :)
 
Campbell Ritchie
Marshal
Posts: 74632
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AA: Look what you've done (‍). You've started us old‑timers in the back room (where us mods drink beer) reminiscing about when we were young
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic