Labs

There is already a labs package in the project for this chapter.

  1. Write a program that declares and initializes two int variables:
  2. big = 2147483647;
  3. bigger = big + 1;

For the big variable, use underscores in the literal value to make it easier to read. Print them both out and explain the results.

(Solution: Overflow.java)

  1. Write a program to see what variable types can do.
  2. Declare an int variable validInt and assign it a valid value.
  3. Declare a long variable longInt and assign validInt to it.
  4. Now try to assign longInt back to validInt. Did it work?

(Solution: ValidInt.java)

  1. Try to draw the memory length diagram on Primitives and Memory. Erase it and try again.

Prev -- Up