• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

set-up on windows 10

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've installed java on windows 10 and want to compile a program from the command line
when in the directory that holds the source code.

I set up environmental variables:
User var: (name) JAVA_HOME (value) C:\Program Files\java\jdk-10.0.1 and

System var (name ) Path (value) - there was a list of values, line by line
not separated by ";" - I added a last line : %JAVA_HOME%\bin

From the command line when in the directory that contains the source file
I type:  javac  filename.java

This set up does not work.  I was following directions from a java beginers web site.
Am I on the right track here? What should I correct?




 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please provide more as to what you mean by

Frankie Bailey wrote:I type:  javac  filename.java

This set up does not work.


Do you get any error messages? If so what are they?

If you type echo %path% into the command line prompt what do you get?
Please paste you answer in your reply.

What is the exact directory/folder where javac can be found?
 
Frankie Bailey
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you type echo %path% into the command line prompt what do you get?
Please paste you answer in your reply.

What is the exact directory/folder where javac can be found?


When I type -  %echo% at C:\  -  I get "the filename, directory name, or volume label syntax is incorrect".
I get the same the same message at every directory prompt.


C:\Program Files\java\jdk-10.0.1\bin  -   contains javac.exe and java.exe.  Are not these the tools to compile and excecute?

C:\javaSource -  contains the source code - the first program : HelloWorld.java

environmental vars are set:
JAVA_HOME (name) -  Program Files\java\jdk-10.0.1 (value)
path(name)  - %JAVA_HOME%\bin (value)

So: (1) Are the environmental vars set correctly?
(2) What directory do I navigate to and what do I enter at the command prompt to compile the program?

 
Frankie Bailey
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I type -  %echo% at C:\  

I meant When I type -  echo %path%
 
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

When I type -  %echo% at C:\  -  I get "the filename, directory name, or volume label syntax is incorrect". ... So: (1) Are the environmental vars set correctly?


No, not if you typed echo %PATH% correctly.  (It doesn't matter what directory you're in, nor does the case of the letters.)

I think your PATH environment variable is messed up.  Don't do anything until that is fixed.
 
Knute Snortum
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
To fix the PATH, since you're on Windows 10, I would type "environment" into the search field at the bottom of the screen.  Click on "Edit the system environment variables."  Click on "Environment Variables."  You will see a User Variables window and a System Variables window.  The PATH variable is both of those windows are combined to make the PATH variable you see at the command line.  Scroll down to PATH in both windows (one at a time) and press the Edit button on the right.

I don't know what you're going to see in those windows, but try to get the PATH variable correct.  The format is path:path:...  Editing should give you a nice list of all the individual paths.

I would advise you to copy and paste the contents of both PATH variables to a Notepad app of some kind.
 
Frankie Bailey
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Back up... You folks are quick!

I noticed that I did not put a space after echo.

echo %path% - produces the path that I see in the advanced properties window where the path is set.  It's very long but at
the end is the entry I made - %JAVA_HOME%\bin
 
Pete Letkeman
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When executing echo %path% from the command line (not PowerShell) you should be getting something kind of like:
C:\Program Files\Microsoft MPI\Bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files (x86)\Microsoft Emulator Manager\1.0\;C:\Program Files\dotnet\;C:\Program Files\Java\jdk-9\bin\;C:\Program Files\Microsoft VS Code Insiders\bin;C:\Program Files\Microsoft VS Code Insiders\bin;
The important part in this example is this C:\Program Files\Java\jdk-9\bin\; which is the location that javac is found.

If you get an error when running echo %path% from the command line then you may have a typo.
If you do not have a typo then you may not have the correct command line program started, I suggest that you use cmd.exe.
If you do not have a typo and you are using cmd.exe then you may have other system issues.

I've attached a screen shot of my result when I execute echo %path%, which has a lot.
Outlined in red is the value where I've chosen to place javac.exe.
cmd_2018-08-08_20-23-50.png
[Thumbnail for cmd_2018-08-08_20-23-50.png]
echo %path%
 
