A very basic newbie question on Java
:confused: I've purchased "The Java Tutorial, Third Edition" . It was written for the j2sdk1.3 compiler. Iv'e downloaded j2sdk1.4_05 into FC2. Will the newer compiler not always work with the examples in the book? I'm working on a example called "CreateObjectDemo" that
creates a rectangle. The code: Point origin_one = new Point(23, 94); Rectangle rect_one = new Rectangle(origin_one, 100, 200); Rectangle rect_two = new Rectangle(50, 100); When I run javac the compiler gives me an error message that states: "cannot resolve symbol" It points to each Point and each Rectangle for 6 errors. Here's the whole program: public class CreateObjectDemo { public static void main(String[] args) { // Declare and create a point object and two rectangle objects Point origin_one = new Point(23, 94); Rectangle rect_one = new Rectangle(origin_one, 100, 200); Rectangle rect_two = new Rectangle(50, 100); // Display rect_one's width, height, and area System.out.println("Width of rect_one: " + rect_one.width); System.out.println("Height of rect_one: " + rect_one.height); System.out.println("Area of rect_one: " + rect_one.area()); // Set rect_two's position rect_two.origin = origin_one; // Display rect_two's position System.out.println("X Position of rect_two: " + rect_two.origin.x); System.out.println("Y Position of rect_two: " + rect_two.origin.y); // Move rect_two and display its new position rect_two.move(40, 72); System.out.println("X Position of rect_two: " + rect_two.origin.x); System.out.println("Y Position of rect_two: " + rect_two.origin.y); } } I guess I just need to know if I should use j2sdk1.3. It's on the disk that came with the book. The compilers are not backward compatible? Sorry for the dumb newbie problem. Thanks in advance -- Larry |
i believe java is backwards compatible, so you should be OK. at least, right now, your problem is not compatibility; it seems to be something simpler:
does the example show you how to write the Point and Rectangle classes, too? if so, put the java files for those 2 classes in the same directory where the java file for your CreateObjectDemo class is. otherwise, they are library classes, and from the jdk1.4.2 api at http://java.sun.com/j2se/1.4.2/docs/api/index.html, you need to add the following lines to the beginning of the CreateObjectDemo file. Code:
import java.awt.Point; |
:D Many thanks rgiggs, You were right. I didn't have to import , I had to make a Point and a Rectangle class. The book is a little confusing.
One other quick question if I may? I notice your'e using slack 10? I burned a copy the other day. Are the alsa utils, etc, etc now available? I was browsing somewhere and they were complaining that everything was still for 9.1 Thanks for the reply -- Larry |
Quote:
|
Eclipse is a good IDE for Java. You can easily determine and correct errors and exceptions.
|
Quote:
|
All times are GMT -5. The time now is 03:59 AM. |