Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

FocusAndEarnIt

macrumors 601
Original poster
May 29, 2005
4,624
1,063
Ok, so I have programmed NOTHING, I want to learn, I just got a book from my neighbor, it's Core JAVA 2 Fudamentals.

He's a busy programmer, and I finally caught him. :p

So he gave me this book and... I have Xcode installed on my iBook (in sig) and I know very little about Terminal

Any suggestions on where to start, and tips?
Help please
 

Nutter

macrumors 6502
Mar 31, 2005
432
0
London, England

WebMongol

macrumors member
Sep 19, 2004
50
0
Bay Area, CA
lilstewart92 said:
Ok, so I have programmed NOTHING, I want to learn, I just got a book from my neighbor, it's Core JAVA 2 Fudamentals.

He's a busy programmer, and I finally caught him. :p

So he gave me this book and... I have Xcode installed on my iBook (in sig) and I know very little about Terminal

Any suggestions on where to start, and tips?
Help please

If you want to learn Java all you need is a text editor, tutorial and a lot of time.
For programming editor I recommend TextWrangler (it's free).
Later you can try something more sophisticated, like vim or emacs.

Or you can start with simpler, easier to learn and fun language, like Python.
There is a number of free online tutorials to learn Python:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
Python has an interactive mode so you even do not need editor.
In Terminal type /usr/bin/python and you are redy to write your first
Python code:

mac:~/$ /usr/bin/python
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> # Python Hello world
... print "Hello, World"
Hello, World
>>> # loop:
... for i in range(5): print "Hello, World", i
...
Hello, World 0
Hello, World 1
Hello, World 2
Hello, World 3
Hello, World 4
>>>

Terminal is in /Applications/Utilities directory.

Following 4-line Python code that downloads a content of ww.yahoo.com root page, counts number of bytes, words and lines, and writes it into file - 'web.html':

>>> import urllib
>>> doc = urllib.urlopen("http://www.yahoo.com/").read()
>>> print len(doc), len (doc.split()), len (doc.split('\n'))
37230 2626 611
>>> open('web.html', 'w').write(doc)

# back to shell: count number of lines, words and bytes in web.html file
# and open the file in web browser:

mac:~/$ wc web.html
610 2626 37230 web.doc
mac:~/$ open web.html

Try to do the same in Java or Objective-C and you'll see the difference.


Good luck.
 

greatdevourer

macrumors 68000
Aug 5, 2005
1,996
0
Just to get to grips with the whole bug-find, syntax-error thing, I'd recommend AppleScript (macscripter.net). You can do some pretty cool stuff with it, nothing too powerful, but the 'do shell script' command helps (it allows you to do UNIX commands within the program). Plus, it'll be 100% compat with the x86 boxes without a recompile
 

FocusAndEarnIt

macrumors 601
Original poster
May 29, 2005
4,624
1,063
Thanks for all the info guys!!

I'll try it out this weekend!

I'll let you know how it goes :)
 

HiRez

macrumors 603
Jan 6, 2004
6,250
2,576
Western US
I would recommend ANSI C or Java as a starter language, however I would like to second the suggestion of Python as a first learning language. It's a very powerful scripting language that shares a lot with the traditional "real" languages of C, Java, etc., even including object-oriented concepts and classes now. Its syntax is also elegant, concise, and very easy to read, unlike some other languages. And as WebMongol demonstrated, it's very easy to get started with to make it do real work easily, and requires no fancy development tools or compilers, just a good text editor such as TextWrangler, which WebMongol also suggested and I recommend.
 

Ti_Poussin

macrumors regular
May 6, 2005
210
0
Install the developper tool, with xCode you can try C++ (not too hard and a good base). May wanna check Python like other have state before to give you an idea of how programming work.

An another way is doing HTML by code and adding javascript (similar to C) later on.

There an index of help and tutorial in the developper Folder once you install developper tool, locate here:
/Developer/ADC Reference Library/index.html
open it in safari there's a good start to check this out, some example are include too.
 

devman

macrumors 65816
Apr 19, 2004
1,242
8
AU
I agree with Nutter - if you want to program for Mac then Objective-C and Cocoa is what you should learn.

If you want to go with Java then the Head First Java book is excellent for someone new.
 

haym37

macrumors newbie
Feb 19, 2005
5
0
If you get really into programming, most likely, you won't be using a Mac for programming (unless you're making Cocoa/Mac OS X specific applications), therefore, I wouldn't suggest Objective-C. If you want to get into web development, PHP is a great and easy language to start out with. Otherwise, I would highly suggest starting with Java, then advancing to C or C++. A GREAT book for beginning Java is Sams Teach Yourself Java 2 in 21 Days, Professional Reference Edition which can be found on Amazon at:

