aspose file tools*
The moose likes Beginning Java and the fly likes How to install jdk and set path variable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to install jdk and set path variable?" Watch "How to install jdk and set path variable?" New topic
Author

How to install jdk and set path variable?

jignesh soni
Ranch Hand

Joined: Dec 10, 2007
Posts: 150
I have downloaded and installed jdk1.6.0_01 on my computer.
path is c:\jdk1.6.0_01\bin.
I have set environment variable "path" and value is "c:\1.6.0_01\bin".
I have written a source code class TrialClass.java and saved in c:\JavaFiles
I am trying to compile this source code as follows
c:\Documents and Settings\Aministration>javac TrialClass.java
result is "javac: file not found: TrialClass.java"

What is it that I am not doing right ?
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

Originally posted by jignesh soni:
I have downloaded and installed jdk1.6.0_01 on my computer.
path is c:\jdk1.6.0_01\bin.
I have set environment variable "path" and value is "c:\1.6.0_01\bin".
I have written a source code class TrialClass.java and saved in c:\JavaFiles
I am trying to compile this source code as follows
c:\Documents and Settings\Aministration>javac TrialClass.java
result is "javac: file not found: TrialClass.java"

What is it that I am not doing right ?


There is nothing wrong in the way you installed java.

Look close at the error message it says file not found which means that the file you want to compile using javac is not in that current path.

Actually,you saved your TrialClass.java file inside C:\JavaFiles and you are trying to compile that file from C:\Documents and Settings\Administrator

There is two solution for your problem
1.Change your working directory to the directory in which your TrialClass.java file is present, in your case (C:\JavaFiles) and then compile it using javac
Example:


2.From any working directory you can compile your file,Just add the location of your file while passing as argument to javac,
Example:
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Actually, I think there might be another problem. Have you really installed your JDK in

c:\jdk1.6.0_01\bin

and set the path to

c:\1.6.0_01\bin

or was that a spelling error?
jignesh soni
Ranch Hand

Joined: Dec 10, 2007
Posts: 150
Thanks,
Its working now. I have questions about path variables.
What kind of variable is environment variable. I have given name "path" to the variable, can I give any other name for accessing c:\jdk1.6.0_01\bin say "road" instead of path or "path" is the only name I can use ?
When do I use classpath ? Do I have to set it up like path ? if yes, what will be the path for classpath ?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

'path' is used by the OS to know where to find binary (executable) files. I'm pretty sure the use of this is defined by the people who wrote your Operating System, so no, you can't really change it.

Generally, for beginners, it is recomended to NOT SET the classpath variable. this one is used by java to find class files. if it is not set, java defaults to the local directory from where the command is run. That means that once you create your .class files, you would simply run your "java <classname>" command from the directory where the .class files live.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
jignesh soni
Ranch Hand

Joined: Dec 10, 2007
Posts: 150
I dont think , I understood it well.
If "path" is key word defined by OS and I have to set path for another program. Now, if I compile a java program, how would it which path to take , as both the paths have same variable name ? Secondly, why system asks to set name of variable, if its preset in the system as keyword ?

Thanks
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

when you type in a command on the command line, your OS uses all the directories listed in the path variable. you'll have 5 or 10 or 30 directories in there. the OS says "hmmm... I need to run the XYZ binary. Is it in the first directory? no. Is it in the second? no. Is it in the third? no... " etc. It then eventually finds the binary/executable file, or gives you a "unknown command" error if it can't find it anywhere.

So, you don't substitute one value for another when you change your path, generally you just tack that new directory on the end.
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

Originally posted by jignesh soni:
I dont think , I understood it well.
...... why system asks to set name of variable, if its preset in the system as keyword ?

Thanks


I think fred answered your first question.

Here i will explain your second question answer
Generally when you install WINDOWS it automatically creates PATH environment variable and assigns with value "%SystemRoot%\system32;"

Here %SystemRoot% is your WINDOWS home directory(i.e.,)C:\WINDOWS or any other thing which the user specified while installing Windows.

When you are using Command Prompt you must specify where your EXE file is located.

The commands which you normally use like dir,cls,mkdir are inside that "%SystemRoot%\system32" directory only which makes it to execute without specifying its actual location.Likewise you must give your Java Home directory in the path variable which makes "javac" to be known irrespective of current working directory.

Hope you are clear now....
[ December 18, 2007: Message edited by: Balasubramanian Chandrasekaran ]
sandeep putta
Greenhorn

Joined: Dec 18, 2007
Posts: 3
HI There

From the information above, I come to know that by giving path in path variables (Is it the right term to use??), OS will know where to find its required binary files from �Path�.

First: What I want to conform is, when we run the command in the command prompt as "javac filename.java" I think OS will look for javac.dll in the bin folder and process the .java file to generate .class file. So when ever it encounters �javac� it will go to path variables and checks all the folders for javac.dll.

Secondly: about the �classpath�, you said it is used by java to find class files. If it is not set, java defaults to the local directory from where the command is run. My doubt is it is set then is it compulsory to set the path in the command prompt to run .class files

Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Welcome to the Ranch.

You are correct about "path" only it is called an "environment variable" in Windows. Yes, the OS goes through the path, starting with whichever folder it finds on the left, until it finds something which corresponds to javac (in your example). (I think it is actually called javac.exe in Windows.) If it never finds javac, then it says something like "unable to find javac," or, "bad command-javac not recognised." You have to set the PATH to find the java program or the javac program.

Then it goes through the classpath looking for "filename.java." If you have left the classpath unchanged, as Fred Rosenberger has already told you, it looks through whichever folder your command prompt window happens to be set at. If you look through the Windows classpath you will usually find ;.; somewhere. That means "current directory." As you said, javac creates a .class file, in whichever directory you have told it to (default: current directory).
Then when you invoke "java Something" the OS looks through the PATH to find java, then (?java) looks through the CLASSPATH (current directory) to find Something. As Fred Rosenberger has said, the classpath is usually set up before you start, so you leave the default settings unchanged.
sandeep putta
Greenhorn

Joined: Dec 18, 2007
Posts: 3
hi Ritchie. Thanks for the information, I have learned something new
I have one more DOUBT. There are several file extenctions like Jar, Dll, Exp, Template... and files with no extenctions in java setup. Can you please explain the difference in this extenctions. i have some knowledge about txt and Log extenctions, but have no idea on Dll and Exp.

tc
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Only too please to be able to help; sorry I haven't been able to reply earlier.

We use relatively few types of file in Java:
  • The source code files always use .java as their extension
  • The compiled class files have .class as their extension, but when you call "java Foo" you miss out the extension
  • You can put several .class files and other resources and a "manifest" file together to form a Java ARchive file, called a .jar
  • There are counterparts to .jar files for mobiule devices with extensions like .war.
  • And I have probably forgotten a few others!
  • Remember, it can seem a bit confusing but you call "javac Foo.java" and then "java Foo" without the .class extension.
    CR
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 36508
        
      16
    . . . and we don't usually use .dll or .exe files in Java.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: How to install jdk and set path variable?
     
    Similar Threads
    Problem working with eclipse
    Downloads and Classpath
    Installing Bea Studio Workshop
    cannot find [filename].java
    JDK Setup Problem