Beginner Java Concepts

Previous: Comments Next: Objects

Primitive Variables

Primitive Variables are simple, single value data that we store for later use. In Java, you need to specify the type of variable whenever you declare a new variable. However, Java is more forgiving with print statements and variable types. The types of primitive variables are:

int myInt = 1;
float myFloat = 1.0f;
double myDouble = 5.00;
char myChar = 'A';
boolean myBoolean = true;

System.out.println("My int is: " + myInt);
System.out.println("My float is: " + myFloat);
System.out.println("My int is: " + myDouble);
System.out.println("My int is: " + myChar);
System.out.println("My int is: " + myBoolean);


Scope refers to whether a variable is able to be used in different parts of the code. This can also be thought of as relevancy. When declaring variables, you can either declare global or local variables. Declaring a variable globally means that you are able to use it throughout the rest of your class file. Local variables are declared, used, and only available in the methods which you declared them in.

Create your playground on
This playground was created on, our hands-on, knowledge-sharing platform for developers.
Go to