Java
  Home arrow Java arrow Page 3 - Java and Object-Oriented Programming
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
JAVA

Java and Object-Oriented Programming
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2007-09-19


    Table of Contents:
  • Java and Object-Oriented Programming
  • How State and Behavior Affect One Another
  • Class, Inheritance and Interface
  • All About Variables

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Java and Object-Oriented Programming - Class, Inheritance and Interface
    ( Page 3 of 4 )

    Working with Class

    While an object represents one specific thing, a class represents a category of things. For example, a Ford dealership has many cars, all similar in make and model. If you were to go to one, you would notice they all have the same basic structure. Four tires, a couple of doors, a horn that unfortunately does not sound like the one in the Dukes of Hazard. You would say all of these Fords are in the same class.

    But suppose you took one home. Maybe you added a DVD player to it, or a set of rims so high you could run over people without actually hitting them. Maybe you give this movie-playing monster truck a name. Herbert, why not? You no longer refer to it as a Ford, or its class, but instead as an individual object.

    Class allows for uniformity within a program. All objects within a certain class, typically, should carry the same core properties. You wouldn't want to use a program where every button was a different color and size and behaved in an entirely new and wonderful way.

    Unless you were Willy Wonka, in which case, you'd be better off sticking to chocolate.

    Inheritance

    In the above example we used Ford as a class of cars, and Herbert the Monster Truck as a special instance of a Ford, or an object. In addition to these two specifications, there is also a superclass. In the case of Ford, the superclass would be Cars and Trucks.

    With inheritance, the subclass literally inherits certain qualities of the superclass. For instance, all Cars and Trucks drive on roads, have four tires, an engine, lights, etc. So therefore, all Fords inherit those same characteristics. That isn't to say that Fords can't have any different features; they can and do. But at the core, they are the same.

    In programming this is done so that the programmer does not have to continually program objects and classes over and over. Instead, he can simply code it once and know that every time he creates an object, he will not have to worry about its core properties.

    Interface

    While an object is the abstract representation of everyday objects, the interface is its physical representation. This could be the buttons in a program, scrollbars, drop-down menus, etc. Simply put, the interface is the method by which you change the state and initiate the behavior of an object.

    A good example would be the key to your car. You insert it into the ignition, which changes the state (sends electricity to the starter) and initiates the behavior change (starts the car).



     
     
    >>> More Java Articles          >>> More By James Payne
     

       

    JAVA ARTICLES

    - Exception Handling Techniques in Java
    - More About Multithreading in Java
    - The Basics of Multiple Threads in Java
    - Data Access Using Spring Framework JDBC
    - New Object Initialization in Java
    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek