VARIABLES AND DATA TYPES

Cards (20)

  • JAVA KEYWORDS
    These are reserved keywords that cannot be used as variables, methods, classes, or any other identifiers.
  • JAVA KEYWORDS
    Take note: true, false, and null are not keywords, but they are literal and reserved words that cannot be used as identifiers.
  • JAVA VARIABLES
    containers for storing data values. These are data containers that save the data values during Java program execution.
  • Different Types of Variables
    • String
    • int
    • float
    • char
    • Boolean
  • String
    stores text, such as "Hello". String values are surrounded by double quotes
  • int
    stores integers (whole numbers), without decimals, such as 123 or -123
  • float
    stores floating point numbers, with decimals, such as 19.99 or -19.99
  • char
    stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
  • Boolean
    stores values with two states: true or false
  • To Declare (Create) Variables
    Syntax:
    Type variableName = value;
  • "final" or "constant"

    which means unchangeable and read-only:
  • To Declare (Create) Variables
    Declaring more than one variable of the same type, you can use a comma-separated list
    Syntax:
    int num1, num2, num3;
  • JAVA VARIABLES
    Data types specify the different sizes and values that can be stored in the variable.
  • There are two types of data types in Java:
    Primitive data types
    Non-primitive data types
  • Primitive data types: 

    Include boolean, char, byte, short, int, long, float, and double.
  • Non-primitive data types: 

    Include Classes, Interfaces, and Arrays.
  • Integral Data Types
    store whole numbers, positive or negative (such as 123 or -456), without decimals. Valid types are byte, short, int, and long.
  • Boolean Types
    is a primitive data type used to represent a logical value.
  • Character Types
    used to store a single character.
  • String Types
    used to represent a sequence of characters.