Java Installation Problems

I'm trying to get Java going on my machine but am having no joy. I have version J2SDK1.4.2_06. This is installed to C:\j2sdk1.4.2_06 andis appearing in my Add And Remove Programs. I then went into Environment Variables and entered 'JAVA_HOME' as the variable and 'C:\j2sdk1.4.2_06\bin' as the variable value in the user variables. However if I use cmd to navigate to a folder containing a java program and use the javac command I get the following error:

'javac' is not recognised as an internal or external command, operable program or batch file.

Can anybody suggest what the problem might be? Should I set the class path in the System Variables rather than the User Variables?

[707 byte] By [paul_carrona] at [2007-11-27 9:00:25]
# 1
You need to add $JAVA_HOME/bin to your path. You may want to update for version of java to.....
ita6cgra at 2007-7-12 21:29:02 > top of Java-index,Java Essentials,New To Java...
# 2
When you add JAVA_HOME to your PATH enviornment variable, here is a more complete example:JAVA_HOME= C:\j2sdk1.4.2_06PATH= C:\\bin;%JAVA_HOME%\lib;%JAVA_HOME%\bin;%JAVA_HOME%\lib\tools.jar
George123a at 2007-7-12 21:29:02 > top of Java-index,Java Essentials,New To Java...
# 3
Thats me up and running. Cheers.
paul_carrona at 2007-7-12 21:29:02 > top of Java-index,Java Essentials,New To Java...
# 4
No problem :-)
ita6cgra at 2007-7-12 21:29:02 > top of Java-index,Java Essentials,New To Java...
# 5
install java program set environment varible and one time path set the command prompt then execute javac
sij17tada at 2007-7-12 21:29:02 > top of Java-index,Java Essentials,New To Java...
# 6
> install java program > > set environment varible and one time path set the> command prompt > > then execute javacMethinks you are a tad to late... At least according to:>Thats me up and running. Cheers.
ita6cgra at 2007-7-12 21:29:02 > top of Java-index,Java Essentials,New To Java...
# 7

Another one for yous:

I have eclipse. Got it up and running. Everything seemed fine until I tried to run a program and got the following in my consol:

java.lang.Error: Unresolved compilation problem:

Syntax error, 'for each' statements are only available if source level is 5.0

at FindLatestFile.getLatest(FindLatestFile.java:13)

at FindLatestFile.main(FindLatestFile.java:25)

Exception in thread "main"

Im running j2sdk1.4.2_06. Is this telling me I need to upgrade to 5? Seems to be coming from:

for (File f : fileList) {

if (f.lastModified() > latestModDate) {

latestModDate = f.lastModified();

latestFile = f;

}

}

paul_carrona at 2007-7-12 21:29:02 > top of Java-index,Java Essentials,New To Java...
# 8
Yeah it looks like you need to upgrade to 1.5.xxx
ita6cgra at 2007-7-12 21:29:02 > top of Java-index,Java Essentials,New To Java...
# 9
That means that 'for each' statement is available in java 1.5 and higher.But you have told us you are running j2sdk1.4.2_06 (java 1.4)Switch in eclipse java compilator to use java 1.5
m00dya at 2007-7-12 21:29:02 > top of Java-index,Java Essentials,New To Java...
# 10

Well for the time being I cant get upgraded(Dont ask! Work are not into advancing with technology. In fact rpg3 is still used here!!!).

Anyway. Can anybody tell me how this would be rewritten so that it will compile with 1.4:

for (File f : fileList) {

if (f.lastModified() > latestModDate) {

latestModDate = f.lastModified();

latestFile = f;

}

}

paul_carrona at 2007-7-12 21:29:02 > top of Java-index,Java Essentials,New To Java...
# 11

Need a little bit more of your code. But the basics are :

for(int i=0; i < fileList.size(); i++){

file = fileList.get(i);

if (file.lastModified() > latestModDate) {

latestModDate = file.lastModified();

latestFile = file;

}

This is assuming you are using a List for your fileList variable

ita6cgra at 2007-7-12 21:29:02 > top of Java-index,Java Essentials,New To Java...
# 12

Here you go.Cant take credit for it as its not my work. Im just playing around with this as its similar to what I want to do in a program I am writing.

import java.io.File;

public class FindLatestFile {

public static File getLatest(File thisDir) throws Exception {

long latestModDate = -1;

File latestFile = null;

if (!thisDir.isDirectory()) {

throw new Exception("Please pass in a directory.");

}

File[] fileList = thisDir.listFiles();

for (File f : fileList) {

if (f.lastModified() > latestModDate) {

latestModDate = f.lastModified();

latestFile = f;

}

}

return latestFile;

}

public static void main(String[] args) {

try {

System.out.println("The latest file in the current directory is " +

getLatest( new File(System.getProperty("user.dir") ) ) + ".");

} catch (Exception e) {

e.printStackTrace();

}

}

}

paul_carrona at 2007-7-12 21:29:02 > top of Java-index,Java Essentials,New To Java...
# 13

Ok so similar to my previous post see below:

for(int i=0; i < fileList.length; i++){//use fileList.length

file = fileList[i]; // get file from array

if (file.lastModified() > latestModDate) {

latestModDate = file.lastModified();

latestFile = file;

}

ita6cgra at 2007-7-12 21:29:02 > top of Java-index,Java Essentials,New To Java...
# 14
Cheers. Thats spot on!
paul_carrona at 2007-7-12 21:29:02 > top of Java-index,Java Essentials,New To Java...
# 15
No problem glad to help :-)
ita6cgra at 2007-7-21 22:52:11 > top of Java-index,Java Essentials,New To Java...