wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes A few really simple questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A few really simple questions" Watch "A few really simple questions" New topic
Author

A few really simple questions

Christopher Burns
Ranch Hand

Joined: Oct 21, 2008
Posts: 33
Hi gang,

These are really simple memory refreshers just so I don't have to spend time looking around that I don't have right now...

First, does the Java language spec MANDATE interfaces? Or is this just convention?

Second, are accessors (can you tell I am a Smalltalker?) conventionally written as getXXX and setXXX or is this a language construct that must be adhered to?

Third, is it just convention that interfaces are named the actual noun, and the implementation class is <interface name>Impl? As in Animal and AnimalImpl. Or, again, is that some sort of language construct?

Yes or no answers would be great, unless there are details that need to be addressed. Please don't feel like you have elaborate.

Cheers,

Chris


"It is our choices, much more than our abilities, that make us who we are."
- Albus Dumbledore
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Those are all just conventions.

However the getXXX() and setXXX() convention is widely used and is in fact assumed in a lot of support software. JSTL is one example.

And the last one (Animal and AnimalImpl) is somewhat of an anti-pattern. It's possible (and completely normal) to write interfaces that can be implemented by many classes. That naming convention (at least to me) presupposes that the interface will be implemented by exactly one class.
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
Originally posted by Christopher Burns:
Hi gang,

These are really simple memory refreshers just so I don't have to spend time looking around that I don't have right now...

First, does the Java language spec MANDATE interfaces? Or is this just convention?

No, it isn't mandated but it is a way to insure that classes that do not inherit from the same superclass have implemented certain methods.

Originally posted by Christopher Burns:

Second, are accessors (can you tell I am a Smalltalker?) conventionally written as getXXX and setXXX or is this a language construct that must be adhered to?


It is a JavaBean standard and part of the JavaBean specs, but there is nothing to force you to do it in your code... unless you are creating Java Components to be shared in an IDE or something that would enforce the JavaBean spec.

Originally posted by Christopher Burns:

Third, is it just convention that interfaces are named the actual noun, and the implementation class is <interface name>Impl? As in Animal and AnimalImpl. Or, again, is that some sort of language construct?


There are certain best practices/standards programmers try to adhere to... and if everyone does it your code will be easier to read... but nothing to enforce it (and interfaces should be an adjective).

Classes should be nouns (i.e., Object, String)
Interfaces should be adjectives (i.e., Runnable)

Methods should typically be verb-noun pairs (i.e.,getCustomerName, setCustomerName)

Variables should be short meaningful names (customerName, depositAmount)

Constants should be uppercase letters with underscore characters (i.e., MAX_WITHDRAWAL_AMOUNT).

I'm sure I may of missed something... but I'm all sure CR will come through and correct me where I glossed over or mistated anything.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Welcome to JavaRanch. Please use a meaningful subject line when you post a question.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Christopher Burns
Ranch Hand

Joined: Oct 21, 2008
Posts: 33
Hi all,

Thanks for the input. Just wanted to make sure there was no compiler expectations.

Jesper: Sorry about that. Couldn't figure out how to make it more specific, but I guess I could have just used one of the questions as a starter.

Cheers,

Chris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A few really simple questions
 
Similar Threads
Java, how to set path in cmd?
help with permutation
use of empty interface
Nanhesru Ningyake
Interface vs. abstract class in UML and in Java; role of TO, VO