primitives & operators

class Overview

  • Homework Solution
  • Eclipse
  • Primitive Types
  • Variables
  • Operators

Eclipse

  • Integrated Development Editor (IDE)
  • Used mostly for Java, but can do other languages as well


Eclipse: Make a new project

  • Create a Project:
    • File > New > Java Project
    • Name the project "Zombie"
  • Try Eclipse out:
    • Compiling (Automatic)
    • Running
    • Setting Program Arguments
    • Debugging

primitive types

  • byte
    • 8-bit
    • signed
    • -128 to 127
    • byte b = 100;
  • short
    • 16-bit
    • signed
    • -32768 to 32767
    • short s = 10000;

more primitive types

  • int
    • 32-bit
    • signed
    • -2,147,483,648 to 2,147,483,647
    • int i = 100000;
  • long
    • 64-bit
    • signed
    • -9,223,372,036,854,775,808  to 9,223,372,036,854,775,807
    • long l = 1000000000L;

even more primitive types

  • float
    • single-precision 32-bit IEEE 754 floating point
    • float f = 123.4f;
  • double
    • double-precision 64-bit IEEE 754 floation point
    • double d = 123.4

non-numeric primitive types

  • boolean
    • true or false
    • boolean result = true;
  • char
    • 16-bit Unicode character
    • char c = 'c';
    • char capitalD = 'D';

variable usage

  • Declaration
    • int i;
  • Instantiation
    • i = 21;
  • Declaration & Instantiation
    • int i = 21;

default declaration values

  • If a variable is declared, but not initialized, the variable is set to it's default.
  • Only applies to member variables, local variables must be initialized before use.
    • byte, short, int -> 0
    • long -> 0L
    • float -> 0.0f
    • double -> 0.0
    • char -> '\u0000' (Null character)
    • Object (or String) -> null
    • boolean -> false

operators

  • Assignment Operator
    • =
  • Arithmetic Operators
  • Compound Assignment Operators
  • Unary Operators
  • Relational Operators
  • Conditional Operators
  • Bitwise & Shift Operators

arithmetic operators

  • Add: +
    • 5 + 4   // 9
  • Subtract: -
    • 5 - 4   // 1
  • Multiply: *
    • 5 * 4   // 20
  • Divide: / (No remainder)
    • 5 / 4   // 1
  • Remainder (Mod): %
    • 5 % 4   // 1

compound assignment operators

  • Add & Assign: +=
    • x += 3
  • Subtract & Assign: -=
    • x -= 3
  • Multiply & Assign: *=
    • x *= 3
  • Divide & Assign: /=
    • x /= 3
  • Remainder & Assign: %=
    • x %= 3

unary operators

  • Unary Operators only take one operand
  • Positive: +
    • +1234
  • Negative: -
    • -1234
  • Increment: ++
    • x++
  • Decrement: --
    • x--
  • Logical Complement: !
    • !x

relational operators

  • Equals: ==
  • Not Equals: !=
  • Greater Than: >
  • Greater Than or Equals: >=
  • Less Than: <
  • Less Than or Equals: <=

conditional operators

  • And: &&
  • Or: ||

bitwise & shift operators

  • Bitwise And: &
  • Bitwise Exclusive Or: ^
  • Bitwise Inclusive Or: |
  • Bitwise Right Shift: >>
  • Bitwise Left Shift: <<

JF Lecture 02: Primitives & Operators

By Ryan Lewis

JF Lecture 02: Primitives & Operators

  • 457