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?
You need to add $JAVA_HOME/bin to your path. You may want to update for version of java to.....
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
Thats me up and running. Cheers.
install java program set environment varible and one time path set the command prompt then execute javac
> 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.
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;
}
}
Yeah it looks like you need to upgrade to 1.5.xxx
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 >

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;
}
}
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
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();
}
}
}
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;
}
No problem glad to help :-)