A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/java/int_keyword_in_java.htm below:

Java - int Keyword

Java - int Keyword

Java int keyword is used to define one of the eight primitive datatype supported by Java. It provides means to create int type variables which can accept a int value. Following are the characteristics of a int data type.

A int variables represents a reserved memory locations to store int values. This means that when you create a variable you reserve some space in the memory.

Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store int values in int variables.

Example 1

Following example shows the usage of int primitive data type we've discussed above. We've created a int variable as intValue and assigned it a int value. Then this variable is printed.

package com.tutorialspoint;

public class JavaTester {
   public static void main(String args[]) {
      int intValue = 2;
      System.out.println("int: " + intValue);	  
   }
}
Output
int: 2
Example 2

Following example shows the usage of int primitive data type in an expression. We've created two int variables and assigned them int values. Then we're creating a new int variable intResult to assign it the sum of int variables. Finally result is printed.

package com.tutorialspoint;

public class JavaTester {
   public static void main(String args[]) {
      int intValue1 = 2;
      int intValue2 = 4;
      int intResult = intValue1 + intValue2;

      System.out.println("int: " + intResult);
   }
}
Output
int: 6
Example 3

Following example shows the usage of int variable with an invalid value. We've created a int variable as intValue and assigned it an out of range value.

package com.tutorialspoint;

public class JavaTester {
   public static void main(String args[]) {
      int intValue = 2147483650;
      System.out.println("int: " + intValue);
   }
}
Output
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
	The literal 2147483650 of type int is out of range 

	at com.tutorialspoint.JavaTester.main(JavaTester.java:5)

java_basic_syntax.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4