# How to name key RPG concepts in Java?

I'm writing a basic RPG at the moment, with characters, races, classes, and the characters evolve on maps, naturally.

How to go around the default names that exist in java.lang and java.util. I'm having a hard time trying to find equivalent names to the following RPG concepts that do not clash with Java basic utilities. Typically, the words Character, Class and Map cause me trouble. For instance this is how typically clashes would occur:

// Line 322, well below the imports
char[] characters = new String("foo").toCharArray();
Character character = new Character();
Map map = getMap();
Class heroClass = getDefaultClass();
// do stuff


In this example, it's hard to tell if Character is java.lang.Character or mygame.engine.Character. What type is Map? Can anyone answer without seeing the imports?

I could use the fully qualified name:

java.lang.Character c = new String("foo").toCharArray()[0];
mygame.engine.Character character = new mygame.engine.Character();
java.util.Map map = getMap();
mygame.engine.Class heroClass = getDefaultClass();
// Do stuff.


But in the long run, and from experience, this is barely readable.

So I'd like to know what are usual techniques and/or synonyms that people use to both avoid confusion and unreadable code.

I have personally thought of using the prefix Game, which will lead to using Game a lot of times: GameClass, GameCharacter, GameMap. I think this is meh, but I can get over with it if people say it's not so unusual.

I'm not asking opinions: I'm looking for alternatives, such as which synonyms are used and are clear enough, or other techniques that don't decrease the readability of the code.

• In java you can name the classes whatever you want except for the reserved keywords. There should not be any conflucts, if you import the correct packages. public class Class is no problem Oct 6, 2016 at 12:48
• Put your classes your own packages. This is what these are for.... Oct 6, 2016 at 12:49
• I would probably prefix Game onto the start of my classes. GameMap, GameCharacter. or if you have a name or codename for your game prefix that. If your game was called Skyrim; SkyrimMap and SkyrimCharacter could make nice class names. Also for the record its only for your own use, you could name the abc or xyz for what its worth. I personally would avoid using custom class names that look close to language stuff, for example at work we have custom namespace (package) names that are the same as .NET namespaces, it can get very confusing and leads to you qualifying the full name. Oct 6, 2016 at 13:12
• @lozzajp You might want to add this as an answer. Oct 6, 2016 at 13:22
• Character -> Actor, Class -> Profession or Specialization. I'm not really sure what you're describing as a map. Like a paper map with locations? Perhaps you could use 'Zone'. If it's like an actual map, then I would probably say 'GameMap' is sufficient, as it would be a 'subclass'. Oct 6, 2016 at 14:39

I would probably prefix Game onto the start of my classes. GameMap, GameCharacter. or if you have a name or codename for your game prefix that. If your game was called Skyrim; SkyrimMap and SkyrimCharacter could make nice class names.

Also if its only for your own use, you could name the abc or xyz for what its worth.

I personally would avoid using custom class names that look close to language stuff, for example at work we have custom namespace (package) names that are the same as .NET namespaces, it can get very confusing and leads to you qualifying the full name

Hope that helps.

P.S. alternatively as others suggested just use the names but in your own package, so it all looks like Game.Character, Game.Class etc.

• The convention GamenameClass gets awkward when you program a (spiritual) successor with a different name and want to reuse code. If Bethesda would have followed that convention, the class for characters in Skyrim would likely be called OblivionClass or even MorrowindClass. It can also lead to Smurf Naming Convention. Oct 6, 2016 at 13:44
• Well, TESClass would be more appropriate then, but the point is nice. All I previously thought was GameClass where <real-game-name>Class is better. Oct 6, 2016 at 13:48
• @Philipp I have heard of people using codenames in development source code for reasons as this. The game name may change just days before launch plans start happening and announcements. So just a codename is given and stuck to by everyone to avoid confusions etc. Very good point about the successors though. Oct 6, 2016 at 13:57
• A shorter addition than 'Game' I sometimes use is 'My' e.g. 'MyTextDraw'. I work alone and so it is at least clear to me. I also use words like 'Enemy' rather than 'character'. You could use other synonyms such as 'Plan' for 'Map'. I would avoid using the name of the game because it makes it much harder to re-use and compare different games. Oct 7, 2016 at 17:07

I strongly advice to use java analog of namespaces.

They are called packages.