440,070 Members | 1,237 Online
Need help? Post your question and get tips & solutions from a community of 440,070 IT Pros & Developers. It's quick & easy.

 P: n/a Hi everyone, I recently installed the Sun J2SE SDK on my machine, and I am having trouble running the java.exe interpreter for my Java compiled code. I remember that I had to set my environment CLASSPATH variable to whatever the current directory is, but I forgot the exact characters to denote this. Or that there was an extra call to the java interpreter (like -cp or -classpath) to indicate the current directory, but that escapes me as well. Can anyone help? Thanks Jul 17 '05 #1
7 Replies

 P: n/a Herman, It might be that you're confusing the CLASSPATH environment variable with the PATH variable. The CLASSPATH should not contain any references to where the "java.exe" is located. This must be set in your PATH environment variable. Depending on which os you're on you can specify the jdk/bin directory in different ways, ie: Windows: ------------------------ Add a reference to the JDK bin directory in the PATH environment variable. From the command line (cmd) this can be done by issuing the following statement set PATH=%PATH%; To see what's in your path: echo %PATH% Setting the PATH environment can also be done by right-clicking the "My computer"-icon on your desktop, selecting properties from the pop-up menu. Click the "Advanced"-tab and select the "Environment variables"-button. the Path can be appended from this window. By doing it this way, the PATH environment will be set permanently as opposed to the method above where it will only be set locally for the command prompt shell. Linux: ------------------------ Set your PATH for the shell you're in by issuing the following statement: export $PATH=$PATH: To set the PATH more permanently for the logged in user, this depends upon what kind of command shell you're using. For bash you can include the above statements in the file ".user_profile" that is located on the user root directory (~username). Solaris: ------------------------ Manipulate the symbolic link /usr/java to point to the directory where the JDK is installed. This can be done by deleting the existing symbolic link and creating a new: delete /usr/java ln -s /usr/java : I'm sorry for "overanswering" your request, but this is something lots are troubled with, so I figured it wouldn't hurt with some details. -- Millian Brave "Herman" skrev i melding news:d6************************@posting.google.com ... Hi everyone, I recently installed the Sun J2SE SDK on my machine, and I am having trouble running the java.exe interpreter for my Java compiled code. I remember that I had to set my environment CLASSPATH variable to whatever the current directory is, but I forgot the exact characters to denote this. Or that there was an extra call to the java interpreter (like -cp or -classpath) to indicate the current directory, but that escapes me as well. Can anyone help? Thanks Jul 17 '05 #2

 P: n/a Hi Millan, I can run the java.exe fine from wherever I am. The only thing is, I get an exception when I run the program, called Exception in thread "main" java.lang.NoClassDefFoundError: Hello I believe that the CLASSPATH variable doesn't know where to look to find the .class file, but can't find it. How do I set CLASSPATH to the current directory? Thanks Jul 17 '05 #3

 P: n/a Hey guys, I figured it out, so don't bother with the Classpath question. Thanks anyway. Regarding another question, how do I check whether or not a String object is not null? For example, if (args[0].length() <= 0 || args[1].length() <= 0) { System.out.println("Need the name of input file as first parameter"); System.out.println("And name of output file as second parameter"); System.exit(0); } doesn't work. I get the following exception: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 When I pass no parameters. The String class doesn't have any IsEmpty methods like CString in Visual C++. What's the Java equivalent? Thanks Jul 17 '05 #4

 P: n/a Herman wrote: Hey guys, I figured it out, so don't bother with the Classpath question. Thanks anyway. Regarding another question, how do I check whether or not a String object is not null? For example, if (args[0].length() <= 0 || args[1].length() <= 0) { System.out.println("Need the name of input file as first parameter"); System.out.println("And name of output file as second parameter"); System.exit(0); } doesn't work. I get the following exception: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 When I pass no parameters. The String class doesn't have any IsEmpty methods like CString in Visual C++. What's the Java equivalent? Thanks To answer your question, the test you have above is fine to detect if a valid String reference is an empty string. To answer your next question, you can test if a String reference is valid by comparing it to the keyword "null": String myString = makeAStringOrReturnNull(); if (myString == null) { // error handling } else { // use myString } Now, that answers the questions you are asking. The real problem, however is that you are not asking the right questions. The actual problem is that the args array (argument to the main method) is zero-length. What you need to is check the length of the args array before using args[0] or args[1] like so: if (args.length < 2) { System.out.println("Need the name of input file as first parameter"); System.out.println("And name of output file as second parameter"); System.exit(0); } // Now you can check if the args are empty // If you are really paranoid, you can check for null, but I suspect // JVM wouldn't produce null arguments if (args[0] == null || args[0].length() == 0 || args[1] == null || args[1].length() == 0) { System.out.println("Need the name of input file as first parameter"); System.out.println("And name of output file as second parameter"); System.exit(0); } HTH, Ray Jul 17 '05 #5

 P: n/a If you really meant CLASSPATH, the period represents the current directory in both Windows and Unix. For example: Windows (backslashes and semicolons): CLASSPATH=c:\foo;.;c:\bar; Unix (slashes and colons): CLASSPATH=/foo:.:/bar; "Millian Brave" wrote in message news:f4******************************@news.teranew s.com... Herman, It might be that you're confusing the CLASSPATH environment variable with the PATH variable. The CLASSPATH should not contain any references to where the "java.exe" is located. This must be set in your PATH environment variable. Depending on which os you're on you can specify the jdk/bin directory in different ways, ie: Windows: ------------------------ Add a reference to the JDK bin directory in the PATH environment variable. From the command line (cmd) this can be done by issuing the following statement set PATH=%PATH%; To see what's in your path: echo %PATH% Setting the PATH environment can also be done by right-clicking the "My computer"-icon on your desktop, selecting properties from the pop-up menu. Click the "Advanced"-tab and select the "Environment variables"-button. the Path can be appended from this window. By doing it this way, the PATH environment will be set permanently as opposed to the method above where it will only be set locally for the command prompt shell. Linux: ------------------------ Set your PATH for the shell you're in by issuing the following statement: export $PATH=$PATH: To set the PATH more permanently for the logged in user, this depends upon what kind of command shell you're using. For bash you can include the above statements in the file ".user_profile" that is located on the user root directory (~username). Solaris: ------------------------ Manipulate the symbolic link /usr/java to point to the directory where the JDK is installed. This can be done by deleting the existing symbolic link and creating a new: delete /usr/java ln -s /usr/java : I'm sorry for "overanswering" your request, but this is something lots are troubled with, so I figured it wouldn't hurt with some details. -- Millian Brave "Herman" skrev i melding news:d6************************@posting.google.com ... Hi everyone, I recently installed the Sun J2SE SDK on my machine, and I am having trouble running the java.exe interpreter for my Java compiled code. I remember that I had to set my environment CLASSPATH variable to whatever the current directory is, but I forgot the exact characters to denote this. Or that there was an extra call to the java interpreter (like -cp or -classpath) to indicate the current directory, but that escapes me as well. Can anyone help? Thanks Jul 17 '05 #6

 P: n/a Thanks, Ray. I'm new to Java coming from C++, so that's why a lot of stuff I don't already know. Thanks again! Jul 17 '05 #7

 P: n/a To answer your question directly you can ask if( args[ 0 ] == null) .... But in this case, it's not the string that's null, it's the array that's empty. So you can check that with if( args.length == 0 ) .... Rich in article d6**************************@posting.google.com, Herman at he*******@hotmail.com wrote on 10/14/03 6:37 PM: Hey guys, I figured it out, so don't bother with the Classpath question. Thanks anyway. Regarding another question, how do I check whether or not a String object is not null? For example, if (args[0].length() <= 0 || args[1].length() <= 0) { System.out.println("Need the name of input file as first parameter"); System.out.println("And name of output file as second parameter"); System.exit(0); } doesn't work. I get the following exception: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 When I pass no parameters. The String class doesn't have any IsEmpty methods like CString in Visual C++. What's the Java equivalent? Thanks Jul 17 '05 #8

### This discussion thread is closed

Replies have been disabled for this discussion.