http://www.amazon.com/exec/obidos/t...104-2477602-3979940?v=glance&s=books&n=507846

I learned a lot from it, as a beginner with Java, and it has helped me build a strong foundation to advance onto more advanced programming, and I'm sure it'd do the same for you. :)
 

GeeYouEye

macrumors 68000
Dec 9, 2001
1,669
10
State of Denial
WebMongol said:
If you want to learn Java all you need is a text editor, tutorial and a lot of time.
For programming editor I recommend TextWrangler (it's free).
Later you can try something more sophisticated, like vim or emacs.

Or you can start with simpler, easier to learn and fun language, like Python.
There is a number of free online tutorials to learn Python:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
Python has an interactive mode so you even do not need editor.
In Terminal type /usr/bin/python and you are redy to write your first
Python code:

mac:~/$ /usr/bin/python
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> # Python Hello world
... print "Hello, World"
Hello, World
>>> # loop:
... for i in range(5): print "Hello, World", i
...
Hello, World 0
Hello, World 1
Hello, World 2
Hello, World 3
Hello, World 4
>>>

Terminal is in /Applications/Utilities directory.

Following 4-line Python code that downloads a content of ww.yahoo.com root page, counts number of bytes, words and lines, and writes it into file - 'web.html':

>>> import urllib
>>> doc = urllib.urlopen("http://www.yahoo.com/").read()
>>> print len(doc), len (doc.split()), len (doc.split('\n'))
37230 2626 611
>>> open('web.html', 'w').write(doc)

# back to shell: count number of lines, words and bytes in web.html file
# and open the file in web browser:

mac:~/$ wc web.html
610 2626 37230 web.doc
mac:~/$ open web.html

Try to do the same in Java or Objective-C and you'll see the difference.


Good luck.
In Objective-C/Cocoa:

NSString *str = [NSString stringWithContentsOfURL:mad:"http://www.yahoo.com"];
NSLog(@"%@, %@, %@", [str length], [[str componentsSeparatedByString:mad:" "] count], [[str componentsSeparatedByString:mad:"\n"] count]);
[str writeToFile:mad:"web.html"];

That's three lines right there. Four, if you include the required #import <Foundation/Foundation.h> that's at the top of every file. Granted, the first line doesn't (didn't? I haven't tried since Panther) work as you might expect. You need either a CFURLConnection (but that's C) or to use WebKit, but if you do that, you've got yourself a web browser in 0 lines of code just using Interface Builder.
 

WebMongol

macrumors member
Sep 19, 2004
50
0
Bay Area, CA
GeeYouEye said:
In Objective-C/Cocoa:

NSString *str = [NSString stringWithContentsOfURL:mad:"http://www.yahoo.com"];
NSLog(@"%@, %@, %@", [str length], [[str componentsSeparatedByString:mad:" "] count], [[str componentsSeparatedByString:mad:"\n"] count]);
[str writeToFile:mad:"web.html"];

That's three lines right there. Four, if you include the required #import <Foundation/Foundation.h> that's at the top of every file. Granted, the first line doesn't (didn't? I haven't tried since Panther) work as you might expect. You need either a CFURLConnection (but that's C) or to use WebKit, but if you do that, you've got yourself a web browser in 0 lines of code just using Interface Builder.

Well, your example shows the power of Cocoa framework. The only problem is I can not compile and run it. Following is modified version that works:
// to run: gcc -Wall -framework Foundation wcurl.m -o xwcurl && ./xwcurl

#import <Foundation/Foundation.h>

int main(int argc, char** argv)
{
NSAutoreleasePool *main_pool = [[NSAutoreleasePool alloc] init];

NSURL* aURL = [NSURL URLWithString: @"http://www.yahoo.com/"];
NSString *str = [NSString stringWithContentsOfURL:aURL];
NSLog(@"%d, %d, %d", [str length], [[str componentsSeparatedByString:mad:" "] count], [[str componentsSeparatedByString:mad:"\n"] count]);
[str writeToFile: @"web.html" atomically:NO];

[ main_pool release ];
return 0;
}

- I do not program in Objective-C so it may not be an optimal version
- line count is up to eleven - almost 3x of my Python code
- I fixed a few bugs to make it compile and run:

