0% found this document useful (0 votes)
4 views

Data Types in Java

Java data types are categorized into Primitive and Non-Primitive types. Primitive types include int, float, char, and boolean, while Non-Primitive types consist of Strings, Arrays, and user-defined Classes and Objects. These types are essential for storing and manipulating data in Java programming.

Uploaded by

nitinsamazing
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Data Types in Java

Java data types are categorized into Primitive and Non-Primitive types. Primitive types include int, float, char, and boolean, while Non-Primitive types consist of Strings, Arrays, and user-defined Classes and Objects. These types are essential for storing and manipulating data in Java programming.

Uploaded by

nitinsamazing
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Data Types in Java

Java data types are divided into Primitive Data Types and Non-Primitive Data Types.

1. Primitive Data Types

Primitive data types are predefined by the language and stored directly in memory. They are
lightweight and simple.

 int is commonly used for integers unless memory optimization is required.


 Use float for decimal numbers when memory is a concern, but double is more precise.
 char holds a single character enclosed in single quotes (e.g., 'A').
 boolean is used for true/false values in conditional statements.

2. Non-Primitive Data Types

Non-primitive (or reference) data types are created by the programmer and include objects,
arrays, and strings.

 String: Represents a sequence of characters.

Ex: String name = "Hello, World!";

 Array: Used to store multiple values of the same data type.

Ex: int[] numbers = {1, 2, 3, 4, 5};

 Classes and Objects: Defined by the programmer to model real-world entities


class Student {
String name;
int age;
}

You might also like