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.

Define data with literals

Define data with literals - Java Tutorial

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

Start my 1-month free trial

Define data with literals

- [Instructor] We can use prefixes and suffixes and to help define literals. For the exam, you need to know all the different prefixes that can be used in literals. Let's just dive right into it. The first line defines an int with a literal value and assign it to a variable a. The next two lines print the value in a in two different formats, decimal and binary. What would you expect the output to look like? The fourth lines prints literal 42 just for comparison. The code compiles nicely. The zero x is actually a prefix that tells Java hexadecimal is being used. Two a is hexadecimal for 42. Hence the first line of the output. The second line in the printout shows that two a in hexadecimal is the same bit pattern as 42 in decimal. Hexadecimal may come in handy if you're using RGB codes for colors or Unicode for letters. Let's look at another example. Here we have an int container into which we're inputting a zero in front of 52. Does it change the meaning of 52? What will the output…

Contents