These FAQ's are just how to get thing working on Ubuntu, not intros to the languages. The compiling of the sample programs are just to show it works (and a general howto)
My wiki is dedicated to learning, and those links are on it.
These FAQ's are just how to get thing working on Ubuntu, not intros to the languages. The compiling of the sample programs are just to show it works (and a general howto)
My wiki is dedicated to learning, and those links are on it.
We should also add some information abotu setting the CLASSPATH. That can be a major source of issues for newbies and experienced programmers alike.
There are several ways to do this and I am not sure which one is best really. I know the path is: /usr/lib/jdk1.6.0/bin
Any suggestions on which way to set the CLASSPATH.
javac *.java
This works
I've never had an IDE with interactive debugging and have had to rely on print statements to tell me where the program is executing and how variables values are changing.
For example: System.out.println("Here I am. x=" + x);
Often conditional using a boolean so I can turn the output on and off with a single statement change:To find out how a method is being called, I add the following statementin the method to print the call stack:Code:boolean debug = true; ... if(debug){ System.out.println("Here I am. x=" + x); }
You'll need the -g option on the javac compile to have the statement numbers in the code.Code:try{throw new Exception("who called");}catch(Exception ex) {ex.printStackTrace();}
If the method is called many times you may only want to see it once:
Code:boolean oneTime = true; .... if(oneTime) { oneTime = false; try{throw new Exception("who called");}catch(Exception ex) {ex.printStackTrace();} }
Finding NullPointerException in large program that doesn't have enough try{}catch blocks:
Copy the NullPointerException.java class from the source.zip file for your JDK and modify by adding:
Compile it and put the class file(s) in its own jar file. Prepend that jar file to the classpath for the java program using the -Xbootclasspath option:Code:// Insert our own special debugging version public String getMessage() { try{throw new Exception("Where am I");}catch(Exception ex){ex.printStackTrace();} return super.getMessage(); }
When you get a NullPointerException, your code will be called with its printStackTrace() showing who called.Code:java -Xbootclasspath/p:D:\JavaDevelopment\MyJavaClasses.jar -classpath .... ...
What is the "It" you refer to?It says that it is unable to locate 'tools.jar'.
I believe they're talking about DrJava. Here is what the quickstart guide has to say:
"To compile programs in DrJava, you must make sure you have a Java JDK (Java Development Kit) installed on your machine."
http://drjava.org/quickstartdocs/gettingready.html
To turtlepaul and vladislav:
That page talks about manually downloading and installing the Java SDK from Sun, but hopefully you can just use synaptic to install the sun-java6-jdk package.
Hopefully just installing the JDK package will get things working, but if not then the tools.jar preference mentioned at http://drjava.org/quickstartdocs/preferences.html may need to be set.
I found the tools.jar file and put the location in in the preferences, and it still doesn't work. It says it's incompatible.
Bookmarks