Home arrow Java & J2EE arrow Page 4 - Java Classes

Naming Conventions for Our Pal, the Method - Java

Well it's been a while since we discussed Java and I graced these pages with its complicated beauty (for an example of complicated beauty, take a peek at Hillary Swank, who is pretty in a well...complicated sort of way). In this new series of articles, we will be discussing Classes.

TABLE OF CONTENTS:
  1. Java Classes
  2. How to Declare a Class
  3. Using Public Methods to Obtain Private Fields
  4. Naming Conventions for Our Pal, the Method
  5. Creating Objects with Constructors
By: James Payne
Rating: starstarstarstarstar / 20
January 09, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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 & J2EE Articles          >>> More By James Payne
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: