From the course: Oracle Java Certification: 1. Data Types

Unlock the full course today

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

Examples of primitives

Examples of primitives - Java Tutorial

From the course: Oracle Java Certification: 1. Data Types

Start my 1-month free trial

Examples of primitives

- [Instructor] I really enjoy looking at examples that can help understand and solidify the concepts. Let's take a look at some primitive types examples that show differences in different data types. So what do you think this code would output? It looks very simple. The first line defines a variable, and the second line prints its value. The type of the variable is int, and the value on the right-hand side is a hard coded integer value. What could go wrong? Well, unfortunately the code doesn't compile. Let's look at the error. It says the int value is too large. Java compiler will attempt to interpret the literal number as an int type, since the literal value is hard coded, the compiler can check its size requirements versus what's available. The int value that we inputted manually is simply too large. An int in Java uses 32 bits and this quantity is roughly two to the 47th power, which requires at least 47 bits to store. Let's try to fix the problem. We're intentionally making the…

Contents