|
Java Conventions
|
|
06-01-2010, 02:14 AM
Post: #1
|
|||
|
|||
|
Java Conventions
So, let's start with the basic header. Your java source file header should be
informative, generally, I use the following template: Code: /*Immediately after the header is the imports section. I generally try to organize them alphabetically. Here's an example. Code: import java.io.*;Now, class name conventions. Classes should use the Pascal naming conventions. For those unfamiliar with this terminology, the Pascal naming convention states that the first letter of each word is capitalized, for example TheCat, TheDog, Entity, PlayerEntity, InventoryItem. Here's some example class declarations: Code: public class PlayerEntity extends EntityNow, we're going to talk about fields. Fields should use the camel-case naming convention, and generally should be private. The camel-case naming convention says that the first word in a compound word or phrase should be all lower-case. For example: theCat, theDog, entity, playerEntity, inventoryItem. One more rant, when using arrays declare it with the [ ] beside the type, not beside the name. (See the last example below) Example field declarations: Code: private int id;Field names should never be overly wordy, but should always be descriptive. Do not use lame phrases such as "lmao, lol, omg", etc, as variable/field names. Now, accessors. Accessors are methods (see the next section) that provide a public means to get and set the private data inside the class. They should also use the camel-case naming convention, for example, isActive( ), getID( ), setID( ), to name a few. Code examples: Code: int id;Methods, pretty much self explanatory, you have three primary access modifiers, which are public, private and protected, however, since this is a conventions article and not a beginner java programming article, I'll leave learning that to you. Methods are functions inside a class, the biggest thing is remember to use camel-case naming conventions for naming your methods, otherwise the java coding convention god shall smite your mothers. Also, parameters use the camel-case naming convention as well. Ok, last rant. Indention is your friend, and use it wisely. Here's some examples: Code: // If statementsFor more information on coding conventions, please visit http://java.sun.com/docs/codeconv/ Grand finale, a example hello world program. Code: /*
|
|||
|
06-01-2010, 07:56 AM
Post: #2
|
|||
|
|||
|
RE: Java Conventions
:) I'm already liking this one :D
|
|||
|
06-13-2010, 03:21 AM
Post: #3
|
|||
|
|||
|
RE: Java Conventions
Currently, I am a student at University of technology, my major is engineering computer, it is mean that I know about java but actually, I really hate it, I hate it from the first day I know it, it make my head hurt. Thou I hate it like that but I am still studying it because it necessary. You talk about java but can I ask, you hate it or like it??
|
|||
|
« Next Oldest | Next Newest »
|
| Possibly Related Threads... | |||||
| Thread: | Author | Replies: | Views: | Last Post | |
| Java vs C++ | reovlu | 0 | 237 |
01-17-2012 11:51 AM Last Post: reovlu |
|
| Getting started with Java Programming! | bull12rede43 | 5 | 660 |
05-17-2010 03:11 AM Last Post: Lightpixel |
|
User(s) browsing this thread: 2 Guest(s)





