Java
  Home arrow Java arrow Page 2 - Java Classes
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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: 3 stars3 stars3 stars3 stars3 stars / 5
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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
     
     
    Iron Speed
     
    ADVERTISEMENT

    The Web Buyer's Guide is your best source for white papers on a wide range of IT products and services. This Week's Featured White Papers: Building a Virtual Infrastructure from Servers to Storage by Network Appliance

    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


       · Hi,Entertaining, easy-to-read article but... I can't help feeling your wording...
       · Oh I nearly forgot, the Bad Non-Default Constructor (BNDC?) isn't that bad at all of...
       · Hey Elinor,Thanks for taking the time to comment. Good points all around,...
     

       

    JAVA ARTICLES

    - 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...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup
    - Using RPC-Style Web Services with J2EE
    - Integrating XML with J2EE
    - Taming Tiger: Concurrent Collections
    - Combating the ‘Object Crisis’

    Iron Speed



    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway