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

 byte  in Java Language

 int  in Java Language

long  in Java Language

 float  in Java Language

char  in Java Language

 void  in Java Language

try  in Java Language

Catch in Java Language

implements  in java Language

public  in Java Language

static  in Java language

Volatile  in Java Language

Package  in Java Language

class  in Java Language

boolean  in Java Language

break in Java Language

do  in Java Language

double  in Java Language

This  in Java Language

final  in Java Language

switch  in Java Language

interface  in Java Language

extends  in Java language

 

Suggested for you

 Java language Keywords

C language Keywords

 Python language Keywords

keywords in C language

Finally  in Java language

 

 

 

The void keyword in Java programming language
The short keyword in Java programming language