int keyword in java

int ” is a primitive type.

A int variable stores a 32−bit integer value.

Examples


int number = 5;
int octalNumber = 0377;
int hexNumber = 0xff;


The int keyword can be used as a method parameter as below:

1
2
3
4
public void displayAge(int age) {
 
    System.out.println("Age of a person is "+age);
}
public void displayAge(int age) {

    System.out.println("Age of a person is "+age);
}


The int keyword can be used as a return type of a method as well:

1
2
3
4
public int getDisplayAge() {
 
                return 45;
}
public int getDisplayAge() {
 
                return 45;
}

All integer literals in Java are 32−bit int values unless the value is followed by l or L as in 100L or 100l,
indicating that the value should be interpreted as a long.

About the Author

Karibasappa G C (KB)
Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on