introduction_java
Refresher : Introduction to Java : Input/Output + Data Types + Operators
Topics
- Intro
- If-Else
- While
- For
- Patterns
- Functions
- 1D Array
- 2D Array
- ArrayList
- Strings
- Hashing
Data Types
- String
- Numbers
Data types are divided into two parts
Primitive data types: A primitive data type specifies the size and type of variable values, and it has no additional methods. includes byte, short, int, long, float, double, boolean and char
| Data Type | Size | Description |
|---|---|---|
| byte | 1 byte | Stores whole numbers from -128 to 127 |
| short | 2 bytes | Stores whole numbers from -32,768 to 32,767 |
| int | 4 bytes | Stores whole numbers from -2,147,483,648 to 2,147,483,647 |
| long | 8 bytes | Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
| float | 4 bytes | Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits |
| double | 8 bytes | Stores fractional numbers. Sufficient for storing 15 decimal digits |
| boolean | 1 bit | Stores true or false values |
| char | 2 bytes | Stores a single charracter/letter or ASCII values |
https://www.w3schools.com/java/java_data_types_numbers.asp
Non-Primitive: Non-primitive data types are called reference types because they refer to objects. such as String, Arrays and Classes
The main differnece between primitive and non-primitve data types are:
- Primitve types are predefined (already defiened) in Java. Non-primitive types are created by the programmer and is not defined by java (except for string).
- Non-primitive types can be used to call methods to perform certain operations, while primitve types cannot.
- A primitve type always has a value, while non-primitve types can be null.
- A primitve type starts with a lowercase letter, while non-primitve types start with an uppercase letter.