Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Few basic question in core-java

 
Sankar vignesh
Greenhorn
Posts: 3
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,
i am new to JAVA , when i am going with the JAVA language concepts i cannot able to understand some words ands concepts , which are

1.When i reading the book, many times , i saw the word INSTANCE, i know that in common English instance is an alternative word of example , so is that same as the common English word , if so what that instance[example] is going to do do with the class

2.In inheritance , when a class 'B' is extended from 'A' then , 'B' has every thing that 'A' has, so which means a copy of A is present in 'B' are we are accessing the A's[original not a copy] values only, why i am asking this question is because it has given that Inheritance is one which help CODE RE-USE ,so it must be like only one thing which is used by every one.

3.Is that Encapsulation means combining the fields and methods together or combining of fields and methods in such a way that the methods operate on the fields,instead of accessing the fields directly.

4.What is mean by tight encapsulation and loose encapsulation.


Please any one guide in right path........


 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sankar,

Most of your doubts will be solved once you get to understand core Object Oriented concepts.

I hope you know what Class is. Then it is easy to understand what object is. Object is simply an instance of a class.
e.g. if there's a class Nation - with members as area, name, capital, population etc. then an instance is a specific Nation with data - e.g. India, Russia etc. (of course, instance might be without data as well).

Once you get to understand difference between class and object, further questions (inheritance, encapsulation) etc. could be resolved by yourself.

You can try reading Head First Java and Head First Object Oriented Analysis and Design.

I hope this helps.
 
Sankar vignesh
Greenhorn
Posts: 3
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anayonkar Shivalkar wrote:Hi Sankar,

Most of your doubts will be solved once you get to understand core Object Oriented concepts.

I hope you know what Class is. Then it is easy to understand what object is. Object is simply an instance of a class.
e.g. if there's a class Nation - with members as area, name, capital, population etc. then an instance is a specific Nation with data - e.g. India, Russia etc. (of course, instance might be without data as well).

Once you get to understand difference between class and object, further questions (inheritance, encapsulation) etc. could be resolved by yourself.

You can try reading Head First Java and Head First Object Oriented Analysis and Design.

I hope this helps.



Thanks for your quick reply . ..


if there's a class Nation - with members as area, name, capital, population etc. then an instance is a specific Nation with data


So which means a special kind of class ..............
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sankar vignesh wrote:So which means a special kind of class

No. Instance is not a special type of class.

In layman's terms, we can say class is a complex datatype.
e.g.
Here, int is a datatype, i is variable of type int and 0 is its value (since int stores numeric value).

now, consider a class:
here, Integer is a class. new Integer(0) creates a new object of Integer class. The object holds value 0 and (in Java) i is reference to that object.

Now, Nation is a class, India is object:(btw, this is just an example)
Furthermore, classes Integer, Nation etc. do have their own methods and might have other fields as well. e.g. We called default constructor of Nation while creating India object, so lateron, we can set data members for that object to India specific value. e.g.
I would still advice you to go thoroughly through any Object Oriented Programming related book, because Java is full of classes and objects.
 
Winston Gutkowski
Bartender
Pie
Posts: 10498
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sankar vignesh wrote:1.When i reading the book, many times , i saw the word INSTANCE, i know that in common English instance is an alternative word of example

Not really, although it is sometimes used that way. An 'instance' is a specific item, situation, or point in time; and the word is usually used with a qualifier to express individuality, as for example:
In this instance - refers to a specific situation.
The last instance - refers to a final (or last encountered) thing or situation.

In Java the word is similarly used to indicate a specific object, as opposed to other objects of the same type; although it is also often used in reference to variables or methods to indicate that they are not static (ie, they belong to, or work on, individual objects, not a class).

2.In inheritance , when a class 'B' is extended from 'A' then, 'B' has every thing that 'A' has, so which means a copy of A is present in 'B'

No. This is Java, not C++. In class (ie, definition) terms, class B contains all visible elements of A and, in type terms, is an A. Therefore
B bAsB = new B();
A bAsA = new B();

are both perfectly legal; but new B() only creates one object.

3.Is that Encapsulation means combining the fields and methods together or combining of fields and methods in such a way that the methods operate on the fields...

I'd say that the 2nd part of your statement is closer, but I really think you need to read up a little more on this subject (Wikipedia might not be a bad place to start). Encapsulation is not something that can be explained in a single sentence.

4.What is mean by tight encapsulation and loose encapsulation.

Don't know. Are you sure you're not referring to 'tight' and 'loose' coupling? Again, the Java Tutorials or Wikipedia will probably be of more help than opinions on a forum.

I think you also need to read up on the difference between classes and objects, but simply put: an object is a thing, a class is a blueprint (ie, a definition) for an object.

Winston
 
Sankar vignesh
Greenhorn
Posts: 3
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your reply but still i have some questions for you

Anayonkar Shivalkar wrote:
Sankar vignesh wrote:So which means a special kind of class

Now, Nation is a class, India is object:





But as per my understanding from book "India" here is a reference or reference variable , its not a object,but actually it is pointing to the object.

I would still advice you to go thoroughly through any Object Oriented Programming related book, because Java is full of classes and objects.




Ya i have went through Head First Java and also done some Google search, i find that Instance means real occurrence of particular thing, so in JVM only the object exits means even though when we write a simple class it will be converted into a object of that class type[As i searched i find that class Class object will be created] .
-- Am i wright correct me if am wrong...

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic