Rules For Variable Declaration in Java Last Updated : 15 Jun, 2022 Comments Improve Suggest changes Like Article Like Report Variable in Java is a data container that saves the data values during Java program execution. Every variable is assigned a data type that designates the type and quantity of value it can hold. Variable is a memory location name of the data. A variable is a name given to a memory location. For More On Variables please check Variables in Java. Syntax: data _type variable_name = value;Rules to Declare a Variable A variable name can consist of Capital letters A-Z, lowercase letters a-z digits 0-9, and two special characters such as _ underscore and $ dollar sign.The first character must not be a digit.Blank spaces cannot be used in variable names.Java keywords cannot be used as variable names.Variable names are case-sensitive.There is no limit on the length of a variable name but by convention, it should be between 4 to 15 chars.Variable names always should exist on the left-hand side of assignment operators. List of Java keywords abstract continue fornewswitchassertpackage synchronizeddefaultgotobooleandoifprivatethisbreakelseimportpublicthrowbyteenumimplements protected throwscasedoubleinstanceof returntransientcatchextends intshorttrycharfinalinterfacestaticvoidclassfinallylongstrictfp volatileconstfloatnativesuperwhile The table above shows the list of all java keywords that programmers can not use for naming their variables, methods, classes, etc. The keywords const and goto are reserved, but they are not currently used. The words true, false, and null might seem like keywords, but they are actually literals, you cannot use them as identifiers in your programs. Example Java import java.io.*; class GFG { public static void main(String[] args) { // Declaring all the // possible combinations of // variable format int _a = 10; int $b = 20; int C = 30; int c = 40; int result = _a + $b + C + c; // Displaying O/P System.out.println("Result: " + result); } } Output: Result: 100 Here are a few valid Java variable name examples: myvarmyVarMYVAR_myVar$myVarmyVar1myVar_1 Comment More infoAdvertise with us Next Article Rules For Variable Declaration in Java jainshubham766 Follow Improve Article Tags : Java java-basics Practice Tags : Java Similar Reads Do We Need Forward Declarations in Java? No, Java does not require forward declaration. Programming languages like C and C++ forward declarations play a very important role, it is used to inform the compiler about the presence of a function or class before it is fully defined. In this article, we will discuss whether we need forward declar 4 min read Final Static Variable in Java When the value of a variable is not varied, then it is not a good choice to go for an instance variable. At that time, we can add a static modifier to that variable. Whenever we declare a variable as static, then at the class level, a single variable is created which is shared with the objects. Any 3 min read Final Local Variables in Java In Java, a local variable is a variable, which is declared inside a method. Local variables are only accessible within the method in which they are declared, other methods in the class do not know anything about that variable. When we declare a local variable, we need to initialize it first before u 3 min read final variables in Java In Java, we can use final keyword with variables, methods, and classes. When the final keyword is used with a variable of primitive data types such as int, float, etc), the value of the variable cannot be changed. Example 1: Usage of final with primitive datatype Java // Java Program to illustrate 2 min read Unnamed Patterns and Variables in Java Java programming language offers multiple features that allow developers to write rich and concise code. Among these features, there are unnamed patterns and variables which enables developers to work with data in a more flexible and elegant way. In this article, we will study about unnamed patterns 4 min read Array Declarations in Java (Single and Multidimensional) In Java, an Array is used to store multiple values of the same type in a single variable. There are two types of arrays in Java:Single-dimensional arraysMulti-dimensional arraysIn this article, we are going to discuss how to declare and use single and multidimensional arrays in Java.Single-Dimension 6 min read Are Static Local Variables Allowed in Java? In Java, there are different types of variables, each with its own behavior and scope. Understanding these variables plays a very important role. In this article, we will discuss the concept of static with local variables, and we will also discuss in Java static local variables are allowed or not.Wh 3 min read Static Variables in Java In Java, when a variable is declared with the static keyword. Then, a single variable is created and shared among all the objects at the class level. Static variables are, essentially, global variables. All instances of the class share the same static variable. These are the main scenarios when we u 3 min read Instance Variable as Final in Java As we all know, when the value of a variable varies from object to object, then that type of variable is known as an instance variable. The instance variable is declared inside a class but not within any method, constructor, or block.If we don't initialize an instance variable, then the JVM automati 3 min read Like