int Java Keyword with Examples

📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.

🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.

▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube

▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube

Key points about int Keyword

  1. The int keyword is used to declare a variable as a numeric type. For example, int a = 10;
  2. A int variable is a signed 32-bit type that has a range from –2,147,483,648 to 2,147,483,647.
  3. The Integer class is a wrapper class for the int primitive type. It defines MIN_VALUE and MAX_VALUE constants representing the range of values for this type.

int Java Keyword Example

In the following example, the sum, i and n variables are of type int:
package net.javaguides.corejava.variables; public class LocalVariableExample { public int sum(int n) { int sum = 0; for (int i = 0; i < n; i++) { sum = sum + i; } return sum; } public static void main(String[] args) { LocalVariableExample localVariableExample = new LocalVariableExample(); int sum = localVariableExample.sum(10); System.out.println("Sum of first 10 numbers -> " + sum); } }
Output:
Sum of first 10 numbers -> 45


Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare