aspose file tools*
The moose likes Beginning Java and the fly likes just trying to understand Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "just trying to understand" Watch "just trying to understand" New topic
Author

just trying to understand

Bhakundo Karki
Greenhorn

Joined: Sep 03, 2009
Posts: 2
Hello fellows, i am absolute beginner to Java and just wanted to understand few things from the example was looking at...

public class House {
long propertyNumber;
String propertyType;
byte Stories;
public int Bedrooms;
double MarketValue;
}


public class Main {
public static void main(String[] args) {
House property = new House();

property.propertyNumber = 283795;
property.propertyType = "Single Family";
property.Bedrooms = 4;
property.MarketValue = 652880;
}
}

ok in this example i was wondering (in the main class) why do we have to define a variable in a different class and refer to it would it not be easier if we just define the propertynumber and all others in the "main" class excluding class house? umm i cant even explain what i m not understanding :P


learn and share... Intelligent is sexy too... ;)
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

I suggest you start from OO concepts here.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Welcome to Ranch

I suggest you should start with the link Vijitha has posted. Hope it helps you.


http://muhammadkhojaye.blogspot.com/
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2503
    
    8

I agree. It's all to do with OO. Then encapsulation (making variables private access and have getter/setters)


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
pankaj vijay
Ranch Hand

Joined: Apr 01, 2008
Posts: 75
Freak ... property file concept is very useful when you will build a large project.


Pankaj Vijay (SCJP, SCBCD)
Learn Core Java,Learn Servlet Jsp, SCJP Questions,Struts Tutorial
Karan Johar
Greenhorn

Joined: Oct 02, 2009
Posts: 25
Football Freak wrote:Hello fellows, i am absolute beginner to Java and just wanted to understand few things from the example was looking at...

public class House {
long propertyNumber;
String propertyType;
byte Stories;
public int Bedrooms;
double MarketValue;
}


This is called Encapsulation, where you hide all the properties of a House in a House class. Makes things easy to manage and relate together.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

Football Freak wrote:


Please check your private messages for an important administrative matter.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39396
    
  28
Karan Johar wrote:This is called Encapsulation, where you hide all the properties of a House in a House class. Makes things easy to manage and relate together.
No that is called a mistake when you forget to mark the fields "private".
Greg Stevens
Ranch Hand

Joined: Jul 23, 2009
Posts: 41
Football Freak wrote:
ok in this example i was wondering (in the main class) why do we have to define a variable in a different class and refer to it would it not be easier if we just define the propertynumber and all others in the "main" class excluding class house?


What if I have some project involving "houses" and would like to reuse your house code? If you have put everything needed to work with
houses in a House class instead of putting the variables and methods in your actual program, then it would be much easier for me to reuse
that abstraction/functionality. If I had to wait for you to extract all of the relevant variables and methods from your program code, it would
not be worth it (for me to wait, or for you to take the time to pull out all of the "house" stuff).

So as others have pointed out this boils down to the object-oriented principles of software reuse. A further aspect of this object-oriented
software reuse would be that if, in the future, you need to do something with some special type of house -- maybe a condo -- you could
start with the House class you already have and extend it with inheritance mechanisms.
Bhakundo Karki
Greenhorn

Joined: Sep 03, 2009
Posts: 2
thanks everyone! i think i will start with the link given for OO and thanks for all the responses.
 
wood burning stoves
 
subject: just trying to understand