lesson 2

Cards (34)

  • Data Type
    A classification system in Java used to specify the variables' value type
  • The data type used varies on what kind of operation it needs to be used upon without any errors
  • Primitive Data Types
    Data types that are built into a programming language, also called pre-defined data types
  • Non-Primitive Data Types

    Data types that are not built into the programming language
  • Primitive Data Types

    • Integers, floating points, characters are some examples
    • Can be used by the user to declare variables directly
  • Integer
    Represents whole numbers, ranges from -2147483648 to 2147483647, uses 4 bytes of memory
  • Integer
    • int Age = 21;
  • Character
    Used for storing characters, uses 1 byte of memory, enclosed in single quotes
  • Character
    • char MiddleInitial = 'A';
  • Boolean
    True or False values, uses 1 byte, usually used for conditional operations and looping
  • Boolean
    • bool is_true = true;
  • Floating-Point
    Used for holding floating-point numbers (decimals and exponents), uses 4 bytes, stores 6-7 decimal points
  • Floating-Point
    • float Pi = 3.14;
  • Long

    Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
  • Long
    • long num1 = 254512131215848;
  • Short
    Stores whole numbers from -32,768 to 32,767
  • Short
    • Short num2 = 30000;
  • Double Float
    Same as float but has double precision on decimal values, stores 15 decimal digits
  • Double Float
    • double Pi = 3.1415;
  • Void
    Represents a valueless entity, used for functions that do not return a value
  • Void
    • void FunctionName(){}
  • Array
    A collection of items stored at continuous memory locations
  • String
    Designed to hold a sequence of characters in a single variable
  • Operators
    Symbols used to indicate an operation that tells what to do with the numbers in order to get to the final result
  • Types of Operators
    • Arithmetic Operators
    • Relational/Comparison Operators
    • Logical Operators
  • Arithmetic Operators
    • Addition (+), Subtraction (-), Multiplication (*), Division (/), Modulus (%), Increment (++), Decrement (--)
  • Relational Operators

    • Equal to (==), Not Equal to (!=), Greater than (>), Less than (<), Greater than or Equal to (>=), Less than or Equal to (<=)
  • Logical Operators

    • Logical and (&&), Logical or (||), Logical not (!)
  • Implicit Conversion

    Java automatically converts between certain data types if they are compatible
  • Implicit Conversion
    • int a = 10;
    long b = a; //this converts the value of a from int to long
  • Casting
    You can use casting to convert between certain data types that are not automatically compatible
  • Casting
    • double num = 1.2;
    int numm = (int) num; //convert the value of num from double to int
  • String Parsing
    You can convert a String to another data type using parsing methods
  • String Parsing
    • String thisString = "5";
    int thisInt = Integer.parseInt(thisString); //converting from string to int