- stringWithContentsOfURL requires NSURL object so I added initialization of NSURL
- writeToFile requires two parameters
- NSLog requires %d or %u format for integers

- plus I added memory management code, #import and main()

I think it's too many details for somebody just learning to program. Python allows you to concentrate on essence of your task and not waste your time on artificial language constructs.
Majority of people that want to learn some programming will never make it. For computer science major starting with C and moving to Objective-C, C++, Lisp, etc is the right way. But it does not make any sense for "normal people" to struggle with complexity of low level languages, get frustrated and give up. If student can develop proficiency in high-level programming language he/she may learn arcane language and API as a second step.

Python was developed with goal of using it as first language, has great documentation, supported on almost all platforms and is a real programming language that may be used for broad spectrum of problems.
Plus Python is shipped as part of Mac OS X.
 

devman

macrumors 65816
Apr 19, 2004
1,242
8
AU
WebMongol said:
Well, your example shows the power of Cocoa framework. The only problem is I can not compile and run it. Following is modified version that works:
// to run: gcc -Wall -framework Foundation wcurl.m -o xwcurl && ./xwcurl

#import <Foundation/Foundation.h>

int main(int argc, char** argv)
{
NSAutoreleasePool *main_pool = [[NSAutoreleasePool alloc] init];

NSURL* aURL = [NSURL URLWithString: @"http://www.yahoo.com/"];
NSString *str = [NSString stringWithContentsOfURL:aURL];
NSLog(@"%d, %d, %d", [str length], [[str componentsSeparatedByString:mad:" "] count], [[str componentsSeparatedByString:mad:"\n"] count]);
[str writeToFile: @"web.html" atomically:NO];

[ main_pool release ];
return 0;
}

- I do not program in Objective-C so it may not be an optimal version
- line count is up to eleven - almost 3x of my Python code
- I fixed a few bugs to make it compile and run:

- stringWithContentsOfURL requires NSURL object so I added initialization of NSURL
- writeToFile requires two parameters
- NSLog requires %d or %u format for integers

- plus I added memory management code, #import and main()

I think it's too many details for somebody just learning to program. Python allows you to concentrate on essence of your task and not waste your time on artificial language constructs.
Majority of people that want to learn some programming will never make it. For computer science major starting with C and moving to Objective-C, C++, Lisp, etc is the right way. But it does not make any sense for "normal people" to struggle with complexity of low level languages, get frustrated and give up. If student can develop proficiency in high-level programming language he/she may learn arcane language and API as a second step.

Python was developed with goal of using it as first language, has great documentation, supported on almost all platforms and is a real programming language that may be used for broad spectrum of problems.
Plus Python is shipped as part of Mac OS X.

*sigh* lines of code (LOC) is not a useful measure of comparison, let alone trying to make a cross-language (and thus cross-framework) comparison using LOC.

If you want to be so terse we can regress to APL - "in which you can write a program to simulate shuffling a deck of cards and then dealing them out to several players in four characters, none of which appear on a standard keyboard." (quote from David Given)

Less LOC is not necessarily better.

(and this is ignoring your "articificial language constructs" - whatever they are, what is a high level language, what is a real language - whatever real means here, what a normal person is - and whether they should even be programming, and and and...)
 

FocusAndEarnIt

macrumors 601
Original poster
May 29, 2005
4,624
1,063
Thanks everybody!!

You guys are soooo nice here. WOW! :)

:D

P.S. You guys have helped me join the programming world, I'm not good, at all! but, I'm learning :)

P.S.S. I'm using Xcode 2.0, should I be using something else?

Thanks! :D
 

prophet621

macrumors member
Jul 31, 2005
86
0
I would also recommend Python. I am currently learning Pyton and the reasons I chose that language over the others is because it's easy yet has some power. It's also easier to read if you need to debug or someone else is going to need to look through the code.

As a first programming language it appears to be the best choice and you can apply that knowledge to other OO languages.

One other reason I picked Python, it's cross platform. I primarily use Windows and have a Linux box and recently bought an ibook to play around with macs and Python will work on all platforms though with Windows you need to install the free compiler. I know there are a few others that can also do this but are not as easy to understand with code and syntax as Python seems to be.

BitTorrent was written in Python. I have the source code saved somewhere I was going to look at and try to see how much I can understand or at least make some sence of.

Cocoa looks like a bunch of monkeys banged on the keyboard.
 

