From the course: Java 8 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Declaring and initializing numeric primitives

Declaring and initializing numeric primitives - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Declaring and initializing numeric primitives

- You can represent numbers in Java as either primitive values or as complex objects. I'll show you how to represent them as primitives here and then show how to use helper classes to get information about numeric values. I'm working in the project PrimitiveNumbers. It has two classes named Main and MaxValues. Both of these classes have a Main method but no executable code. In the Main class, I'll add code to the Main method. And I'm going to declare six variables each using one of the primitive numeric data types. I'll start with a byte that I'll name b and assign it a value of one. Then I'll create a short integer. I'll name that sh and I'll give that a value of one as well. Then an int, a 32 bit integer. I'll name that i and give it a value of one. And then a long integer with the type long. I'll assign that the name of l and give it a value of one as well. Notice all of these integer types are using a literal of one. The compiler looks at the value of one and always starts with an…

Contents