
-----------------------------------
peanut
Fri Apr 14, 2006 8:45 am

Java on mac
-----------------------------------
Hey guys, I'm doing some classes of Java programming in my university. And I work on a mac at home. From the university I got a element package with some classes that I need to use from my programming. I'm using right now xcode for mac, and well my question is how do I import the classes? I tried javac -classpath  but it doesnt seems to work.

Thx

-----------------------------------
wtd
Fri Apr 14, 2006 11:52 am


-----------------------------------
Can you place the classes in the existing classpath (as specified by the CLASSPATH variable that I'm assumign exists)?

-----------------------------------
peanut
Fri Apr 14, 2006 12:51 pm


-----------------------------------
well I must say that I'm totally new with computer language. Java is actually  my first computer language that I'm learning. I read that I can put the element that I'm trying to load in each file, or load it in my classpath. However don't know what's my classpath.

-----------------------------------
wtd
Fri Apr 14, 2006 1:53 pm


-----------------------------------
Your classpath is where Java looks for classes.  

Let's say I have a Java source file Test.java in my home folder (~):

public class Test {
   public static void main(String[] args) {
      Foo f = new Foo();
   }
}

Now, I have Foo.java in ~/projects/java/

public class Foo { }

When I compile Test.java from the commandline...

~ $ javac -classpath projects/java Test.java

And then to run it:

~$ java -classpath .;projects/java Test

-----------------------------------
peanut
Fri Apr 14, 2006 2:29 pm


-----------------------------------
Yes I understand that, I don't use the terminal though to compile or execute the program. I'm using xcode, and well my question was more for the import of classes.

Example:

import element.*;

public class Assignment1
{
         public static void main (String args[])
          {
                 ConsoleWindow = new ConsoleWindow();
                 
                  System.out.println("ConsoleWindow");
           }
}


And the ConsoleWindow class has been put in the element package that I got from school (element.jar). Now I don't know how to import this file.

-----------------------------------
wtd
Fri Apr 14, 2006 2:33 pm


-----------------------------------
For simple projects, you will likely find the command-line a simpler working environment than Xcode (or most other IDEs).

-----------------------------------
wtd
Fri Apr 14, 2006 2:36 pm


-----------------------------------
As for using a JAR archive "element.jar" with classpath:

javac -classpath /path/to/element MyClass.java

Hopefully I'm remembering that correctly.

-----------------------------------
rizzix
Fri Apr 14, 2006 4:24 pm


-----------------------------------
Or simply drop the jar in /Library/Java/Extensions

-----------------------------------
peanut
Sat Apr 15, 2006 6:45 am


-----------------------------------
Thank you guys! :) I got it working.

-----------------------------------
Justin_
Sat Apr 15, 2006 7:04 pm


-----------------------------------
So you have no previous experience with programming and you're taking it in university?  Is computer science your major?  I'm not trying to sound pejorative, but it seems ridiculous that somebody would study CS in university and not have a background in the subject.  I mean, who pays money to learn about something they aren't familiar with?  Won't it be a waste of money if you find out you don't like it?

-----------------------------------
wtd
Sat Apr 15, 2006 7:17 pm


-----------------------------------
One goes to a university to learn what's available.  The vast majority of students will change their major at least once.  A good portion of those will change majors three or more times.

-----------------------------------
peanut
Sun Apr 16, 2006 10:11 am


-----------------------------------
Actually I'm studying Aerospace Engineering. And a subject that I get is JAVA programming. Somehow (in the near future), I'm going to use then my skills, that I'm learning now with JAVA, to program some things. What I know, is that next year I will be programing a flight simulator as a project  :D .

-----------------------------------
md
Sun Apr 16, 2006 9:21 pm


-----------------------------------
I know a whole lot more about CS then many people here; and yet I've decided to switch out of CS. Clearly what you study has little to do with what you know and more to do with what interests you. I know lots of people who knew very little or nothing about programming who are in CS now, and many people who knew lots about CS who are no longer in it after a year or two of it at university.

-----------------------------------
peanut
Sun Apr 16, 2006 10:18 pm


-----------------------------------
lol, well yes, I am really interested in Java atm and I'm going to learn it on my free time, even if, at my university, we only learn the basics.

-----------------------------------
wtd
Mon Apr 17, 2006 11:04 am


-----------------------------------
I'd suggst you look into other languages as well.  There are other languages that are easier and possibly more fun to experiment with, and Java as a language is pretty mundane.  :)

Oh, and good luck in your academic endeavors.

-----------------------------------
peanut
Mon Apr 17, 2006 11:17 am


-----------------------------------
thank you  :D , I will try another languages as well, do you have any tips on what languages I should check out?

-----------------------------------
wtd
Mon Apr 17, 2006 11:32 am


-----------------------------------
I'm a big fan of Ruby, and that certainly has gotten a lot of attention lately.  Blocks alone would be quite an eye-opener.

A fucntional language would also provide quite the contrast to Java and expose you to a lot of new concepts.  I firmly believe, by the way, that learning other languages, even if you eventually go back to something like Java, will make you a better programmer and benefit you regardless of the language you end up using most of the time.

For fucntional programming languages, Haskell is really interesting, but you would probably find that O'Caml offers a more gentle introduction.

-----------------------------------
wtd
Tue Apr 18, 2006 4:58 pm


-----------------------------------
Oh, additionally... you should check out Scala (http://scala.epfl.ch).  It permits use of java's vast libraries, and incorporates a lot of neat features.
