Archived

This topic is now archived and is closed to further replies.

[java] Small Gap

This topic is 5177 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a small question I have come across with my new exploration, Java. I am coming across not having the command "javac" when I try to compile my work. My teacher blew me off and told me to use a different version of DOS because she was busy. What do I need to do? Its probably simple, but after a weekend like mine, thoughts come hard. Close your eyes, and die in the dark...

Share this post


Link to post
Share on other sites
Add your java directory to your path (you can set that in autoexec.bat if you''re using DOS, though I have no idea why you would be using DOS).

Share this post


Link to post
Share on other sites
Im new? but not completeley ignorant. What would you suggest using? I am following a cisco curriculm that has a complete course of java and I am doing what it says. If there is an easier method I am all ears...

Share this post


Link to post
Share on other sites
Your system has what''s called a path. Which is just a list of directories. Whenever you type in a command, the system will look in each directory in the path to see if they contain a program by that name, if so it will run it. Otherwise it will claim the program doesn''t exist. javac''s directory is (for some reason) not added to the path when you install java.

If you''re using Windows 95/98:
1) start menu->find, type in javac. Figure out where javac is. If it doesn''t turn up, you didn''t install the JDK. It should be in a directory something like C:\j2sdk1.4.2\bin

2) open up C:\autoexec.bat in notepad. You will probably find a line like

SET PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;

just add on that directory you found

SET PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\j2sdk1.4.2\bin;

reboot and you''re good to go.

if you''re using WindowsNT/2000/XP
1) find javac, start menu->search.

2) right click on My Computer. Select properties. Select the "Advanced" tab. Find the "Environment Variables" button (slightly different location for each OS).

3) click on it, up pops a window. In the system variables section should be Path. Edit it and change it just like above. No need to reboot but you will need to use a new dos shell if you''ve got one open.

Share this post


Link to post
Share on other sites
By DOS do you mean the cmd window? Because that window is really only a DOS emulator -- or you might call it a DOS-Shell, but its really not nearly on the level of a shell. Is that what you mean by DOS?

If so you have to set the CLASSPATH environmental variable -- and doing that depends on which version of Windows you are using.

In win2k and above you can do that from the My Computer Icon -> properties -> advanced settings tab -> environmental variables. And there you can set CLASSPATH. In anything below win2k and you have to edit the autoexec.bat manually ( more or less.) And I don''t remember how to do that ''exactly.'' Sorry.

Share this post


Link to post
Share on other sites
This has nothing to do with the classpath. Not to mention the classpath environment variable should rarely, if ever, be set (not to mention he'd have no idea what to set it to). This is a system path issue, as I outlined in great detail in the post just directly above yours.

And of course he means cmd or command, Java does not exist for DOS.


[edited by - tortoise on October 13, 2003 1:50:54 PM]

Share this post


Link to post
Share on other sites
Setting the CLASSPATH is how I learned. And secondly I wasn''t trying to overwrite your post -- we posted nearly at the same time. And you are right i didn''t even say what to set the path to. Oh well.

By the way, what do you mean by rarely? How else does the JVM locate your .class files? Just curious -- I''m no pro-java anything.

And yeah I had a feeling he meant cmd window -- and I was trying to shed some light on the fact that it isn''t DOS...

Is everyone in a pissy mood this week or what?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
No, it''s just that setting a classpath is a really bad idea, in general. It causes all kinds things to break for beginners who don''t know why everything''s breaking.

As for how the compiler and JVM find the classes... They find them either in the bootclasspath (relative to the location of the .exe''s, by default, unless you override it), or relative to where the command was executed from (current directory, or subdirectories according to package name). Or at least since 1.2, that''s how it''s worked. Previous versions of the JVM were broken.

Unless you know why you''d want to change the classpath, you shouldn''t.

Share this post


Link to post
Share on other sites
Ok, guys, what is the prefered method?

Close your eyes, and die in the dark...


NVM. I got it. Thanks guys. Happy programming...

[edited by - x3verge on October 14, 2003 10:01:35 AM]

Share this post


Link to post
Share on other sites
For development, use Ant and/or a good IDE. They will handle classpath issues nicely. If you''re developing something small without third party libraries, then the classpath shouldn''t become an issue.

For running a Java program, there''s several methods that avoid the classpath environment variable:

--Jar manifests, this is the best way to go for jar based apps.

--Ant again, not quite ideal in this environment but will launch an app with perfect classpath settings.

--For big, commercial type programs, something like Install Anywhere is the way to go.

--WebStart. If you''re going to distribute your app from the web, mine as well launch it cleanly from the web too. Webstart handles all the icky issues associated with Java for the end user, and they can easily "install" your program as permanent if they like it, or get rid of it if they don''t.

--For little things, shell scripts work well. The script will be like 2 or 3 lines long and easily adapted to Unix (including MacOSX) or Windows Batch files.

The classpath variable just causes problems. Many apps bundle in their own libraries (like most apps have their own log4j jar). If you also have a different version of log4j in your classpath, then that program will launch with a version of log4j it''s not aware of. This can lead to many problems (most likely being NoSuchMethod and ClassCastException errors). There are other problems that can arise too. Just generally one master classpath for all Java programs doesn''t work.

Share this post


Link to post
Share on other sites
Look into JBuilder as an IDE. Their personal version is free and you can use it for commercial purposes as long as you are a single developer.



First make it work,
then make it fast.

--Brian Kernighan

The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)

Do not interrupt your enemy when he is making a mistake. - Napolean Bonaparte

Share this post


Link to post
Share on other sites