• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting Started with Java and OS X  RSS feed

 
gary hein
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As an oldster trying to lean enough Java to make a web based application for analysis of archaeomag data, I need some help in getting going. I can find more information than I need about Java as a language.

In the sixties and seventies I did real time assembly and Fortan applications so I have some idea of what I am tryig to do. I even have a small spec I wrote to guide the developenmt of the application I want.

I can't find enough information to use my Mac to make any of the samples I found do more than make error messages.

I am using TERMINAL and the text editor on my OS X (10.4.1) system.

I took the ShowShapes code from the code barn. They all compile with a similar error.

RALurker:~ ghein$ javac /users/ghein/ajava/Cirle.java
/users/ghein/ajava/Cirle.java:4: class Circle is public, should be declared in a file named Circle.java
public class Circle implements Shape
^
1 error

RALurker:~ ghein$ javac /users/ghein/ajava/box.java
/users/ghein/ajava/box.java:3: Box is not abstract and does not override abstract method getPathIterator(java.awt.geom.AffineTransform,double) in java.awt.Shape
public class Box implements Shape
^
1 error

RALurker:~ ghein$ javac /users/ghein/ajava/Shape.java

RALurker:~ ghein$ javac /users/ghein/ajava/box.java
/users/ghein/ajava/box.java:3: Box is not abstract and does not override abstract method getPathIterator(java.awt.geom.AffineTransform,double) in java.awt.Shape
public class Box implements Shape
^
1 error

RALurker:~ ghein$ javac /users/ghein/ajava/Poly.java
/users/ghein/ajava/Poly.java:3: Poly is not abstract and does not override abstract method getPathIterator(java.awt.geom.AffineTransform,double) in java.awt.Shape
public class Poly implements Shape
^
1 error

The question for you all is what am I doing wrong?

I have been reading "Head First Java" and getting error with thier first two examples.

It seems foolish to proceed until I can get the simple examples to work.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi gary, welcome to the Ranch.

Your questions are basic Java concepts and are not specific to your use of OS X as a platform (great choice, by the way). So I'm going to move this along to our Java in General (beginner) forum where it will get more exposure.

See ya there!

bear
Forum bartender
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With regards to your first error:



Indeed, a class named Circle must be in a file with the same name. You apparently typoed and named the file Cirle.java. Close, but computers are just so darned picky about these kinds of things.

Fix that one up and see how much further along that gets you.
 
gary hein
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the spelling in the text of the example. What about the others gettin the same error?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you implement an interface on your class there are methods that must be overridden. That is what those other messages mean. So...

public class Box implements Shape

Your Box class needs a method:

getPathIterator(java.awt.geom.AffineTransform,double)

The message is there because you have no such method in your Box class. Same with the other classes with similar error messages.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg's right, but...

Gary is only accidentally implementing the "java.awt.Shape" interface. He's actually trying to implement a "Shape" interface that's part of this simple example.

OK. Let's see if we can get this under control.

First, rename every source file so its name is identical to the name of the class it contains, including capitalization. So box.java -> Box.java .

Second, recognize that Java ascribes a certain level of meaning to directory hierarchies and paths. Your main problem here is that when you're compiling, say, Circle.java, the compiler needs to find Shape.java, but it doesn't know where to find it; so it's using a system class named Shape instead, which is not what you want.

So...

% cd /users/ghein/ajava/
% javac -classpath . -d . *.java

Now if you didn't see any errors, congratulations, it worked!
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi gary,

I've just tested this on a Mac running OS 10.4.1 with Java 5.0. I think your only problem is remembering that Java is case-sensitive. And whenever you have a public class (or interface) defined in a .java source file, then that .java file must share the same case-sensitive name as the public class (or interface)...
  • Box.java
  • Circle.java (yes, there's a typo in the example)
  • Poly.java
  • Shape.java
  • ShowShapes.java
  • Once these are compiled, run the program by typing...

    java ShowShapes

    Note that you do not type the .class extension with the java command. Also note that ShowShapes is the "entry point" for this program because it contains the main method.

    (Also, note that the "close" button on the window is not programmed to work. So to close this example, you will need to return to the Terminal prompt and type Ctrl+C.)
    [ July 02, 2005: Message edited by: marc weber ]
     
    Layne Lund
    Ranch Hand
    Posts: 3061
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by gary hein:
    That is the spelling in the text of the example. What about the others gettin the same error?



    Welcome to the Ranch, gary. I just have a few general comments if you don't mind:

    When I am trying to fix compiler errors, I usually just focus on one at a time. In my programming career (new as it may be), one problem in the source code can cause multiple errors down the line. I typically find that fixing the first error often causes a different list of errors the next time I compile.

    Also, as you can see the error messages usually give you a really good clue about what the problem is. I hope the hints here have helped you understand that enough so you can try to figure out the errors on your own next time. Of course, if you can't, please keep coming back with the error messages and we will describe what might be causing them.

    I hope you enjoy learning Java. Good luck with it and keep coming back with questions.

    Regards,

    Layne
     
    gary hein
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks to all of you.

    The KEY advice was the need to work out of the directory where the source files are located. That one suggestion gets the rank beginner,me, going so he can discover the case sensative a problem solving, missing method, etc.

    I will be back from time to time as I work my way through Head First Java. I hope my questions get more interesting.

    Thanks again
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!