Java
  Home arrow Java arrow Page 2 - Java Classes
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? 
JAVA

Java Classes
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 10
    2008-01-09


    Table of Contents:
  • Java Classes
  • How to Declare a Class
  • Using Public Methods to Obtain Private Fields
  • Naming Conventions for Our Pal, the Method
  • Creating Objects with Constructors

  • 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 Classes - How to Declare a Class
    ( Page 2 of 5 )

    There are several ways to define your classes. The simplest would be:


    class YourClass {

    declare your field, constructor, and methods here

    }

    You can also define them in a more complex manner: 

    class YourClass extends YourSuperClass implements SomeInterface {

    declare your field, constructor, and methods here

    }


    Here is a list of components class declarations can contain:

    • Public, Private, and other modifiers.

    • Class Name.

    • Superclass name, if applicable with the keyword extends before it.

    • The keyword implements followed by a list of interfaces (separated by commas).

    • Body of the class, encapsulated with braces{}.

    Variables in Classes

    We discussed variables and data types in a previous article, but they need a little further discussion here, as they relate to classes.

    Variables in classes are known as member variables and are called fields. They are composed of a modifier (such as public or private), a type, and a name. An example would be:


    public int myEnormousIQ;


    In the above example, the public portion of our declaration is known as an access modifier. It determines which classes have access to the member field. There are several access modifiers: public, protected, package, and private.

    • Public: can be referenced from anywhere in the application by the class in which it is defined.

    • Package: can be referenced by only the same package through the class in which it was defined.

    • Private: can only be referenced by the class in which it was defined.

    • Protected: can be referenced by its class and subclass and from its package.



     
     
    >>> 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 2 Hosted by Hostway
    Stay green...Green IT