The int keyword in Java programming language
- Home
- Keyword in Java
- The int keyword in Java programming language
- On
- By
- 0 Comment
- Categories: Keyword in Java
The int keyword in Java programming language
The int keyword in Java programming language
In this tutorial, we will discuss the int keyword in java programming language
In Java programming language, “int” is the keyword used to store the integer value. int allows the creation of methods with the return value. It is a primitive data type in Java programming languages.
It holds 32 bit signed integer value.
integer data type is able to store both unsigned and signed integer.
Declaration
Syntax
the syntax of keyword an int
int <variable_name> <integer_value>;
Example – int variable
Example of keyword an int
int number = 39; int octalNaumber=0377; int hexNumber=0xff;
Program 1
public class intEx1{ public static void main (String args[]){ int age=20; System.out.println("My age is :"+age); } }
When the above code is executed, it produces the following result
My age is: 20
Example – int method
int add(){ //statements }
Above method is an int method with return any value.
Example int method within class
public class Example _int{ // this is a class in java public static void main(String args[]){ // this is the main method in java } public int add(){ // this is a int method with a return value; } }
Program 2
public class intEx2{ public static void main (String args[]){ my_age(20); } static int my_age(int age){ System.out.println("My age is :"+age); return; } }
When the above code is executed, it produces the following result
My age is :20
There are other Java language keywords that are similar to this keyword
Suggested for you