Java Integer: Definition & Examples

Instructor: David Gloag

David has over 40 years of industry experience in software development and information technology and a bachelor of computer science

In this lesson, we'll take a look at integers in Java and give some examples of integers and the code for them. At the end, you should have a good understanding of this fundamental concept.

To Live is to Use Numbers

As a people, we make great use of numbers and calculations. We count the people in line for a coffee in the morning, we enumerate the individual players on our favorite sports teams, and we add up the dollars in our bank account. In fact, it's such a big part of our lives and society, that we learn to do it from an early age. It makes sense then, that this idea would transfer over to the machines we build. Our cell phones, tablets, and laptops all have the ability to work with numbers and perform calculations. And one of the technologies often used for this is Java, and its built-in language construct, integers.

What is Java?

Java is a computer programming language that is often used in the devices mentioned above. Why? Because it has the following attributes:

  • General Purpose - It can be used for many different types of problems and applications.
  • High-Level - It is easy to write. One Java statement translates into several machine language statements.
  • Includes Math Operations - The language supports a number of mathematically oriented actions either through operators (symbols) or functions (methods or libraries).

Java as a programming language has seen wide acceptance, existing on some three billion devices worldwide.

What is an Integer in Java?

Most of us are familiar with the idea of an integer from our grade-school days. It is a value that has no fractional part. In other words, integers are similar to the set of whole numbers but add in the negative numbers as well. So, it is both positive and negative non-decimal numbers. When we talk about integers in computer programming languages like Java, we are talking about a similar thing. It is a memory location, or locations, that hold a non-decimal or non-fractional number or numbers, both positive and negative.

The keyword 'int' represents an integer type, a description of the memory that is used to hold the value. This type also imposes restrictions on its use. For example, you can't store a fractional number in an integer. Also, you cannot perform mixed-type calculations without some additional manipulation.

Examples of Integers in Java

Okay, we've talked about what an integer is in Java, now let's look at some code. The first thing we'll look at is how to declare it:

int integer_value;

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account