Java programming, did anyone get confusd by the terms?

Nocturnal

Lifer
Jan 8, 2002
18,927
0
76
I am trying to read a book on Java but often get confused when the terms, class, method, object, instance, etc are used. Is a class the entire box of the program functions? And then you have method, object and instance. Is method the same thing as a object? Confusing to say the least.
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
What you're getting hung up on isn't necessarily Java, but Object Oriented Programming. You might want to look into a quick resource on OOP before dealing with how Java implements it.

Edit: Wikipedia has some quick definitions to get you started
 

professor1942

Senior member
Dec 22, 2005
509
0
0
An object is an instance of a class, eg. you could create a generic type 'Student' which is a class and create objects of that class, each with a different name and student number.

method = behaviors of an object/class, also called functions in other languages.

Say you create a class Dog with variables for name, type and weight.

Then you create a dog object with the unique data, "Rex", 40 lbs., Collie.

if your dog barks or eats, those are methods, eg. dog.bark() or dog.eat()

 

Nocturnal

Lifer
Jan 8, 2002
18,927
0
76
Originally posted by: professor1942
An object is an instance of a class, eg. you could create a generic type 'Student' which is a class and create objects of that class, each with a different name and student number.

method = behaviors of an object/class, also called functions in other languages.

Say you create a class Dog with variables for name, type and weight.

Then you create a dog object with the unique data, "Rex", 40 lbs., Collie.

if your dog barks or eats, those are methods, eg. dog.bark() or dog.eat()

Sweet. I get that example. You should be a teacher.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
When I first started, inheritance and polymorphism were confusing, and recursion took a little while to wrap my head around, too. After practicing for a while, though, it's all second nature now. You have to just stick with it and keep writing code and it'll get clearer with time.

I know that's not the most helpful advice, but even when you start to get it, you think "oh, I get that now" and you're able to make something work for the first time. It was a bit tough,but you got it to work.

Come back to it a year later and it'll seem trivially easy if you've had a lot of practice in the meantime.

I remember the first time I had to write a linked list. It was confusing and difficult, and took forever to get it working, but I understood the concepts. I've come back and written other linked lists years later and they're a peice of cake now.
 

Nocturnal

Lifer
Jan 8, 2002
18,927
0
76
Oh know, thank you Tyler. You once helped me with binary and I thought I would never get it. Today I am able to succesfully convert binary to decimal, and vice versa along with hex and so fourth. Thanks for your insight.