Java int keyword22 Feb 2025 | 2 min read The Java int keyword is a primitive data type. It is used to declare variables. It can also be used with methods to return integer type values. It can hold a 32-bit signed two's complement integer. Points to remember
![]() Examples of Java byte keywordExample 1Let's see an example to use int data type with positive and negative value. Output: num1: 10 num2: -10 Example 2Let's see an example to check whether the int data type holds decimal value. Output: error: incompatible types: possible lossy conversion from double to int Example 3Let's see an example to check whether the int data type holds float value. Output: error: incompatible types: possible lossy conversion from float to int Example 4Let's see an example to check whether the int data type holds char value.In such case, the compiler typecast the character implicitly into int type and returns the corresponding ASCII value. Output: num: 97 Example 5In this example, int data type holds the minimum and maximum value. Output: min: -2147483648 max: 2147483647 Example 6Let's create a method that returns an integer value. Output: 10 Next TopicNew-keyword-in-java |
Facing The Sun Problem in Java
The Facing the Sun problem involves determining the number of buildings in a row that can see the sun, assuming sunlight comes from a specific direction (typically the left). Each building's height influences visibility, making it a problem that often requires traversal and comparison techniques for...
7 min read
Java Program to Convert Boolean to Integer
In Java, the boolean data type represents one of two values: true or false. Converting a boolean to an integer involves mapping these boolean values to integers, typically 1 for true and 0 for false. This conversion is useful in various scenarios, such as storing...
6 min read
compareToIgnoreCase Java
In Java, the method compareToIgnoreCase() belongs to the String class that belong to java.lang package. It is used for comparing any two strings by ignoring the lower- and upper-case differences. The method does the comparison of strings using the Unicode value of each character present in...
5 min read
How Garbage Collection Works in Java
? In Java, garbage collection is the process of managing memory, automatically. It finds the unused objects (that are no longer used by the program) and delete or remove them to free up the memory. The garbage collection mechanism uses several GC algorithms. The most popular algorithm...
5 min read
How to Create a Generic List in Java
? Java is a potent programming language that can be used to create a vast array of desktop, online, and mobile apps. The List interface is one of Java's core data structures. A list is a group of elements that are arranged in a certain order and...
4 min read
How to Create a New Folder in Java
In Java, we can use the File object to create a new folder or directory. The File class of Java provide a way through which we can make or create a directory or folder. We use the mkdir() method of the File class to create a...
3 min read
Composition in Java
The Composition is a way to design or implement the "has-a" relationship. Composition and Inheritance both are design techniques. The Inheritance is used to implement the "is-a" relationship. The "has-a" relationship is used to ensure the code reusability in our program. In Composition, we use an...
4 min read
Binary Tree Java
Binary tree is a tree type non-linear data structure that are mainly used for sorting and searching because they store data in hierarchical form. In this section, we will learn the implementation of binary tree data structure in Java. Also, provides a short description of...
64 min read
Implementing our Own Hash Table with Separate Chaining in Java
Hash tables are a fundamental data structure in computer science, providing efficient storage and retrieval of key-value pairs. They achieve average-case constant time complexity for search, insert, and delete operations, making them highly valuable for various applications such as database indexing, caching, and associative arrays....
6 min read
RuleBasedCollator getRules() method in Java with Example
The java.text.RuleBasedCollator class has getRules() function. When creating a rule-based collator object, the RuleBasedCollator class is utilized to retrieve the rule that will be applied. Syntax: public String getRules() Parameter: No arguments are accepted as parameters for this method. Return Value: The rule that is utilized...
2 min read
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India
