This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I am using teach yourself java by O'Neil and am going through some of their examples. The current problem I have is a socket example. It is compiling correctly, but the program is not running for me at all in netbeans 4.1 or in the command prompt. Any help is greatly appreciated.
It looks OK. You'd run the ServerSocketDemo, which will appear to do nothing, and then just leave it running. Now run the SocketDemo. It will contact the ServerSocketDemo, obtain a single random number, print it, and exit. When you run each program you need to supply a number as an argument; you must use the same number for each. "6543" is a personal favorite for this sort of program.
1) From the command prompt, use "cd" to make the current directory be the location of the ServerSocketDemo.class file.
java -cp . ServerSocketDemo 6543
3) Open a new command window, "cd" to the location of the SocketDemo.class file
java -cp . SocketDemo 6543
It should print a number, then quit.
Why are you having a problem? The short answer is that you've got the CLASSPATH environment variable set, and it doesn't include a "." for the current directory. See this document for more information; read the whole thing, including the linked document and the caveats about not relying on CLASSPATH too much! [ May 22, 2006: Message edited by: Ernest Friedman-Hill ]