Search⌘ K
AI Features

Primitives and Arrays

Explore Java primitive types such as int, byte, float, and boolean, and understand their sizes and uses. Learn how to create and manipulate arrays of primitives and objects, including printing techniques and when to use ArrayList for dynamic sizing.

We'll cover the following...

Primitives

Primitive types in Java refer to different ways to store numbers:

  • char: A single character, such as “A” (the letter A).
Java
public class main {
public static void main(String[] args) {
char hello = 'A';
System.out.println(hello);
}
}
  • byte: A number from -128 to 127 (8 bits). This is typically a way to store or transmit raw data.
Java
public class main {
public static void main(String[] args) {
byte num = 100;
System.out.println(num);
}
}
  • short: A 16-bit signed integer. It has a maximum value of around 32,000, precisely 32,767.
Java
public class main {
public static void main(String[] args) {
short num = 32212;
System.out.println(num);
}
}
  • int: A 32-bit signed integer. Its maximum is
...