IBM®
Skip to main content
    Country/region [select]      Terms of use
 
 
    
     Home      Products      Services & solutions      Support & downloads      My account     
 
developerworks > Dashboard > IBM Lotus Domino Web Application Development > ... > Java primer > Introduction to classes and objects
developerWorks
Log In   View a printable version of the current page.
Overview Spaces Forums Blogs Podcasts Wikis Exchange
Introduction to classes and objects
Added by schenkew@us.ibm.com, last edited by jservais on Apr 03, 2008  (view change)
Labels: 
(None)

 This is a community wiki. Be sure you are logged in to edit, comment, and add pages. Not a member yet? It's free and simple. Click Login in the upper right corner and Register.
View a PDF of the original wiki content produced in March 2008 by Lotus and IBM Redbooks.
Table of contents | Previous | Next


The concept of an object

What is an object? Put simply, an object is anything that has both specific attributes that describe it, as well as specific actions that it can perform and can have performed against it. To be more specific, we use the traditional example of a bank account.

A bank account has specific attributes that describe it. It has a balance, for example. It also is of a specific type, i.e, checking or savings. It also may have special aspects such as overdraft protection. All these things, which are considered nouns, that describe the account are properties of the bank account.

What can a bank account do, and what can be done with a bank account? You can make a deposit or withdrawal. You can do more specific things, such as make a transfer to a different account. You can set up overdraft protection or automatic payments. All these things, which are considered verbs, that describe what an account can do are methods of the bank account.

Properties

The properties of an object are nouns that describe it. In the case of the bank account, the following nouns stand out:

  • Account type
  • Balance
  • Interest rate
  • Special services

These items are all necessary to manage the account. Some do not change, such as account type, while some change on a regular basis, such as the balance of the account.

Methods

The methods of an object are actions that the object can perform, or can be performed against it. In the case of the bank account, the following verbs stand out:

  • Deposit
  • Withdraw
  • Calculate interest rate

These are all actions that can be done with the account. You might notice that method collaboration and reuse, for example, the deposit and withdraw methods, might both call the calculate interest rate method in order to correctly calculate a final balance. The balance and interest rate properties of the account are both accessed and updated as part of executing the deposit and withdraw method.

The important point here to remember is that everything you need to manage the object is encapsulated within the object itself.

Classes

A class is a compiled object. All your code for a given object, including properties and methods, is placed in a single .java file, and the class name has to match the file name of the Java file. When compiled, a .class file is produced from the .java file.


    About IBM Privacy Contact