devman

macrumors 65816
Apr 19, 2004
1,242
8
AU
prophet621 said:
Cocoa looks like a bunch of monkeys banged on the keyboard.

Cocoa is not a language.

Since this is about syntax, all Cocoa adds is selectors and class names and they are easy to read.
 

Compile 'em all

macrumors 601
Apr 6, 2005
4,130
323
lilstewart92 said:
Ok, so I have programmed NOTHING, I want to learn, I just got a book from my neighbor, it's Core JAVA 2 Fudamentals.

He's a busy programmer, and I finally caught him. :p

So he gave me this book and... I have Xcode installed on my iBook (in sig) and I know very little about Terminal

Any suggestions on where to start, and tips?
Help please

Java is a very nice and elegant language to start with. It is easy to learn
and understand.

As a fellow poster recommended, start with Java and then depending on
what do you want to do (Web programming, machine interfacing...etc) you
can move on to learn C++ or C or just stick with Java.

All you need to start programming in Java is a text editor, the Terminal and
SUN's GREAT GREAT GREAT online Java tutorial. I am NO SUN employee BTW ;)
Have fun and good luck :)

Edit: I just read your question asking about Xcode. Don't rush things. As I
said before, start with a simple text editor (e.g Textedit) and when you
start working on more complex examples you will need an IDE (Integrated
Development Environment).

For an IDE, Eclipse "IMO" beats any other Java IDE hands down.
As well, Eclipse is heavily used in the industry (e.g IBM and SAP). So any
experience you gain from using Eclipse might help you if later you want to get a Job.
 

prophet621

macrumors member
Jul 31, 2005
86
0
"Cocoa is not a language.

Since this is about syntax, all Cocoa adds is selectors and class names and they are easy to read."

Thank you. I had never heard of Cocoa but have often seem people claim their apps 'were written entirely in Cocoa" and 'programmed in Cocoa". I was under the (apparently) mistaken assumption that Cocoa was a language strickly used for OSX, sort of what MS does with C#.
 

FocusAndEarnIt

macrumors 601
Original poster
May 29, 2005
4,624
1,063
Compile 'em all said:
Java is a very nice and elegant language to start with. It is easy to learn
and understand.

As a fellow poster recommended, start with Java and then depending on
what do you want to do (Web programming, machine interfacing...etc) you
can move on to learn C++ or C or just stick with Java.

All you need to start programming in Java is a text editor, the Terminal and
SUN's GREAT GREAT GREAT online Java tutorial. I am NO SUN employee BTW ;)
Have fun and good luck :)

Edit: I just read your question asking about Xcode. Don't rush things. As I
said before, start with a simple text editor (e.g Textedit) and when you
start working on more complex examples you will need an IDE (Integrated
Development Environment).

For an IDE, Eclipse "IMO" beats any other Java IDE hands down.
As well, Eclipse is heavily used in the industry (e.g IBM and SAP). So any
experience you gain from using Eclipse might help you if later you want to get a Job.

Holy mastocholi!!! My neighbor works for Eclipse or something. He's involved w/ Eclipse though! :eek:
 

FocusAndEarnIt

macrumors 601
Original poster
May 29, 2005
4,624
1,063
How do I learn the Java language?

I really really don't want to spend money on books, this i just a little around the clock project.

Any REALLY good tutorials online?

Thanks!
 

Blackjack75

macrumors newbie
May 6, 2005
20
0
Thinking in Java

There's a whole book called Thinking In java available for free on the net. It's a good starting point. Also go with eclipse since it's easier than Xcode for java. Xcode's java completion is really lousy.

Xcode is nice though in combination with interface builder, to build cocoa apps. I use it for my mac development and love it. Cocoa and bindings are just wonderful.

Now if you haven't got much experience, I'd say go with java. It's a clean language that will help you grasp all the basics of object oriented programming. The downside (in a sense) is that you won't have to care much about memory management in java since it does it for you. When you come back to "real life" (like objective C retain cycles and good old malloc/free) this might be painful to get used to. It even hurt me after years of java to have to get down back to this and I sure had previous experience with C/C++.

The downside with objective C and Xcode is that you see people mix a lot of C, C++ Obj-C in the sample code you'll find and it might be confusing at start if you don't have experience with C.

Here is one of the numerous copies of this book I was talking about:
http://www.camtp.uni-mb.si/books/Thinking-in-Java/SimpleContents.html

Good luck :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.