Skip to main content

introduction_java

Refresher : Introduction to Java : Input/Output + Data Types + Operators

Topics

  1. Intro
  2. If-Else
  3. While
  4. For
  5. Patterns
  6. Functions
  7. 1D Array
  8. 2D Array
  9. ArrayList
  10. Strings
  11. Hashing

Data Types

  1. String
  2. 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 TypeSizeDescription
byte1 byteStores whole numbers from -128 to 127
short2 bytesStores whole numbers from -32,768 to 32,767
int4 bytesStores whole numbers from -2,147,483,648 to 2,147,483,647
long8 bytesStores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float4 bytesStores fractional numbers. Sufficient for storing 6 to 7 decimal digits
double8 bytesStores fractional numbers. Sufficient for storing 15 decimal digits
boolean1 bitStores true or false values
char2 bytesStores 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.