Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Installing j2sdk 1.4.2_09 on XP

Status
Not open for further replies.

rodwf

MIS
Sep 20, 2005
85
CA
I'm just starting to learn java at uni and so thought i'd install the J2SDK 1.4.2_09 from the sun website. the file downloaded but when i install it the default path the folder is empty. Is there something i'm doing wrong? is there somewhere else i can download the file from?
 
Ok, found out my problem, i downloaded again and i now have it installed, probably a corrupt download.
 
Memo to rodwf:
I had problems downloading the same program, so after I found a solution to all my problems, I made "an instruction sheet" and this might be of help if you encounter another problem.

Here it is:

Java Instructions-Classpath+Run-Sep.15.05
File \\586\E\Data\Java4+5\*.*
Charles Keller – For Win98 and Win-XP
----------------------------------------------------
1. Setting your PATH & Classpath:
To successfully set your PATH & SET CLASSPATH in your Autoexec.bat file, using Notepad
“Autoexec.bat” (using quotes), you have to enter them as follows:

SET PATH=%PATH%;C:\;C:\Windows\Command;C:\J2SDK1.5.2.09\bin;
(Your exact Java program name, like “J2SDK1.5.2_09” or “SDK1.5.0_04” must be included in your PATH, you also have to add “bin” to it).

SET CLASSPATH=C:\Java-CK (or wherever your *.java files resides)
Your folder name can be anything you wish, like C:\> Java-Program or C:\> J-Program

2. To activate your new settings in the Autoexec.bat file:
a) Go to C:>
b) at C:> Type “c:autoexec.bat”, without the quotes and <press Enter>


3. To create your Java Program:
Go to NetBeans IDE (free from SUN Developer Network)
or any other Java Programming Editors, like GEL IDE, Jcreator or Jedit:
and create your *.java program like this:

//: File: C:\Java-CK\HelloDate.java
import java.util.*;

/** Java example program.
* Displays a string and today's date.
*/
public class HelloDate {
/** Sole entry point to class & application
* @param args array of string arguments
* @return No return value
* @exception exceptions No exceptions thrown
*/
public static void main(String[] args) {
System.out.println("Hello, it's: ");
System.out.println(new Date());
}
} ///:~

Go to page 2
------------------------------------



Page 2


4. To create your *.CLASS file:
a. Go to a DOS-Win Box
b. at C:> type “CD Java-CK”, without the quotes, press <Enter>
c. at C:\Java-CK> type “javac HelloDate.java”, without the quotes, <press Enter>
and your HelloDate.class will be created under C:\Java-CK\*.*
The JAVAC compiler will create your *.class file and put it in the same folder
where your HelloDate.java resides.

JAVAC stands for compiler and the computer converts the text in “HelloDate.java” into a machine language that the computer can understand, which are only Ø and 1, like 1Ø1Ø11Ø11Ø.
If the binary notation in the machine language is: 1Ø1Ø1111ØØ it means decimal number: 700
5. To RUN your HelloDate program:
d. Go to a DOS-Win Box
e. at C:\> type “CD Java-CK”. without the quotes, press <Enter>
f. at C:\Java-CK> type “java HelloDate”, without the quotes, press <Enter>
g. and your java program will run like this:
h. Hello, it’s:
Thu Sep 15,21:25:41 PDT 2005.

5. Capitalization in Java:
The Java language is very much “case sensitive”.
If your class is “HelloDate” and you type “java hellodate”, it will not work.

------ End.


 
Hello cgkeller,

Thank you for the info as it did come in very handy, i'm now able to compile my program but i do have a problem when running it. I changed directory as stated to where my *.class file is (cd c:\src) and typed out java myfirstjavaprog,unfortunetly that came with the error:
exception in thread "main" java.lang.NoClassDefFoundError: myfirstjavaprog. I did try it with the .class extension and got the same error message.
I've put the java programs folder path (c:\src) in the 'classpath' within the enviroment variables and the j2sdk1.4.2_09 folder path (c:\j2sdk1.4.2_09\bin)into 'path' which i believe i should have done.

Here's the simple program i created:

class myfirstjavaprog
{
public static void main(String args[])
{
System.out.println("Hello World");
}
}


If yourself or anyone can enlighten me as to what went wrong i'd very much apreciate it.

Rodwf
 
The CLASSPATH variable is not automatically picked by the JVM. Just tell it do do with

Code:
java -classpath %CLASSPATH% myfirstjavaprog

Btw, by convention, Java classes use to start with a capital letter (MyFirstJavaProg)

Cheers,
Dian
 
Thanks for the reply Dian,

Am i to understand that i have to enter java -classpath %classpath% myfirstjavaprog in a dos shell or to the classpath?
 
Dian,
The CLASSPATH environment variable is picked up by the JVM automatically ...

If you did :

set CLASSPATH=C:\where_my_class_file_is

then :

java MyProgramme

then it would work fine, picking up the CLASSPATH env var.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Well, if that were true, then

Code:
java Myclass
and
Code:
java -classpath %CLASSPATH% Myclass

should have identical results. Isn't it?

Cheers,
Dian
 
ok, i found what i done wrong, In the 'path' i didn't use the'.' after the folder path, i had entered c:\j2sdk1.4.2_09\bin;c:\j2sdk1.4.2_09\jre; no '.' so i added the '.' and it now works.
 
Btw, rodf, here's a link where you can find a explanation of how classpath works:
It works as sedj said, including the classpath variable automatically.

My experience says it doesn't always work that way, specially if you're using window and the set command to set classpath.

The right way to go, in my opinion is sedj's one. You should have no problems if you follow his instruction. If you still have them, try my way.

Cheers,
Dian
 
thanks for the info, much appreciated. There two things i don't follow though, The 'java MyProgramme'and the 'java -classpath %CLASSPATH% myfirstjavaprog', i don't understand where they come in!.

I've entered the classpath c:\j2sdk1.4.2_09\bin.;c:\j2sdk1.4.2_09\jre; and the path c:\src .

Are 'java Mprogramme' and 'java -classpath %CLASSPATH% myfirstjavaprog' entered into notepad and saved as a .bat file then ran? or is one supposed to add these entries into path or
classpath?
 
Ok, let's clarify it:

PATH: environment variable where the OS will look for executable files like java.exe. You should include here the directory where java.exe is

CLASSPATH: environment variable where Java will look for .class files. You should include here c:\src.

After that, in the command line, you should execute java <Your Class Name> or use a bat.

Cheers,
Dian

 

Cheers Dian, all's fine now. Thanks for the clarification.
 
You're wellcome, but this time I was one that added confusion to a pretty clear issue.

The problem is that today I'm experiencing a lot of problems with paths and classpaths and took this thread out of its original scope.

Cheers,
Dian
 
Now i'm going to install JDK1.5.0_05, then netbeans and then jre1.5.0_05.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top