Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Java Object

 
Bala jee
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im basically a C Programmer and Im very new to java i need to know about oops concepts can you expain me about that.
Like
what is object and what is class?
Why we need class and Objects?
is instance and object one and the same?
...
 
fred rosenberger
lowercase baba
Bartender
Posts: 12090
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a class is like a blueprint. it tells you what's IN the thing, and what the thing can DO.

an object is one of the (possibly) many things you build from that blueprint. they'll be very similar, but one may have blue paint, and another red, but both have an outside_color.

in C terms, a class is like your struct definition - you list each element and type. but you also declare methods on that struct, that make sense to that struct.

so, if i made a person struct, it might have (i'm not trying to get the exact right syntax here):

struct person {
string first_name;
string last_name;
date birthdate;
}

in Java, you can add methods to the thing (still not going for correct syntax):

class person {
string first_name;
string last_name;
date birthdate;

/*this method will return the first and last name concatenated as*/
*a single string */
public string get_name();

/* this method will use the person's birthdate and the current */
/* system date to calculate the person's age, and return that */
public int get_age();
}
 
Bala jee
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why we need class and Objects?
is instance and object one and the same?

The above two questions are not still answered can any one explain me these also?
 
Srikanth Iyer
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java unlike C is a Object-orineted programmming lang.....

that means it helps you visualize the program in real-life terms..........

YOU would have learnt struct and data-structures in C.....

the main problem with record structures is that the library designer cannot hide the implementation of the lobrary without affecting the clent code because the code is often tied to the particular detalis of the data structures.

So by the 1980 object oriented programming or oops came ....


The main advantage of ooop was the ability to hide the data......

The combination of data attriubtes and procedures(called methods) are known as a class......
 
Bala jee
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is instance and object one and the same?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bala jee:
is instance and object one and the same?


Basically, yes. An instance is an object. An object is an instance (of a class).

We usually use the word "instance" to mean an object of a particular class, which is the subject of the discussion. The word "object" is used more to refer to an instance of any class. However, these are not rules, just tendencies.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic