The first type of data we will store is the whole number. Whole numbers are very common in programming. You often see them used to store ages, or maximum sizes, or the number of times some code has been run, among many other uses.

In Java, whole numbers are stored in the int primitive data type.

ints hold positive numbers, negative numbers, and zero. They do not store fractions or numbers with decimals in them.

The int data type allows values between -2,147,483,648 and 2,147,483,647, inclusive.

To declare a variable of type int, we use the int keyword before the variable name:

// int variable declaration int yearJavaWasCreated; // assignment yearJavaWasCreated = 1996; // declaration and assignment int numberOfPrimitiveTypes = 8;



The file CountComment.java has a number of comments in it.

In your head, count the number of comments. Then, inside the main() method, declare a variable called numComments that holds how many comments you counted.


Print out numComments.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?