Java
  Home arrow Java arrow Page 4 - 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 - Naming Conventions for Our Pal, the Method
    (Page 4 of 5 )

    Methods can be named the same as classes. However, a bunch of nerds decided that they should all use the same convention, and that method names should be a lowercase verb, or if you want to add more than one word, then the second, third, and so forth words should have their first letter capitalized.

    Here are some examples of good method naming conventions:

      retrieveInfo

      killBoss

      eatChickenMcnuggets

      sleepAtWorkAndStillGetPaid

      dateAngelinaJolie

      watchMidgetWrestling

      slapMisterTThenRunLikeHell

    Most of the time methods will have a unique name. However, Java does allow for a little thing called overloading, which allows different methods to be named the same and yet still be distinguishable from one another due to method signatures. A method signature consists of its name and parameter types. An example of two methods with the same name and different signatures would be:


    killChuckNorris(int, int, int, double)

    killChuckNorris(double, double, double, int)


    Overloading is a little beyond the scope of this article, however we will discuss it in the future.

    Constructors: More than Meets the Eye

    Constructors can be thought of as big beluga construction workers, sitting on a fence and swinging their feet back and forth as they eat from a solid metal sandwich pail, cat-calling and generally going nuts when dames and broads with gams up to here walk by.

    Aside from belittling women and eating big sammiches, constructors also build objects based on blueprints that you provide. Who'da thunk you'd grow up to be a fancy-schmancy architect type?

    There are three types of constructors (unless you include copy, which we won't): default, non-default, and cloning. I'll describe each one briefly below:

    The Good Default Constructor

    Default constructors are typically used to create the most basic instance possible, which means giving all the members a value such as null or zero, or even an empty string. You can assign values, mind you, but typically you don't or some nerd will yell at you for being a bad programmer.

    The Bad Non-Default Constructor

    A non-default constructor is used to create an object with most of its values defined for all of the object's members. If your mother was an object, we could say that she is ugly, she is fat, she is easy, she loves the navy, and she votes Democratic.

    The Ugly Clone Constructor

    Settle down all you Star Wars nerds. I know the mere mention of the word Clone stirs you into a Clone Bores frenzy. Clone does what it probably sounds like: replicates an object.

    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 3 hosted by Hostway