Java Variables is like a Videogame Inventory System.

Mon, September 15, 2025 | 3 min read

java

Java Variables is like a Videogame Inventory System.

Java variables might sound confusing and long to understand. But can be easily approaching to a pre-existing idea, which in my case are videogames. For my case I think of variables as inventory slots system in a videogame. Lets call this the Java inventory system and its for my RPG game called Java.

Naming Slots

This inventory slot system has a lot of rules and mechanics. One big rule is that every inventory slot needs to be given a name. The name must be unique from every other slot. This is to ensure the game does not get confused on what slot to pick. In addition these slots have special naming conventions. For example these can’t start with a number. However, you can put an underscore or a $ at the beginning or in between your names. The underscore was added as a way to allow players to add spacing in-between their variables. For example instead of naming their slot BagOfGold, it could be named as Bag_Of_Gold.

Slot Types

In addition to stating a name the slot must be told what type of item it will hold. Like in any inventory system, it can contain weapons, potions, gold, armour, resources and anything else. Java’s inventory system in vast and powerful and can hold anything we can imagine. In Java, a player can use a pre-existing type that Java provides or create their own types. For now use an pre-existing type. These pre-existing slots are called primitive types as basic data types that represent simple values. Java has eight primitive data types. Boolean, Byte, Char, Short, Int, Float, Double, Long.

Boolean is used for logic true false statements, Byte is for 8 bit data. Char is for single characters. A short is a whole number with a small range. Int is also a whole number but with a greater range. Long is also a whole number, but with a greater range than the first two. Then float and double are to store decimal values. Double is greater than a float.

To remember these 8 primitive types. Use pre-exiting knowledge to help connect it and. In this case I assign a Pokémon and attack name to remember it all. Squirtle uses bubble beam, Ivyeroa uses bullet seed, Charizard uses fire blast, and Lapras uses dragon dance.

Why would I need to know the the different ranges of the whole and decimal numbers if I could always use the greatest value. Which in response, is a great question. As of September 2025, storage would not be an issue.

However, I would argue its best to know your types. As some types will be better for certain situations. Like in Pokémon, you could just use Fire Types for the entire journey and maybe you will workout. Until you reach a Water Gym leader and then you have to stock on Full-Potions.