Unit 1: Primitive Types

Cards (37)

  • System.out.print
    Displays output on the computer monitor.
  • System.out.println: Displays output on the computer monitor and moves cursor to next line.
  • String Literals: A sequence of characters enclosed in double quotations " ".
  • Java Main Skeleton: Includes the class and main method arguments. Must include both in order to run successfully.

  • public static void main(String args[])
    Main method. Code to be run must be placed within the main method.

  • public class MyProgram: Class
    The name of MyProgram must match the name of the file.
  • Modulus (%): Means divide and take the remainder of two values.
    Ex)
  • Integer division is not equivalent to double division
  • An int divided by double or a double divided by int will result in a double
  • Dividing by Zero: Will cause an ArithmeticException.
  • Order of Operations: The order in which mathematical expressions should be evaluated. Starts with Parentheses, Exponents, Multiplications and Division, Addition and Subtraction. (PEMDAS)
  • Literal: The fixed value being assigned to a variable. Often primitive data types.
  • Arithmetic Exception: Exception that is thrown to warn programmers about arithmetic errors in their code.
  • Import Statement: The first bit of code that is needed is the import statement. Essentially, this code is saying "import the class Scanner from java.util for use in this program".
  • Package: Packages are used to group code into a folder for easy use.
    Java.util is a package that stores various classes of code that are used to add functionality to our programs.
  • Data Type: The call Scanner at the beginning of this line of code is actually a data type. Scanner is its own type of data type that is defined in the Scanner class.
  • Variable name (input): Once the data type is declared, the next part is naming the variable. While in this example we use the name input, you can use any variable name when writing the initial steps for user input.
  • Creates A New Scanner: The next part of this line is the creation of a new Scanner object. In order to create a Scanner that will search for user input, we need to first create a new Scanner. The keyword new is used to indicate that we are creating a new Scanner object.
  • String input
    String name = input.nextLine();
  • Integer input
    int number = input.nextInt();
  • Double input
    double decimal = input.nextDouble();
  • Partial Line Methods
    nextInt() and nextDouble()
  • Scanner Class: A class within java.util. It contains code specifically designed to help with user input.
  • variable.nextLine()
    Allows users to input String values.
  • variable.nextInt()
    Allows users to input int values.
  • variable.nextDouble()
    Allows users to input double values.
  • char: Characters ('A', 'B', 'C', etc) Stores single character values in single quotations.
  • Boolean
    true/false (true) Store true/false value.
  • Declaration: Data type (int) + Variable name (numApples)
    ex) int numApples;
  • Final: Prevents variables from changing value.
  • Increment: Increase the value of a variable by one. variable ++;
  • Decrement: Decrease the value of a variable by one. variable --;
  • Casting: Turning something of one type into another type
  • Implicit Casting: When Java automatically casts the value correctly without the programmer needing to do so. Java will cast an int to a double, but will not cast a double to an int value.
  • Integer.MIN_VALUE: The lowest value Java is able to access. -2147483648
  • Integer.MAX_VALUE: The highest value Java is able to access. 2147483647
  • Overflow: When a calculation relies on a number outside the acceptable number range, Java will wrap back to the MIN or MAX value depending on the value.