File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How does java -version work without setting path to java\bin Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How does java -version work without setting path to java\bin" Watch "How does java -version work without setting path to java\bin" New topic
Author

How does java -version work without setting path to java\bin

Rakesh Rajmohan
Greenhorn

Joined: Jul 09, 2009
Posts: 22
Hello.. When I try compiling my java program using 'Javac' I use to get error "Javac not recognized as...". So I have set the path..

"set path = C:\Program Files\Java\jdk1.5.0_03\bin". So the error stopped.

But when I checked using 'java -version' from command prompt, it worked even before I had set the path as above.

Help me understanding the way it worked. Thanks!!


Cheers,
Rakesh
Kalabaw moo
Ranch Hand

Joined: May 26, 2009
Posts: 61
try this path

Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3742
    
  16
It's running the java.exe in your c:\windows\system32 directory.
This uses the registry to find out the location of your JRE.


Joanne
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14420
    
  23

Welcome to JavaRanch.

You most likely have a java.exe in your Windows system directory (C:\Windows\System32).
That version of java.exe looks in the Windows registry to find the JRE to execute.

The Windows system directory is in your PATH by default on Windows.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Rakesh Rajmohan
Greenhorn

Joined: Jul 09, 2009
Posts: 22
Great.. Can you tell when why is the java.exe present in system32 folder..?

and what I understand from the post is using "java - version" command to find out if the path has been set correctly to java\bin is not the correct way.

So what is the best way to find out if the path has been set correctly.. (I can best type 'set path' in commond prompt and it gives the path info..)

Cheers,
Rakesh
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14420
    
  23

Probably because besides the JDK you have a JRE installed separately. I think the JRE installation puts java.exe in your Windows system directory.
Kalabaw moo
Ranch Hand

Joined: May 26, 2009
Posts: 61
When JRE is installed the java.exe is included and I was able to try that in one of my laptop it ran the application I created without the jdk. I just typed in java MyApplication
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How does java -version work without setting path to java\bin