Pete Letkeman
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please copy and paste the results of running echo %path%.
It should contain the full path to where you have javac on your system.
 
Master Rancher
Posts: 4835
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

An example:


Microsoft Windows [Version 10.0.17134.191]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\Norm>echo %JAVA_HOME%\bin
C:\Program Files\Java\jdk1.8.0_60\bin

C:\Users\Norm>

 
Frankie Bailey
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Progress.

In the Advanced System Settings Environmental Variables box...

I deleted the %JAVA_HOME%.
I deleted my addition to the path and retyped - carefully - C:\Program Files\java\jdk-10.0.1\bin\

This worked. From the command prompt in the source file directory,  I compiled the program and have a .class file.

BUT... I got an error when executing -  could not find the jre. Do I have to make an addition to the path? Will try that.
Should have tried before I wrote this post. Too anxious to report success.
 
Norm Radder
Master Rancher
Posts: 4835
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I got an error when executing  


Please copy the full text of the error message and paste it here. It has important info about the error.
 
Frankie Bailey
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the error message:



Microsoft Windows [Version 10.0.17134.165]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\owner>cd...

C:\Users\owner>cd..

C:\Users>cd..

C:\>cd javaSource

C:\javaSource>dir
Volume in drive C is Windows
Volume Serial Number is 2656-4124

Directory of C:\javaSource

08/09/2018  12:02 PM    <DIR>          .
08/09/2018  12:02 PM    <DIR>          ..
08/09/2018  12:02 PM               426 HelloWorld.class
08/08/2018  02:12 PM               126 HelloWorld.java
              2 File(s)            552 bytes
              2 Dir(s)  906,624,696,320 bytes free

C:\javaSource>java HelloWorld
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: HelloWorld has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0
       at java.lang.ClassLoader.defineClass1(Native Method)
       at java.lang.ClassLoader.defineClass(Unknown Source)
       at java.security.SecureClassLoader.defineClass(Unknown Source)
       at java.net.URLClassLoader.defineClass(Unknown Source)
       at java.net.URLClassLoader.access$100(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

C:\javaSource>





 
Norm Radder
Master Rancher
Posts: 4835
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

HelloWorld has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0  


The java program is older than the javac program.  The output of the javac program is not compatible with the older version of the java program.

To see the program's versions, use the command with the -version option:
javac -version
java -version

Installing a compatible/newer version of java should fix the problem.
 
Saloon Keeper
Posts: 25830
184
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
JAVA_HOME is not used by the Java compiler or runtime.

In fact, it's not an official part of Java at all - just a common convention used by many Java products to point to which of possibly several JDK's or JRE's installed on your system you want to use for that app.

For basic compiling and running, you need to set the JDK bin directory in the PATH. While it's permissible to use an environment variable there (%JAVA_HOME%\bin), if you don't know how paths and environment variables work in Windows, then you're likely to get into trouble.

Likewise, adding C:\Program Files\java\jdk-10.0.1\bin\ to the PATH can be troublesome. The reason being that "Program Files" has a space in the filename and that confuses the OS command-line parser. Unless you explicitly quote the path, it's likely to actually add "C:\Program" to the path, which is meaningless here. So either quote the path or use the 8.1 equivalent (which is usually something like C:\PROGRA~1\java\jdk-10.0.1\bin). That's assuming that 8.1 aliases still apply. I haven't checked lately, since I don't do Windows any more.

The JDK has a JRE embedded into it. Thus you'll find the "java" program both in the JAVA_HOME\bin and in JAVA_HOME\jre\bin, but you don't need to point to the jre bin directory to run. Use the same PATH for both the javac compiler and java excutable.
 
Frankie Bailey
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The JDK has a JRE embedded into it. Thus you'll find the "java" program both in the JAVA_HOME\bin and in JAVA_HOME\jre\bin, but you don't need to point to the jre bin directory to run. Use the same PATH for both the javac compiler and java excutable.


Yes. This is what I understood when I downloaded the JDK. I can see that javac and java are both in the jdk folder.  So the path that I have set now leads correctly to javac - the program was compiled. So why is the path not correct for java to execute?

As far as quotes around "Program Files" ... they are necessary at the command prompt but not in the path variable -go figure.

But I cannot execute.  Should I delete the JRE folder? Ready to say "Good Bye World".
 
Norm Radder
Master Rancher
Posts: 4835
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But I cannot execute.  


Do you get the same error message?

What were the responses for the commands with the -version option?

What is the full contents of the PATH variable?
Open a command prompt and enter:
PATH
Copy the contents and paste here.

I expect the PATH variable to have two paths for java:
1) for the older version of the java.exe file. Set by a JRE installation
2) for the newer version of the javac.exe file
 
