Primitive Data Types in Java

Tiffany White,

Variables in Java need to be declared before they can be used in Java because it is a statically-typed language. Because of this, you need to state the type of variable you are declaring.

A variable's data type tells Java what type of data the variable contains. For instance, an int contains an integer value. You can perform operations on the int data type like any other value number value.

There are 8 primitive data types in Java. Primitive types are defined by Java and cannot be used elsewhere in your code. 1

The primitive data types in Java are:

Literals

Primitive data types are not objects instantiated from classes. You do not create a new one with the new keyword. Instead, you write the literal values of the data type when declaring and initilaizing the variables. For instance:

public static void main(String[]args) {
	double balance = 0.00;
	char grade = 'B';

Note: You need to use single quotes in the initialization of a Unicode character with the char data type.

Thoughts

Java primitive data types are different than JavaScript data types. I will post more on JavaScript data types soon.

Variables in Java need to be declared before they can be used in Java because it is a statically-typed language. Because of this, you need to state the type of variable you are declaring.

A variable's data type tells Java what type of data the variable contains. For instance, an int contains an integer value. You can perform operations on the int data type like any other value number value.

There are 8 primitive data types in Java. Primitive types are defined by Java and cannot be used elsewhere in your code. 1

The primitive data types in Java are:

Literals

Primitive data types are not objects instantiated from classes. You do not create a new one with the new keyword. Instead, you write the literal values of the data type when declaring and initilaizing the variables. For instance:

public static void main(String[]args) {
	double balance = 0.00;
	char grade = 'B';

Note: You need to use single quotes in the initialization of a Unicode character with the char data type.

Thoughts

Java primitive data types are different than JavaScript data types. I will post more on JavaScript data types soon.

Footnotes

  1. For instance, you cannot write String int = "Integer"; which is a convulted example but it stresses the point I'm trying to make. 2

© tiff.RSS