Java Type Casting
Java Type Casting (Type Conversion) Type casting in Java is the process of converting a variable from one data type to another. There are two types of type casting: 1. Widening Casting (Automatic /...
Java Type Casting (Type Conversion) Type casting in Java is the process of converting a variable from one data type to another. There are two types of type casting: 1. Widening Casting (Automatic /...
✅ var Keyword in Java The var keyword was introduced in Java 10 to allow local variable type inference, meaning Java will automatically detect the data type based on the value assigned. 👉 You...
✅ Java Non-Primitive Data Types In Java, non-primitive data types (also called reference types) are used to store references (memory addresses) to objects rather than actual values.They are more complex than primitive types and...
✅ Java Data Types — Examples Here’s a complete practical example of all main Java data types in action: primitive and non-primitive. 📌 Example Program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | public class DataTypesExample { public static void main(String[] args) { // Primitive Data Types byte age = 25; short year = 2025; int population = 1400000; long distance = 12345678900L; float price = 9.99f; double salary = 50000.75; boolean isJavaFun = true; char grade = 'A'; // Non-Primitive Data Type String name = "Vipul"; // Printing all variables System.out.println("Byte Age: " + age); System.out.println("Short Year: " + year); System.out.println("Int Population: " + population); System.out.println("Long Distance: " + distance); System.out.println("Float Price: " + price); System.out.println("Double Salary: " + salary); System.out.println("Boolean isJavaFun: " + isJavaFun); System.out.println("Char Grade: " + grade); System.out.println("String Name: " + name); // Arithmetic operation with numbers int a = 10, b = 20; System.out.println("Sum of a + b: " + (a + b)); } } |
📌 Output Byte Age: 25 Short Year:...
✅ Java Characters (char) In Java, the char data type is used to store a single character.It can be a letter, digit, or special symbol and is enclosed in single quotes ‘ ‘. Characteristics...
Java Boolean Data Type The boolean data type in Java is using to store true or false values. It is commonly used in conditions, comparisons, and decision-making. Boolean Characteristics Feature Details Size 1 bit...
Java Numbers Numbers in Java are stored using numeric data types. You can use numbers to perform calculations, store values, and work with mathematical expressions. Java supports two main categories of number types: ️1....
Java Data Types – Complete Guide In Java, data types define what kind of data a variable can store and how much memory it uses. 1. Types of Data Types in Java Java data...
Java Variables Examples Examples Variables in Java are used to store data values. Each variable has a type, a name, and optionally a value. 1. Declare and Assign a Variable
1 2 | int age = 25; System.out.println(age); |
2. Declare First,...
Java Constants (final) In Java Constants (final) is a variable whose value cannot be changed once it is assigned.To declare a constant, you use the final keyword. Basic Example
1 2 | final int age = 25; System.out.println(age); |
If you try to change...