Tim Holloway
Saloon Keeper
Posts: 25830
184
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

Norm Radder wrote:
I expect the PATH variable to have two paths for java:
1) for the older version of the java.exe file. Set by a JRE installation
2) for the newer version of the javac.exe file



I don't. There Can Be Only One.

If there are multiple java paths in the PATH, then whichever one supplies an executable first wins. The runner-up is ignored. An exception to that being if you had a JRE preceeding a JDK in the PATH and asked for the javac program, since that's not in the JRE, only the JDK. So it's not actually an exception, when you get down to it.

In practice, you should not attempt to put BOTH a JDK and a JRE in your path. If you're doing development, just put the JDK bin directory in the path and it will work for both development and application execution. As I said earlier, there's a JRE embedded in the JDK, and it's indistinguishable from the JRE-only installation.
 
Norm Radder
Master Rancher
Posts: 4835
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have installed JREs many times.  The last installation added a entry at the start of the PATH.  The JDK installation does not change the PATH.  It's done manually.
So in my case:  java.exe comes from the location set by the JRE installation and the JDK comes from manually added path that is at the end of the PATH.

I was suggesting that could also be the case for the OP.  My requests were to have the OP post info to show what the situation was.

 
Tim Holloway
Saloon Keeper
Posts: 25830
184
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
OK, but I would "expect" the installer to either be smart enough to check for existing entries in the PATH if it does that. At the moment, no non-Windows installer I know of attempts to set the path - which might be rude on a multi-user system like Linux anyways.

But I concur. We definitely need to see Frankie's PATH as it displays in the same command window he compiles and executes java/javac in.

We can tell him, and he can think he understands, but long experience has taught me that what we think the user sees and what the user actually sees are often quite different.

Windows is a bit funky anyway. On Unix-derived systems, there's no separate PATH command, since PATH is just another environment variable. Windows inherited their concept from DOS, back before I think DOS even knew what an "environment" was. On top of that, there are at least 3 different "environments" in Windows: The global environment, the user environment and the environment that has been set or modified for each command window.

And incidentally, Frankie, changes to the Control Panel managed environments (the first two I just mentioned) do not update the current command window environment. You have to open a new one to see those changes. This is actually in line with how Unix works, even if some of the mechanisms are different.
 
Frankie Bailey
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whoa!

I looked closely at the path -  I saw: C:\Program Files(x86)\Comman Files\Oracle\Java\javapath . I navigated to that directory and inside there was  - java!
This entry appeared in the path list BEFORE my addition. I deleted this entry and ... sure enough, my program now executes.

Thanks to you all - are you cowboys?

But I concur. We definitely need to see Frankie's PATH as it displays in the same command window he compiles and executes java/javac in.

Frankie is a SHE, heehee.



 
Frankie Bailey
Greenhorn
Posts: 18
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cowgirl?
 
Norm Radder
Master Rancher
Posts: 4835
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Frankie - did you use the -version option to see what the versions were for java and javac?  Can you post them?

@Tim

I would "expect" the installer to either be smart enough to ...


