• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JAVA kicking and screaming

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did a little programming in PASCAL and learned C++ enough to do loops and simple arrays - now trying JAVA but I need to be a DOS expert just to get the language to run. It seems some expertise in setting CLASSPATH and such is needed just to get Hello World to compile and run. My level of frustration is at the max! I downloaded latest JAVA from SUN --- bought a sample programs CD - and can't run a dern thing! I'm using TEXTPAD as my text editor = nothing compiles - even the professional examples--- so it must be my installation on a Win XP machine...... I'm ready to abandon all hope and return to C++ unless I can get 1 program to compile and run. Tmust be a better way to get started in this language. I can't image anyone standing for this in programs they buy -- what ever happened to the plug and play theory! Guess it doesn't apply to Java language...Hanging on by a thread......
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The classpath for the current versions of j2se is the dot (".") directory, ie, whatever directory you are in. You do need to deal with the path which tells the computer where to find your sdk bin so you can compile (with javac) and run (with java) your programs.

So I would start with this. What is the address of your sdk on your computer and what directory do you want to keep your source code in? On my xp the sdk is here: c:\sdk1.4.2 and the path I use is [c:\sdk1.4.2\bin] just what's inside the square brackets.

I do my code in [c:\jexp], a folder on the hard drive. I keep my source code and the compiled class files here.

To compile your code, at the command prompt [>] navigate to your java folder with [>cd c:\jexp] type enter and you should see [c:\jexp>]. We're in the folder. Put your HelloWorld source code file in here saved with a .java extension.

Now type in [c:\jexp>c:\sdk1.4.2\bin\javac helloworld.java] and enter. Your compiled .class file should appear in the same folder or errors explaining why not in the console.

Then type in [c:\jexp>c:\sdk1.4.2\bin\java HelloWorld] enter and you should be there - success.

After this you can set your path environment variable to save typing. And later you can set your classpath variable when you figure out what you want.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not really about it being complicate. It's just a matter of getting to execute the javac binary. javac is the responsible for compiling your program and transforming it into a bytecode.

You have to check where that binary is and after you do it once, you'll be able to run it more easily. Now, consider downloading Eclipse or NetBeans or some other IDE will which (I think) automatically detect those binaries without the need for you to set the CLASSPATH and PATH to the binaries.

Now, supposing your bin directory is in C:\j2sdk then to compile osmething you'd only need something like

 
Robert Crouch
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the advice - but I was able to edit my autoexic.bat file in WIN98 - but now that I'm using WIN XP- no dice. I can't even find the thing!
Textpad seems great - but each to their own. I can't begin to tell you how frustrating it is to read manuals - write programs - and learn that I can't even install the language right for the stuff to compile in the first place.
I have everything in C:\java
and want to store my original code programs in C:\java\myStuff
but I still can't get anything to comile - since I can't figure out how to let the computer find the java\bin. I may be hopeless ... if just getting the language to actually run is this hard - why bother with it?
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Robert Crouch:
Thanks for the advice - but I was able to edit my autoexic.bat file in WIN98 - but now that I'm using WIN XP- no dice. I can't even find the thing!
Textpad seems great - but each to their own. I can't begin to tell you how frustrating it is to read manuals - write programs - and learn that I can't even install the language right for the stuff to compile in the first place.
I have everything in C:\java
and want to store my original code programs in C:\java\myStuff
but I still can't get anything to comile - since I can't figure out how to let the computer find the java\bin. I may be hopeless ... if just getting the language to actually run is this hard - why bother with it?



Giving up is your choice. But on Windows XP you need to adjust your path so that you can run javac.exe and java.exe from anywhere you want. Otherwise you can just specify the absolute path. So let's begin with that, using the absolute path:

All you need to do at the command prompt is type in the entire path to your javac.exe and java.exe executables. So lets say you have java installed at c:\java and you are running programs in c:\programs. Here is the following command to compile a HelloWorld.java program. I will assume you are already in the c:\programs directory.

c:\java\bin\javac HelloWorld.java

Now let's run it.

c:\java\bin\java HelloWorld

Unless you are using specific 3rd party libraries that are not part of the standard JDK, there is no need to specify or adjust the CLASSPATH so for now, forget about the CLASSPATH. Pretend it doesn't exist.

For the other way we want to adjust our PATH environment variable so that we don't have to specify the absolute path. In Windows XP there are a few steps.

  • Right Click on the My Computer Icon and choose Properties
  • Click on the Advanced Tab
  • Click on the Environment Variables Button


  • At the top you will see user variables and the bottom are global variables. The easiest thing to do is find the PATH variable in the list of global variables and edit it. At the end put a ; and then assuming the same directory structure as above type c:\java\bin. Click OK, and the close all the dialogs that are open. If you had a DOS prompt up you may need to close it and re-open it for the changes to take affect.

    Now, all you have to type is:

    javac HelloWorld.java
    java HelloWorld

    If you do either of the ways I suggested and are still having problems you might want to tell us what errors you are getting. Ranting and raving about how mad and frustrated you are isn't going to help anyone. Take a deep breath and, well, breathe.

    Remember, the CLASSPATH isn't important right now.
     
    Robert Crouch
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Eureka--- I wiped everything out - downloaded fresh - right clicked on MyComuter- checked the Advanced tab - and the environment varibles- saw the class path as only being C:\java so I hade to edit it to be C"\java\jdk\bin and closed everything
    I ran textpad -- loaded a program - and it compiled and then ran ! I feel relieved - thanks for all the help -- and I have a feeling that I'm going to be a frequent visitor to the saloon--- what great friends I've found already. My goal is to become knowledgeable enough to one day help someone else! Thanks guys!
     
    Gregg Bolinger
    Ranch Hand
    Posts: 15304
    6
    Mac OS X IntelliJ IDE Chrome
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Robert Crouch:
    saw the class path as only being C:\java so I hade to edit it to be C"\java\jdk\bin...



    FYI - This is not the CLASSPATH. It's just the PATH to the Java bin directory. The CLASSPATH is used to tell the VM where to find libraries that are not part of the core set of libraries. You won't need to worry about this for a bit while you are picking up the basics. I just don't want you to become confused early on with termonolgy.

    CLASSPATH != PATH.
     
    Robert Crouch
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks once again -- and you're right--- although I can now compile and run elementary programs ... whenever I need to import -- no go! So now I have to set the classpath? Same place in WinXP - new line or add on to path line? Whatever details will be appreciated ( thankX ahed of time )
     
    Gregg Bolinger
    Ranch Hand
    Posts: 15304
    6
    Mac OS X IntelliJ IDE Chrome
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Robert Crouch:
    Thanks once again -- and you're right--- although I can now compile and run elementary programs ... whenever I need to import -- no go! So now I have to set the classpath? Same place in WinXP - new line or add on to path line? Whatever details will be appreciated ( thankX ahed of time )



    What do you mean "no go"? Are you getting compilation issues? Runtime issues? What classes are you importing?

    The best way to specify the classpath is at compile and runtime. Don't worry about setting environment variables for this. just use the -classpath switch on the executable. Example:

    javac -classpath extralib.jar HelloWorld.java
    java -classpath extralib.jar HelloWorld

    Where extralib.jar is the other libraries not included with the JDK. I find it hard to believe you are using extra libraries yet. You might also post your code.
     
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Just FYI

    If your not a command line person, under Windows XP the environment variables can be viewed from the System Properties window which can be found from My Computers -> Properties -> Advanced Tab. On the bottom select Environment Variables and you will be able to set and view User and machine defined information.

    Sal
     
    reply
      Bookmark Topic Watch Topic
    • New Topic