2 Elements and Data Types

Variables

Oracle Academy Section

Section 3: Java Data Types

Lesson 1: What is a Variable?

Lesson 2: Numeric Data

Section 3 Quiz 1 (Lessons 1-2)

Java Foundations Certification Exam Topics

Basic Java Elements

  • Identify the conventions to be followed in a Java program

  • Use Java reserved words

  • Use single-line and multi-line comments in Java programs

  • Import other Java packages to make them accessible in your code

  • Describe the java.lang package

Working with Java Data Types

  • Declare and initialize variables including a variable using final

Key Resources

  1. Java Tutorials:

    1. Variables and Data Types

    2. Classes and Objects

      1. Classes

      2. Declaring Classes

      3. Declaring Member Variables

  2. geeksforgeeks

    1. final keyword in java

  3. Udemy: (you must be logged in to Udemy for video links to work) Main Udemy course link

    1. Using Variables (7:52) variables are like boxes, there are different size boxes for different types of data, declare, initialize, 8 primitive types, add f for float, single quotes for chars

  4. Bucky's Room

    1. Variables (7:24) double, = assignment operator, combine string and double, print vs println, declaring


Supplemental Resources


Most Important Concepts / Code

Pseudocode is an informal language that has no syntax rules and is not meant to be compiled or executed.

A flowchart is a diagram that graphically depicts the steps that take place in a program.= is the assignment operator. It is read "is assigned" or "gets", not "equals".

A variable is a location in memory.

Name variables as descriptive nouns using camelCase.

Java has 8 primitive data types: byte, short, int, long, float, double, boolean, char.

System.out.println("Hello World!"); // basic output

int num1; // variable declaration, once and only once

num1 = 5; // assignment, can be reassigned

int gear = 1; // declaration + assignment = initialization

Getting Input Preview:

Create a Scanner object, like Scanner scanner = new Scanner(System.in);

System.out.println("Enter x1"); // prompt

int x1 = scanner.nextInt(); // get int input, will crash if input isn't an int

double rate = scanner.nextDouble(); // get double input, will crash if input isn't a number

// when going from reading numbers to reading strings you could have a problem because nextInt and nextDouble don't consume the Enter keystroke

scanner.nextLine(); // Consume left-over newline

String firstName = scanner.next(); // reads input until a space

String address = scanner.nextLine(); // reads input including spaces until the end of line \n

if Statement Preview:

If else statements look like this

if (condition) {

something that only happens when condition is true

} else {

something that only happens when condition is false

}

Hour 1

  • Quiz Review

  • What are variables?

  • Questions and Exercises: Variables

  • OOP, classes and objects, properties and behaviors, fields and methods, blueprints

  • Make a class

  • Start small, get it working, add to it

  • Exercises

    • Methodology

      • Use resources

      • Work in Eclipse or another IDE

  • How to use Eclipse

    • Projects

      • Exercises

    • Save All - Never Save As


Hour 2