Yes, I thought so too a while back.  I have had to clean up after every JRE install I have done for the last several years.  

I wrote a utility to find flles on the PATH variable.  Here's its report for the two files in question:


Found java.exe in:
 C:\Program Files (x86)\Common Files\Oracle\Java\javapath\           06/01/18 12:33 PM
 C:\ProgramData\Oracle\Java\javapath\                                06/01/18 12:33 PM
 C:\Program Files\Java\jdk1.8.0_60\bin\                              09/18/15 08:58 PM
Found javac.exe in:
 C:\Program Files\Java\jdk1.8.0_60\bin\                              09/18/15 08:58 PM

 
Frankie Bailey
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this what you want to see?


C:\>cd javaSource
C:\javaSource>javac -version
javac 10.0.1
C:\javaSource>java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
C:\javaSource>


Both javac and java are 10.0.1 from my jdk (now that I've removed the older path)

Norm Radder wrote:
I expect the PATH variable to have two paths for java:
1) for the older version of the java.exe file. Set by a JRE installation
2) for the newer version of the javac.exe file


This is exactly what happened.

So why am I doing this? At the turn of the century, I took a course in Java and
wrote a few java applets and built a web site around them for fun. But they
cannot be viewed in any browser now.  So I thought I might see them again
using the appletviewer if I installed java on my computer.  Having no luck.

In the meantime, I've been writing android web apps and converting them to
native with PhoneGap Build. They are homemade and simple but I put them
on the Google Play Store just for fun.

So if I re-learn java, might I not build a native android app? Meantime - it takes
me a week to say Hello World!



 
Norm Radder
Master Rancher
Posts: 4835
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

using the appletviewer if I installed java on my computer.  Having no luck.  


Can you post the error messages?  I am able to execute applets with appletviewer and with InternetExplorer.   It requires making entries in the Java exclusion list available through Java in the Control Panel.


The -version I was interested in was for the program on the path that was removed.  The programs from the same folder would have the same version as you have shown.
 
Tim Holloway
Saloon Keeper
Posts: 25830
184
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

Norm Radder wrote:I wrote a utility to find flles on the PATH variable.



That's a standard command in Unix/Linux. "which -a". One reason why I like developing on that platform. You don't have to go out and hack or buy a lot of support apps (or at least chase down and individually install open-source ones) because most distros come with very rich package libraries and tons of software development and text-processing utilities. Which are often pre-installed (at least if the OS installer has a "software development" option). It's also nice that all my apps aren't constantly chattering back to their makers over the Internet, won't give me guff about license keys, and there's no 30-minute crawl after each boot-up while virus scanners pound the disk silly. But that's just rubbing it in.

Sorry about the confusion Frankie. My grandfather's name was Frank.

You may not be able to find the appletviewer on recent Java releases. Applets are a lost cause since the rash of security exploits that ruined their good names forever. Sadly, just when internet performance was good enough to support the heavy overheads that applets could demand.

It's not totally trivial to convert applets to stand-alone application, but it shouldn't be too hard. And, incidentally, the recommended substitute for applets is jnlp, which will download (and cache) an actual stand-alone application. It won't run the app in a browser window like an applet, but it works well otherwise.
 
Frankie Bailey
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about the confusion Frankie. My grandfather's name was Frank.  

My father's name was Frank and I was born on Father's Day.

I  googled around and found a hint to see the applets. Type: appletviewer classfilename.html.
All of my applets are wrapped in an html file since they were pages in a web site. It worked.
I see the applet but not the html page. In a browser, I see the html page but not the applet.

Two goals accomplished. I've java set up to write, compile and execute. And I can see
my applets again.

I've converted one of the applets [this past month] to web app. It's much nicer - the  java
version is really clunky. So, I'll get the app ready to submit to Adobe PhoneGap Build and
then the Google Play store. And get on with re-learning java to write a native app.

"It's a hobby...not a business."










 
Frankie Bailey
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the next rank up from, Greenhorn?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic